mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-Nonebot.git
synced 2026-04-01 22:04:51 +00:00
新增查询codeforces比赛功能
修复了ai功能关闭情况下回复慢的BUG
This commit is contained in:
parent
3933a03cac
commit
acad76111a
2 changed files with 53 additions and 4 deletions
|
|
@ -8,7 +8,7 @@ from src.ai_chat import ai_chat
|
||||||
import os
|
import os
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
menu = ['/今日运势','/天气','/图','/点歌','/摸摸头','/群老婆','/今日老婆', '/待办', '/test', '我喜欢你', "❤", "/待办查询", "/新建待办", "/删除待办", "/openai"]
|
menu = ['/今日运势','/天气','/图','/点歌','/摸摸头','/群老婆','/今日老婆', '/待办', '/test', '我喜欢你', "❤", "/待办查询", "/新建待办", "/删除待办", "/openai", "/cf"]
|
||||||
async def check_value_in_menu(event: Event) -> bool:
|
async def check_value_in_menu(event: Event) -> bool:
|
||||||
value = event.get_plaintext().strip().split(" ")
|
value = event.get_plaintext().strip().split(" ")
|
||||||
if value[0] in menu:
|
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 = on_message(rule=to_me() & rule ,block=True)
|
||||||
@check.handle()
|
@check.handle()
|
||||||
async def check(bot: Bot, event: Event):
|
async def check(bot: Bot, event: Event):
|
||||||
print(event.get_plaintext())
|
|
||||||
msg = ai_chat.gpt(event.get_plaintext())
|
|
||||||
print(msg)
|
|
||||||
if is_ai == "True":
|
if is_ai == "True":
|
||||||
|
print(event.get_plaintext())
|
||||||
|
msg = ai_chat.gpt(event.get_plaintext())
|
||||||
|
print(msg)
|
||||||
await bot.send(message=msg,event=event)
|
await bot.send(message=msg,event=event)
|
||||||
else:
|
else:
|
||||||
await bot.send(message=Message(random.choice(text_list)),event=event)
|
await bot.send(message=Message(random.choice(text_list)),event=event)
|
||||||
|
|
|
||||||
49
src/qq_plugins/codeforces.py
Normal file
49
src/qq_plugins/codeforces.py
Normal file
|
|
@ -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)
|
||||||
Loading…
Reference in a new issue