Skip to content

Commit

Permalink
fixed: 修复了下一页翻页多弹出信息的bug
Browse files Browse the repository at this point in the history
perf: 适配了新别名(一别名对应多卡),更新了别名表
  • Loading branch information
fireinsect committed Jun 17, 2024
1 parent b2cf235 commit dcc1a18
Show file tree
Hide file tree
Showing 8 changed files with 3,033 additions and 2,445 deletions.
9 changes: 6 additions & 3 deletions nonebot_plugin_ocgbot_v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ async def nickNameInit():
nick_json = nick_json['RECORDS']
logger.info(f'nickname.json 读取成功')
for js in nick_json:
if js['NK_type'] == 0:
nick_name_0.append(js)
if js['NK_type'] == 1:
if js['nk_type'] == 0:
if js['nick_name'] not in nick_name_0:
nick_name_0[js['nick_name']] = [js['name']]
else:
nick_name_0[js['nick_name']].append(js['name'])
if js['nk_type'] == 1:
nick_name_1.append(js)
except Exception as e:
# 读取失败
Expand Down
14 changes: 4 additions & 10 deletions nonebot_plugin_ocgbot_v2/config.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import nonebot

from nonebot import get_plugin_config
from pydantic import BaseModel
from yarl import URL

global_config = nonebot.get_driver().config


class Config(BaseModel):
static_path: str = ""
use_web_pic: bool = False
bison_outer_url: str = ""
@property
def outer_url(self) -> URL:
if self.bison_outer_url:
return URL(self.bison_outer_url)
else:
return URL(f"http://localhost:{global_config.port}/bison/")


config = get_plugin_config(Config)
8 changes: 4 additions & 4 deletions nonebot_plugin_ocgbot_v2/guess_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def is_now_guess(event: GroupMessageEvent) -> bool:
guessCard = on_command('游戏王猜卡', aliases={'猜一张卡'}, expire_time=datetime.timedelta(1800))
guessSolve = on_message(rule=is_now_guess)
guessReset = on_command('猜卡重置')
aiguessCard = on_command('ai猜卡')
aiGuessCard = on_command('ai猜卡')
gm = guessCardManager()
RESIZE = guess_diff[0].get("resize")
CUTSIZE = guess_diff[0].get("cutsize")
Expand Down Expand Up @@ -118,15 +118,15 @@ def verifySid(sid: str):
# gm.UpdateLastSend(sessionId)
# await aiGuessCard.send([
# MessageSegment.at(user_id=event.sender.user_id),
# MessageSegment.text(text=get_named()",你有三次机会哟~(输入跳过结束游戏)"),
# MessageSegment.text(text=get_named()+",你有三次机会哟~(输入跳过结束游戏)"),
# MessageSegment.image(f"base64://{str(image_to_base64(image), encoding='utf-8')}")
# ])
# except Exception as e:
# print(e)
# await aiGuessCard.finish("咿呀?启动失败了呢")
#
#
# @aiguessCard.got("name")
# @aiGuessCard.got("name")
# async def test_(bot: Bot, event: GroupMessageEvent, state: T_State):
# name = str(state['name'])
# card = state['card']
Expand Down Expand Up @@ -174,7 +174,7 @@ def verifySid(sid: str):
# MessageSegment.text(text="\r\n还有{0}次机会!".format(state['time']))
# ])
# else:
# await aiguessCard.finish([
# await aiGuessCard.finish([
# MessageSegment.at(user_id=event.sender.user_id),
# MessageSegment.text(text=guess_win().format(card.name)),
# MessageSegment.image(f"base64://{str(image_to_base64(state['image']), encoding='utf-8')}")
Expand Down
46 changes: 25 additions & 21 deletions nonebot_plugin_ocgbot_v2/libraries/Card.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,26 @@ def searchById(cid):
def searchByName(name: str):
org_name = copy.deepcopy(name)
name = name.replace(" ", "")
name = nickNameMatch(name)
sql = "texts.name like '%{0}%'".format(name)
cards = selectFS(sql)
if extra_flag == 1:
sql_extra = "select * from datas where name like '%{0}%' GROUP BY name;"
cursor_extra.execute(sql_extra.format(name))
rows = cursor_extra.fetchall()
for row in rows:
card = Card_Extra(row)
cards.append(card)
if len(cards) == 0:
bg_temp = searchFromBG(org_name)
if bg_temp is not None:
cards = searchById(bg_temp)
cards.sort(key=sortCard)
names = nickNameMatch(name)
cards=[]
print(names)
for name in names:
sql = "texts.name like '%{0}%'".format(name)
cardsTemp = selectFS(sql)
if extra_flag == 1:
sql_extra = "select * from datas where name like '%{0}%' GROUP BY name;"
cursor_extra.execute(sql_extra.format(name))
rows = cursor_extra.fetchall()
for row in rows:
card = Card_Extra(row)
cardsTemp.append(card)
if len(cardsTemp) == 0:
bg_temp = searchFromBG(org_name)
if bg_temp is not None:
cardsTemp = searchById(bg_temp)
cardsTemp.sort(key=sortCard)
cards.extend(cardsTemp)

return cards


Expand Down Expand Up @@ -295,23 +300,22 @@ def searchFromBG(name):
return js['result'][0]['id']


def nickNameMatch(name: str):
def nickNameMatch(name: str) -> list:
name = name.upper()
toName = None
for nick in nick_name_0:
if name == nick['nick_name']:
return nick['name']
if name in nick_name_0:
return nick_name_0[name]
for nick in nick_name_1:
if nick['nick_name'] in name:
name.replace(nick['nick_name'], "▶")
name = name.replace(nick['nick_name'], "▶")
toName = nick['name']
namechar = []
for i in range(len(name)):
namechar.append(name[i])
nameforsearch = "%".join(namechar)
if toName is not None:
nameforsearch = nameforsearch.replace("▶", toName)
return nameforsearch
return [nameforsearch]

# a = SqliteUtils()
# name="访问"
Expand Down
1 change: 0 additions & 1 deletion nonebot_plugin_ocgbot_v2/libraries/sendAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ def getPicOnlyMessage(js, num, url):
# =========判断============
# 判断图片是否存在
async def img_exist(url):
print(url)
if url.exists():
return True
else:
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_ocgbot_v2/libraries/staticvar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nick_name_0 = []
nick_name_0 = {}
nick_name_1 = []
forbidden = []
daily_card = []
2 changes: 1 addition & 1 deletion nonebot_plugin_ocgbot_v2/ocg.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def _(bot: Bot, event: Event, state: T_State):
await send(js, bot, event, search_card)
else:
await send3(js, search_card)
await search_card.reject("")
await search_card.reject()


randomCard = on_command('随机一卡', aliases={'抽一张卡'})
Expand Down
Loading

0 comments on commit dcc1a18

Please sign in to comment.