Skip to content

Commit

Permalink
fixed: 优化了部分字符串的拼接
Browse files Browse the repository at this point in the history
  • Loading branch information
fireinsect committed Feb 2, 2024
1 parent fc605d6 commit ed7338c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
8 changes: 4 additions & 4 deletions nonebot_plugin_ocgbot_v2/daily.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import datetime

from PIL import Image, ImageFont, ImageDraw
Expand All @@ -7,13 +6,14 @@
from nonebot.typing import T_State

from nonebot_plugin_ocgbot_v2.libraries.FontUtil import *
from nonebot_plugin_ocgbot_v2.libraries.globalMessage import image_path, deck_path
from nonebot_plugin_ocgbot_v2.libraries.globalMessage import image_path, deck_path
from nonebot_plugin_ocgbot_v2.libraries.staticvar import daily_card
from nonebot_plugin_ocgbot_v2.libraries.tool import hash
from nonebot_plugin_ocgbot_v2.libraries.image import image_to_base64
from nonebot_plugin_ocgbot_v2.libraries.sendAction import card_txt

wm_list = ['同调', '仪式', '融合', '超量', '链接', '灵摆', '顶 G', '重坑', '干饭', '开壶', '唠嗑', '摸鱼', '说书', '开包', '懒觉', '锻炼', '口胡']
wm_list = ['同调', '仪式', '融合', '超量', '链接', '灵摆', '顶 G', '重坑', '干饭', '开壶', '唠嗑', '摸鱼', '说书',
'开包', '懒觉', '锻炼', '口胡']
dailycard = on_command('今日游戏王', aliases={'今日卡运', '今日牌运'})
obj = daily_card
lend = len(wm_list)
Expand All @@ -38,7 +38,7 @@ def getDailyPic(point: int, wm_value):
back_pic = Image.open(image_path + "daily_xilie.png")
else:
back_pic = Image.open(image_path + "daily_kapai.png")
url = deck_path+f"{card['id']}/{card['id']}-{no}.jpg"
url = deck_path + f"{card['id']}/{card['id']}-{no}.jpg"
cardPic = Image.open(url)
proper_list = []
envy_list = []
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_ocgbot_v2/guess_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ async def _(event: GroupMessageEvent):
await guessCard.reject([
MessageSegment.at(user_id=event.sender.user_id),
hint,
MessageSegment.text(text="\r\n还有{0}次机会!".format(guess.User[uid].time))
MessageSegment.text(text=f"\r\n还有{guess.User[uid].time}次机会!")
])
else:
message = [
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_ocgbot_v2/libraries/raiseCard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from PIL import ImageFont, ImageDraw, Image

from nonebot_plugin_ocgbot_v2.libraries.globalMessage import static_path, image_path,font_path
from nonebot_plugin_ocgbot_v2.libraries.globalMessage import image_path, font_path

cardpath = image_path + "card.jpg"
card2path = image_path + "card2.jpg"
Expand Down
18 changes: 9 additions & 9 deletions nonebot_plugin_ocgbot_v2/libraries/sendAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@

def getResult(car):
result = ""
result += car.name + "\n" + car.type + "\nid-" + str(car.cardId) + " " + car.forbidden + "\n\n"
result += f"{car.name}\n{car.type}\nid-{str(car.cardId)} {car.forbidden}\n\n"
car.effect = car.effect.replace('\r', '')
if car.mainType == '怪兽':
if car.deff is None:
result += car.level + ' / ' + car.zz + ' / ' + car.attribute + "\n" + 'ATK:' + car.atk + "\n\n"
result += f"{car.level} / {car.zz} / {car.attribute}\nATK:{car.atk}\n\n"
# result += car.level + ' / ' + car.zz + ' / ' + car.attribute + "\n" + 'ATK:' + car.atk + "\n\n"
else:
result += car.level + ' / ' + car.zz + ' / ' + car.attribute + "\n" + 'ATK:' + car.atk + ' / DEF:' + car.deff + "\n\n"
result += f"{car.level} / {car.zz} / {car.attribute}\nATK:{car.atk} / DEF:{car.deff}\n\n"
# result += car.level + ' / ' + car.zz + ' / ' + car.attribute + "\n" + 'ATK:' + car.atk + ' / DEF:' + car.deff + "\n\n"
# car['effect'] = re.sub(r"(.{50})", "\\1\n", car['effect'])
result += car.effect
else:
Expand Down Expand Up @@ -259,16 +261,16 @@ def img_exist(url):
async def send_cards_byCard(js, func):
result = ""
for car in js.cards:
result += car.name + " " + car.type + " id-" + str(car.cardId) + " " + car.forbidden + "\n"
result += f"{car.name} {car.type} id-{str(car.cardId)} {car.forbidden}\n"
# if car['enName'] is not None:
# result += "英文卡名-" + car['enName'] + " " + "日文卡名-" + car['jpName'] + "\n"
car.effect = car.effect.replace('\r', '')
print(car.deff)
if car.mainType == '怪兽':
if car.deff is None:
result += car.level + ' / ATK: ' + car.atk + ' / : ' + car.zz + ' / ' + car.attribute + "\n"
result += f"{car.level} / ATK: {car.atk} / : {car.zz} / {car.attribute}\n"
else:
result += car.level + ' / ATK: ' + car.atk + ' / DEF: ' + car.deff + ' / : ' + car.zz + ' / ' + car.attribute + "\n"
result += f"{car.level} / ATK: {car.atk} / DEF: {car.deff} / : {car.zz} / {car.attribute}\n"
result += "效果:" + re.sub(r"(.{50})", "\\1\n", car.effect) + "\n"
result += "\n"
result += "\n"
Expand All @@ -277,9 +279,7 @@ async def send_cards_byCard(js, func):
result += "\n"
result += "\n"

page_text = str.format("找到了{0}张卡哟~,当前{1}/{2}页 输入数字可以选择搜索结果!输入`上一页`/`下一页` 进行翻页~", js.amount,
js.nowNum,
js.pageNum)
page_text = f"找到了{js.amount}张卡哟~,当前{js.nowNum}/{js.pageNum}页 输入数字可以选择搜索结果!输入`上一页`/`下一页` 进行翻页~"
await func.send(Message([
MessageSegment("image", {
"file": f"base64://{str(image_to_base64(text_to_image2(result, page_text)), encoding='utf-8')}"
Expand Down
8 changes: 3 additions & 5 deletions nonebot_plugin_ocgbot_v2/priceSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ async def _(bot: Bot, event: Event, state: T_State,args: Message = CommandArg())
page = search_group.groups()[2]
textNext = search_group.groups()[0]
name = textNext
url = gradeUrl + "&keyword={0}&page={1}".format(name, page)
url = f"{gradeUrl}&keyword={name}&page={page}"
result = requests.get(url).json()
page_text = "找到了{0}条数据哟~,当前{1}/{2}页 数据来源:集换社".format(result['total'], result['current_page'],
result['last_page'])
page_text = f"找到了{result['total']}条数据哟~,当前{result['current_page']}/{result['last_page']}页 数据来源:集换社"

await priceSearch.send(Message([
MessageSegment("image", {
Expand All @@ -46,6 +45,5 @@ async def _(bot: Bot, event: Event, state: T_State,args: Message = CommandArg())
def getPriceStr(json):
result = ""
for item in json['data']:
result += "{0} {1} {4}¥起 \n名称:{2} {3} \n\n".format(item['number'], item['rarity'], item['name_cn'],
item['name_origin'], item['min_price'])
result += f"{item['number']} {item['rarity']} {item['min_price']}¥起 \n名称:{item['name_cn']} {item['name_origin']} \n\n"
return result

0 comments on commit ed7338c

Please sign in to comment.