fix: 按照对话模式提供单轮比赛预测
This commit is contained in:
parent
60f0c7ee7e
commit
d5252708e8
14
.env.dev
14
.env.dev
@ -1 +1,15 @@
|
||||
LOG_LEVEL=DEBUG
|
||||
DRIVER=~fastapi
|
||||
HOST=127.0.0.1
|
||||
PORT=10088
|
||||
LOG_LEVEL=INFO
|
||||
# 管理员
|
||||
SUPERUSERS=["xiaoyan159"]
|
||||
# 管理员昵称
|
||||
NICKNAME=["管理员"]
|
||||
# 命令起始符号
|
||||
COMMAND_START=["/", "!"]
|
||||
# 命令分隔符
|
||||
COMMAND_SEP=[".", "/"," "]
|
||||
# 用户会话超时时间
|
||||
SESSION_EXPIRE_TIMEOUT=20
|
15
.env.prod
15
.env.prod
@ -0,0 +1,15 @@
|
||||
LOG_LEVEL=DEBUG
|
||||
DRIVER=~fastapi
|
||||
HOST=127.0.0.1
|
||||
PORT=20000
|
||||
LOG_LEVEL=INFO
|
||||
# 管理员
|
||||
SUPERUSERS=["xiaoyan159"]
|
||||
# 管理员昵称
|
||||
NICKNAME=["管理员"]
|
||||
# 命令起始符号
|
||||
COMMAND_START=["/", "!"]
|
||||
# 命令分隔符
|
||||
COMMAND_SEP=[".", "/"," "]
|
||||
# 用户会话超时时间
|
||||
SESSION_EXPIRE_TIMEOUT=20
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -109,7 +109,6 @@ celerybeat.pid
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
|
3
.idea/NoneBot-Xiao.iml
generated
3
.idea/NoneBot-Xiao.iml
generated
@ -3,8 +3,9 @@
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (Nonebot2-Xiao)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (NoneBot-Xiao)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (Nonebot2-Xiao)" project-jdk-type="Python SDK" />
|
||||
</project>
|
12
bot.py
12
bot.py
@ -1,9 +1,9 @@
|
||||
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 飞书Adapter
|
||||
#
|
||||
# from nonebot.adapters.ntchat import Adapter as NTCHATAdapter
|
||||
|
||||
|
||||
|
||||
@ -12,9 +12,9 @@ nonebot.init()
|
||||
driver = nonebot.get_driver()
|
||||
driver.register_adapter(ONEBOT_V11Adapter)
|
||||
|
||||
driver.register_adapter(飞书Adapter)
|
||||
|
||||
driver.register_adapter(NTCHATAdapter)
|
||||
# driver.register_adapter(飞书Adapter)
|
||||
#
|
||||
# driver.register_adapter(NTCHATAdapter)
|
||||
|
||||
nonebot.load_builtin_plugins('echo')
|
||||
|
||||
|
14
config.yml
14
config.yml
@ -1,8 +1,8 @@
|
||||
# go-cqhttp 默认配置文件
|
||||
|
||||
account: # 账号相关
|
||||
uin: 1233456 # QQ账号
|
||||
password: '' # 密码为空时使用扫码登录
|
||||
uin: 1648107533 # QQ账号
|
||||
password: 'xiaoyan159062' # 密码为空时使用扫码登录
|
||||
encrypt: false # 是否开启密码加密
|
||||
status: 0 # 在线状态 请参考 https://docs.go-cqhttp.org/guide/config.html#在线状态
|
||||
relogin: # 重连设置
|
||||
@ -96,11 +96,11 @@ servers:
|
||||
- ws-reverse:
|
||||
# 反向WS Universal 地址
|
||||
# 注意 设置了此项地址后下面两项将会被忽略
|
||||
universal: ws://your_websocket_universal.server
|
||||
# 反向WS API 地址
|
||||
api: ws://your_websocket_api.server
|
||||
# 反向WS Event 地址
|
||||
event: ws://your_websocket_event.server
|
||||
universal: ws://127.0.0.1:10088/onebot/v11/ws/
|
||||
# # 反向WS API 地址
|
||||
# api: ws://your_websocket_api.server
|
||||
# # 反向WS Event 地址
|
||||
# event: ws://your_websocket_event.server
|
||||
# 重连间隔 单位毫秒
|
||||
reconnect-interval: 3000
|
||||
middlewares:
|
||||
|
@ -96,7 +96,7 @@ servers:
|
||||
- ws-reverse:
|
||||
# 反向WS Universal 地址
|
||||
# 注意 设置了此项地址后下面两项将会被忽略
|
||||
universal: ws://127.0.0.1:18000/onebot/v11/ws
|
||||
universal: ws://127.0.0.1:20000/onebot/v11/ws
|
||||
# 反向WS API 地址
|
||||
# api: ws://your_websocket_api.server
|
||||
# 反向WS Event 地址
|
||||
|
15
src/plugins/weather/__init__.py
Normal file
15
src/plugins/weather/__init__.py
Normal file
@ -0,0 +1,15 @@
|
||||
from pathlib import Path
|
||||
|
||||
import nonebot
|
||||
from nonebot import get_driver
|
||||
|
||||
from .config import Config
|
||||
|
||||
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())
|
||||
)
|
||||
|
5
src/plugins/weather/config.py
Normal file
5
src/plugins/weather/config.py
Normal file
@ -0,0 +1,5 @@
|
||||
from pydantic import BaseModel, Extra
|
||||
|
||||
|
||||
class Config(BaseModel, extra=Extra.ignore):
|
||||
"""Plugin Config Here"""
|
34
src/plugins/weather/plugins/MyWeather.py
Normal file
34
src/plugins/weather/plugins/MyWeather.py
Normal file
@ -0,0 +1,34 @@
|
||||
from nonebot import on_command
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.adapters import Message
|
||||
from nonebot.params import Arg, CommandArg, ArgPlainText
|
||||
|
||||
|
||||
weather = on_command("weather", rule=to_me(), aliases={"天气", "天气预报"}, priority=5)
|
||||
|
||||
@weather.handle()
|
||||
async def handle_first_receive(matcher: Matcher, args: Message = CommandArg()):
|
||||
plain_text = args.extract_plain_text() # 首次发送命令时跟随的参数,例:/天气 上海,则args为上海
|
||||
if plain_text:
|
||||
matcher.set_arg("city", args) # 如果用户发送了参数则直接赋值
|
||||
|
||||
|
||||
|
||||
|
||||
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
|
||||
async def handle_city(city: Message = Arg(), city_name: str = ArgPlainText("city")):
|
||||
if city_name not in ["北京", "上海"]: # 如果参数不符合要求,则提示用户重新输入
|
||||
# 可以使用平台的 Message 类直接构造模板消息
|
||||
await weather.reject(city.template("你想查询的城市 {city} 暂不支持,请重新输入!"))
|
||||
|
||||
|
||||
city_weather = await get_weather(city_name)
|
||||
await weather.finish(city_weather)
|
||||
|
||||
|
||||
|
||||
|
||||
# 在这里编写获取天气信息的函数
|
||||
async def get_weather(city: str) -> str:
|
||||
return f"{city}的天气是..."
|
@ -4,13 +4,12 @@ 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 nonebot.matcher import Matcher
|
||||
from nonebot.adapters import Message
|
||||
from nonebot.params import Arg, CommandArg, ArgPlainText
|
||||
from requests_html import HTMLSession, HTML
|
||||
|
||||
global_config = get_driver().config
|
||||
@ -20,49 +19,3 @@ _sub_plugins = set()
|
||||
_sub_plugins |= nonebot.load_plugins(
|
||||
str((Path(__file__).parent / "plugins").resolve())
|
||||
)
|
||||
|
||||
zhibo8Command = on_command("/zhibo8", rule=to_me(), aliases={'预测', '英超', 'zhibo'}, priority=10)
|
||||
|
||||
xiaobianStr = r"""
|
||||
小编们预测比分:
|
||||
太能喵:
|
||||
叶小欢:
|
||||
大帝强:
|
||||
小小:
|
||||
"""
|
||||
|
||||
|
||||
@zhibo8Command.handle()
|
||||
async def handler_zhibo8(bot: Bot, event: Event, state: T_State):
|
||||
session = HTMLSession()
|
||||
zhibo8Get = session.get("http://www.zhibo8.cc")
|
||||
print(zhibo8Get)
|
||||
saishiContent = zhibo8Get.html.xpath("//ul/li[starts-with(@id, 'saishi')]")
|
||||
vsMap = dict()
|
||||
# 解析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)
|
||||
|
||||
resultStr = ""
|
||||
for roudNum in vsMap:
|
||||
resultStr += "【" + roudNum.replace("第", "联赛 第") + " 比分预测】\r\n"
|
||||
for vs in vsMap[roudNum]:
|
||||
resultStr += vs + xiaobianStr+"\r\n"
|
||||
await zhibo8Command.finish(resultStr)
|
||||
|
||||
|
||||
def parserSaishiItem(saishiStr):
|
||||
html = HTML(html=saishiStr)
|
||||
listItem = html.xpath("//b//text()")
|
||||
roundNum = listItem[0].split(" ")[0].strip()
|
||||
homeName = listItem[0].split(" ")[1].strip()
|
||||
awayName = listItem[-1].strip()
|
||||
timeStr = html.xpath("//li/@data-time")
|
||||
time = datetime.strptime(timeStr[0], "%Y-%m-%d %H:%M")
|
||||
return (roundNum, time.strftime("%m月%d日%H:%M") + " " + homeName + " vs " + awayName)
|
||||
|
79
src/plugins/zhibo8/plugins/Foresee.py
Normal file
79
src/plugins/zhibo8/plugins/Foresee.py
Normal file
@ -0,0 +1,79 @@
|
||||
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()):
|
||||
# 事件预处理,获取对应的赛程数据
|
||||
session = HTMLSession()
|
||||
zhibo8Get = session.get("http://www.zhibo8.cc")
|
||||
print(zhibo8Get)
|
||||
saishiContent = zhibo8Get.html.xpath("//ul/li[starts-with(@id, 'saishi')]")
|
||||
# 解析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 = listItem[0].split(" ")[0].strip()
|
||||
homeName = listItem[0].split(" ")[1].strip()
|
||||
awayName = listItem[-1].strip()
|
||||
timeStr = html.xpath("//li/@data-time")
|
||||
time = datetime.strptime(timeStr[0], "%Y-%m-%d %H:%M")
|
||||
return (roundNum, time.strftime("%m月%d日%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
|
Loading…
x
Reference in New Issue
Block a user