From 161c36c4bc53e0ee4a64a89e4213f3907edd243e Mon Sep 17 00:00:00 2001 From: xiaoyan Date: Fri, 22 Sep 2023 17:26:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 3 +- .idea/NoneBot-Xiao.iml | 2 +- .idea/misc.xml | 2 +- bot.py | 12 +--- src/plugins/zhibo8/__init__.py | 21 ------- src/plugins/zhibo8/config.py | 5 -- src/plugins/zhibo8/plugins/Foresee.py | 80 --------------------------- 7 files changed, 6 insertions(+), 119 deletions(-) delete mode 100644 src/plugins/zhibo8/__init__.py delete mode 100644 src/plugins/zhibo8/config.py delete mode 100644 src/plugins/zhibo8/plugins/Foresee.py diff --git a/.env b/.env index 41a913d..7a4a15f 100644 --- a/.env +++ b/.env @@ -1,2 +1,3 @@ ENVIRONMENT=prod -DRIVER=~fastapi \ No newline at end of file +DRIVER=~fastapi +FEISHU_BOTS=[{"app_id":"cli_a58e99809818d00c","app_secret":"4tY3KSlogZZ0qR6wxq5pTb05adfVcxJU","verification_token":"ZHdJF5ruJFOhVDgvsrfEMbNsil643caV","encrypt_key":"xiaoyan159","is_lark":false}] \ No newline at end of file diff --git a/.idea/NoneBot-Xiao.iml b/.idea/NoneBot-Xiao.iml index 55e3958..1a7b082 100644 --- a/.idea/NoneBot-Xiao.iml +++ b/.idea/NoneBot-Xiao.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 26dbb7a..dc9ea49 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/bot.py b/bot.py index 91cd6bb..8fcd0aa 100644 --- a/bot.py +++ b/bot.py @@ -1,20 +1,12 @@ import nonebot -from nonebot.adapters.onebot.v11 import Adapter as ONEBOT_V11Adapter - -# from nonebot.adapters.feishu import Adapter as 飞书Adapter -# -# from nonebot.adapters.ntchat import Adapter as NTCHATAdapter +from nonebot.adapters.feishu import Adapter as FeishuAdapter nonebot.init() driver = nonebot.get_driver() -driver.register_adapter(ONEBOT_V11Adapter) - -# driver.register_adapter(飞书Adapter) -# -# driver.register_adapter(NTCHATAdapter) +driver.register_adapter(FeishuAdapter) nonebot.load_builtin_plugins('echo') diff --git a/src/plugins/zhibo8/__init__.py b/src/plugins/zhibo8/__init__.py deleted file mode 100644 index e210097..0000000 --- a/src/plugins/zhibo8/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -from datetime import datetime -from pathlib import Path -import nonebot -from nonebot import get_driver, on_message -from nonebot.adapters.onebot.v11 import Bot, Event -from nonebot.typing import T_State -from nonebot.params import CommandArg -from nonebot.message import event_preprocessor - -from .config import Config -from nonebot import on_command -from nonebot.rule import to_me -from requests_html import HTMLSession, HTML - -global_config = get_driver().config -config = Config.parse_obj(global_config) - -_sub_plugins = set() -_sub_plugins |= nonebot.load_plugins( - str((Path(__file__).parent / "plugins").resolve()) -) diff --git a/src/plugins/zhibo8/config.py b/src/plugins/zhibo8/config.py deleted file mode 100644 index 820f04d..0000000 --- a/src/plugins/zhibo8/config.py +++ /dev/null @@ -1,5 +0,0 @@ -from pydantic import BaseModel, Extra - - -class Config(BaseModel, extra=Extra.ignore): - """Plugin Config Here""" diff --git a/src/plugins/zhibo8/plugins/Foresee.py b/src/plugins/zhibo8/plugins/Foresee.py deleted file mode 100644 index 691f403..0000000 --- a/src/plugins/zhibo8/plugins/Foresee.py +++ /dev/null @@ -1,80 +0,0 @@ -from datetime import datetime -from nonebot.adapters.onebot.v11 import Bot, Event -from nonebot.typing import T_State -from nonebot.params import CommandArg, Command - -from nonebot import on_command -from nonebot.rule import to_me -from requests_html import HTMLSession, HTML - -zhibo8Command = on_command("/zhibo8", rule=to_me(), aliases={'预测', '英超', 'zhibo8'}, priority=10) - -xiaobianStr = r""" -小编们预测比分: -太能喵: -叶小欢: -大帝强: -小小: -""" -vsMap = {} -@zhibo8Command.handle() -async def handle_first_receive(bot: Bot, event: Event, state: T_State, args= CommandArg()): - # 事件预处理,获取对应的赛程数据 - vsMap.clear() - session = HTMLSession() - zhibo8Get = session.get("https://www.zhibo8.cc/") - print(zhibo8Get) - saishiContent = zhibo8Get.html.xpath("//div[@class='vct-box']/div[@class='_content']/ul/li") - # 解析xpath - # 解析xpath - for item in saishiContent: - if item.html.find("英超") >= 0: - if item.html.find("阿森纳") >= 0 or item.html.find("曼城") >= 0 or item.html.find("曼联") >= 0 or item.html.find( - "利物浦") >= 0 or item.html.find("切尔西") >= 0: - rouneNum, vsStr = parserSaishiItem(item.html) - if rouneNum not in vsMap.keys(): - vsMap[rouneNum] = [] - vsMap[rouneNum].append(vsStr) - - plain_text = args.extract_plain_text() - if plain_text: - state.set_arg("round", plain_text) - else: - await zhibo8Command.send(message=""""选择要查看的轮次,当前支持查看的轮次为:\r\n{} \r\n""".format(getRoundPrompt(vsMap))) - -@zhibo8Command.got(key="round", prompt="""请输入编号:""") -async def getRoundNum(event: Event): - round = str(event.get_message()) - if round.isdigit() == False: - await zhibo8Command.reject(prompt="请输入编号(数字)") - if len(vsMap.keys())>=int(round): - resultStr = "" - roudNum = list(vsMap.keys())[int(round)-1] - # for roudNum in vsMap: - resultStr += "【" + roudNum.replace("第", "联赛 第") + " 比分预测】\r\n" - for vs in vsMap[roudNum]: - resultStr += vs + xiaobianStr + "\r\n" - await zhibo8Command.finish(resultStr) - else: - await zhibo8Command.reject_arg(key="round", prompt="输入的编号错误,请重新输入!") - -def parserSaishiItem(saishiStr): - html = HTML(html=saishiStr) - # listItem = html.xpath("//b//text()") - roundNum = html.xpath("//span[@class='_league']//text()")[0] - homeName = html.xpath("//span[@class='_teams']//text()")[0].strip() - awayName = html.xpath("//span[@class='_teams']//text()")[-1].strip() - timeStr = html.xpath("./li/@data-time")[0] - time = datetime.strptime(timeStr, "%Y-%m-%d %H:%M") - timeTuple = time.timetuple() - return (roundNum, "{}月{}日".format(timeTuple.tm_mon, timeTuple.tm_mday)+time.strftime("%H:%M") + " " + homeName + " vs " + awayName) - - -def getRoundPrompt(roundMap): - str = "" - i = 1 - for key in roundMap: - print(key) - str += "{}: {} \r\n".format(i, key) - i = i+1 - return str