diff --git a/src/qq_plugins/check.py b/src/qq_plugins/check.py index 7c9ce19..3a32a73 100644 --- a/src/qq_plugins/check.py +++ b/src/qq_plugins/check.py @@ -8,7 +8,7 @@ from src.ai_chat import ai_chat import os import yaml -menu = ['/今日运势','/天气','/图','/点歌','/摸摸头','/群老婆','/今日老婆', '/待办', '/test', '我喜欢你', "❤", "/待办查询", "/新建待办", "/删除待办", "/openai"] +menu = ['/今日运势','/天气','/图','/点歌','/摸摸头','/群老婆','/今日老婆', '/待办', '/test', '我喜欢你', "❤", "/待办查询", "/新建待办", "/删除待办", "/openai", "/cf"] async def check_value_in_menu(event: Event) -> bool: value = event.get_plaintext().strip().split(" ") if value[0] in menu: @@ -23,10 +23,10 @@ with open(os.getcwd() +'/src/ai_chat/config/chat_ai.yaml', 'r', encoding='utf-8' check = on_message(rule=to_me() & rule ,block=True) @check.handle() async def check(bot: Bot, event: Event): - print(event.get_plaintext()) - msg = ai_chat.gpt(event.get_plaintext()) - print(msg) if is_ai == "True": + print(event.get_plaintext()) + msg = ai_chat.gpt(event.get_plaintext()) + print(msg) await bot.send(message=msg,event=event) else: await bot.send(message=Message(random.choice(text_list)),event=event) diff --git a/src/qq_plugins/codeforces.py b/src/qq_plugins/codeforces.py new file mode 100644 index 0000000..8eea06e --- /dev/null +++ b/src/qq_plugins/codeforces.py @@ -0,0 +1,49 @@ +import requests +from nonebot.rule import to_me +from nonebot.plugin import on_command +from nonebot.adapters.qq import Message, MessageEvent, MessageSegment + +cf_query = on_command("cf", rule=to_me(), priority=10, block=True) +@cf_query.handle() +async def get_cf_rounds(): + result = requests.get('https://codeforces.com/api/contest.list?gym=false').json() + print("正在请求codefoeces比赛API") + i = False + all_matches = "" + for matches in result['result']: + if i: + break + if matches["phase"] == "BEFORE": + phase = "未开始" + elif matches["phase"] == "FINISHED": + phase = "已结束" + elif matches["phase"] == "CODING": + phase = "进行中" + elif matches["phase"] == "PENDING_SYSTEM_TEST": + phase = "等待判题" + elif matches["phase"] == "SYSTEM_TEST": + phase = "判题中" + elif matches["phase"] == "FINISHED": + phase = "已结束" + else: + phase = "未知" + one_match = ("\n比赛:" + str(matches["name"]) + + "\n状态:" + phase + + "\n时长:" + str(int(matches["durationSeconds"]) / 3600) + "h\n") + all_matches = "".join([all_matches, one_match]) + + if phase == "未开始": + until_start_time_min = 0 - int(matches["relativeTimeSeconds"]) / 60 + if until_start_time_min <= 180: + until_start = "距开始:" + str(int(until_start_time_min)) + "min\n" + elif 180 < until_start_time_min <= 1440: + until_start = "距开始:" + str(int(until_start_time_min / 60)) + "h\n" + elif until_start_time_min > 1440: + until_start = "距开始:" + str(int(until_start_time_min / 60 / 24)) + "days\n" + else: + until_start = "距开始:未知\n" + all_matches = "".join([all_matches, until_start]) + if matches["phase"] == "FINISHED": + i = True + print(all_matches) + await cf_query.finish(all_matches)