minatoaquacrews / nonebot_plugin_what2eat Goto Github PK
View Code? Open in Web Editor NEWWhat2eat & what2drink plugin for nonebot2
License: MIT License
What2eat & what2drink plugin for nonebot2
License: MIT License
至少来个几千种吧(😋
dev-v0.4.0
新的功能:今天喝什么?实现你问今天喝什么
,Bot随机选取并回答:
不如来一杯 大杯 去冰 半糖 四季玛奇朵,加波霸和椰果!
当然,上述回答形式没有固定,但是我想实现的随机选取的变量有:
可以去dev
分支查看drinking.json
、drinking2.json
以及data_source.py
的部分代码:
class DrinkingManager:
...
json
文件存有诸如一点点
、茶颜悦色
、蜜雪冰城
、CoCo
的菜单信息,代码部分仅列出了选取的逻辑。目前,我仅考虑一点点
的点单逻辑就稍显复杂了,后续喜茶
等品牌则更复杂。问题有:
喜茶
中更为常见);一点点
)。期望实现大概率添加1~3项不同的配料,小概率添加1项付费配料,总配料不宜过多;茶颜悦色
泡沫茶仅有茶小冻
选项,而奶盖茶无茶小冻
而有加坚果碎
等选项)、或者配料均付费(例如CoCo
)一般人不会加太多种、或者更复杂如喜茶
部分饮品的配料升级/替换的逻辑(冷热饮可选或可更换的配料不同);json
),虽然比较清晰,如此选择逻辑的实现也导致代码会比较复杂,例如Q1、Q3:{
"一点点": {
"cup": [
"中杯",
"大杯"
],
"sugar_level": [
"无糖",
"三分糖",
"五分糖",
"七分糖",
"全糖"
],
"ice_level": [
"热",
"标准冰",
"少冰",
"去冰",
"常温"
],
"ingredients": {
"free": [
...
],
"paid": [
...
]
},
"drinks": {
"general": [
...
],
"hot_only": [
...
],
"ice_only": [
...
]
}
}
}
如果您有更好的想法或建议,欢迎提出!🥳 此issue长期开启
就是这一配置 GREETING_GROUPS_ID=["123456789", "987654321"] # 默认开启小助手的群组,或{"123456789", "987654321"}
加了群号运行一次之后,注释掉或者清空群号还是会每个时间段提醒。greetings.json
里记录为(示例)
"groups_id": {
"123456789": true,
"": true
发送:晚上喝啥/今晚吃啥 等都回出现类似的log
06-15 16:54:00 [SUCCESS] nonebot | OneBot V11 ********* | [message.group.normal]: Message *********from ***********@[群:**********] '晚上喝啥'
06-15 16:54:00 [DEBUG] nonebot | Checking for matchers in priority 1...
06-15 16:54:00 [DEBUG] nonebot | Checking for matchers in priority 5...
06-15 16:54:00 [DEBUG] nonebot | Checking for matchers in priority 10...
06-15 16:54:00 [DEBUG] nonebot | Checking for matchers in priority 12...
06-15 16:54:00 [DEBUG] nonebot | Checking for matchers in priority 15...
06-15 16:54:00 [INFO] nonebot | Event will be handled by Matcher(type='message', module=src.plugins.nonebot_plugin_what2eat)
06-15 16:54:00 [DEBUG] nonebot | Running Matcher(type='message', module=src.plugins.nonebot_plugin_what2eat)
06-15 16:54:00 [DEBUG] nonebot | Running handler Dependent(call=_)
06-15 16:54:00 [DEBUG] nonebot | Handler Dependent(call=_) skipped
06-15 16:54:00 [INFO] nonebot | Matcher(type='message', module=src.plugins.nonebot_plugin_what2eat) running complete
06-15 16:54:00 [DEBUG] nonebot | Stop event propagation
06-15 16:54:00 [DEBUG] nonebot | Checking for matchers completed
06-15 16:54:00 [DEBUG] nonebot | Running PostProcessors...
06-15 16:54:01 [DEBUG] nonebot | Running PostProcessors...
其中的Handler Dependent(call=_) skipped
可能是问题的关键,但是我不清楚为什么会被skip
插件中使用on_command的命令是可以执行的,log如下,bot回复的是test已加入群特色菜单~
06-15 16:54:43 [SUCCESS] nonebot | OneBot V11 *****| [message.group.normal]: Message -*****from *****@[群:*****] '添加 test'
06-15 16:54:43 [DEBUG] nonebot | Checking for matchers in priority 1...
06-15 16:54:43 [DEBUG] nonebot | Checking for matchers in priority 5...
06-15 16:54:43 [DEBUG] nonebot | Checking for matchers in priority 10...
06-15 16:54:43 [DEBUG] nonebot | Checking for matchers in priority 12...
06-15 16:54:43 [DEBUG] nonebot | Checking for matchers in priority 15...
06-15 16:54:43 [INFO] nonebot | Event will be handled by Matcher(type='message', module=src.plugins.nonebot_plugin_what2eat)
06-15 16:54:43 [DEBUG] nonebot | Running Matcher(type='message', module=src.plugins.nonebot_plugin_what2eat)
06-15 16:54:43 [DEBUG] nonebot | Running handler Dependent(call=_)
06-15 16:54:43 [DEBUG] nonebot | OneBot V11 | Calling API send_msg
06-15 16:54:43 [DEBUG] nonebot | Running CalledAPI hooks...
06-15 16:54:43 [INFO] nonebot | Matcher(type='message', module=src.plugins.nonebot_plugin_what2eat) running complete
06-15 16:54:43 [DEBUG] nonebot | Stop event propagation
06-15 16:54:43 [DEBUG] nonebot | Checking for matchers completed
06-15 16:54:43 [DEBUG] nonebot | Running PostProcessors...
比如在群A添加了群特色菜品
在群B就会显示菜品已添加
resource
另外,插件第一次的时候并没有正常的创建 data.json
与 greating.json
此时我的配置是(用的yaml)
what2eat_path: data/what2eat
use_preset_menu: true
use_preset_greating: true
插件会报错,FileNotFoundError: [Errno 2] No such file or directory: 'data/what2eat/data.json'
今天吃什么指令无回复,同#41.已尝试切换到v-0.4.x和切换到较早commit,无效果。
顺便问下图片资源在哪里下载
BOT无反应
日志如下
08-25 23:42:15 [SUCCESS] nonebot | ONEBOT V11 2821521344 | [message.group.normal]: Message -1918647081 from 609638635@[ 群:1006443456] "晚上吃什么"
08-25 23:42:15 [INFO] nonebot | Event will be handled by <Matcher from nonebot_plugin_what2eat, type=message, priority=15, temp=False>
08-25 23:42:15 [INFO] nonebot | Matcher <Matcher from nonebot_plugin_what2eat, type=message, priority=15, temp=False> running complete
08-25 23:42:15 [ERROR] nonebot | Running matcher <Matcher from nonebot_plugin_what2eat, type=message, priority=15, temp=False> failed.
Traceback (most recent call last):
File "c:\users\administrator\appdata\local\programs\python\python38\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\administrator\appdata\local\programs\python\python38\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\Scripts\nb.exe\__main__.py", line 7, in <module>
sys.exit(main())
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\nb_cli\commands\main.py", line 30, in run
run_bot(file, app)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\nb_cli\handlers\deploy.py", line 25, in run_bot
nonebot.run(app=f"{module_name}:{app}")
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\nonebot\__init__.py", line 261, in run
get_driver().run(*args, **kwargs)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\nonebot\drivers\fastapi.py", line 170, in run
uvicorn.run(
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\uvicorn\main.py", line 576, in run
server.run()
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\uvicorn\server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "c:\users\administrator\appdata\local\programs\python\python38\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\asyncio\base_events.py", line 603, in run_until_complete
self.run_forever()
File "c:\users\administrator\appdata\local\programs\python\python38\lib\asyncio\windows_events.py", line 316, in run_forever
super().run_forever()
File "c:\users\administrator\appdata\local\programs\python\python38\lib\asyncio\base_events.py", line 570, in run_forever
self._run_once()
File "c:\users\administrator\appdata\local\programs\python\python38\lib\asyncio\base_events.py", line 1859, in _run_once
handle._run()
File "c:\users\administrator\appdata\local\programs\python\python38\lib\asyncio\events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\nonebot\message.py", line 146, in _check_matcher
await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)
> File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\nonebot\message.py", line 196, in _run_matcher
await matcher.run(bot, event, state, stack, dependency_cache)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\nonebot\internal\matcher.py", line 672, in run
await self.simple_run(bot, event, state, stack, dependency_cache)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\nonebot\internal\matcher.py", line 639, in simple_run
await handler(
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\nonebot\dependencies\__init__.py", line 92, in __call__
return await self.call(**values)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\nonebot_plugin_what2eat\__init__.py", line 45, in _
msg = eating_manager.get2eat(event)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\nonebot_plugin_what2eat\data_source.py", line 48, in get2eat
self._eating = load_json(self._eating_json)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\nonebot_plugin_what2eat\utils.py", line 53, in load_json
return json.load(f)
ValueError: Unexpected character found when decoding array value (1)
在.env.{environment}文件中设置如下:
GROUPS_ID=["123456789"]
报错:
if len(self._data["group_food"][group_id]) > 0:
KeyError: '123456789'
05-02 21:16:25 [WARNING] nonebot_plugin_what2eat | What2eat text resource missing! Please check!
05-02 21:16:25 [ERROR] uvicorn | Traceback (most recent call last):
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\site-packages\starlette\routing.py", line 677, in lifespan
async with self.lifespan_context(app) as maybe_state:
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 199, in __aenter__
return await anext(self.gen)
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot\drivers\fastapi.py", line 165, in _lifespan_manager
await self._lifespan.startup()
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot\drivers\_lifespan.py", line 35, in startup
await self._run_lifespan_func(self._startup_funcs)
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot\drivers\_lifespan.py", line 29, in _run_lifespan_func
await cast(ASYNC_LIFESPAN_FUNC, func)()
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot_plugin_what2eat\config.py", line 240, in what2eat_check
await eating_check()
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot_plugin_what2eat\config.py", line 77, in eating_check
raise ResourceError("Missing necessary resource: eating.json!")
nonebot_plugin_what2eat.config.ResourceError: Missing necessary resource: eating.json!
05-02 21:16:25 [ERROR] uvicorn | Application startup failed. Exiting.
05-02 21:16:25 [ERROR] apscheduler | Job "dy_sched (trigger: date[2023-05-02 21:16:25 CST], next run at: 2023-05-02 21:16:25 CST)" raised an exception
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot\__init__.py", line 309, in run
get_driver().run(*args, **kwargs)
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot\drivers\fastapi.py", line 198, in run
uvicorn.run(
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\site-packages\uvicorn\main.py", line 568, in run
server.run()
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\site-packages\uvicorn\server.py", line 59, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 47, in run
_cancel_all_tasks(loop)
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 63, in _cancel_all_tasks
loop.run_until_complete(tasks.gather(*to_cancel, return_exceptions=True))
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 633, in run_until_complete
self.run_forever()
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 321, in run_forever
super().run_forever()
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 600, in run_forever
self._run_once()
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 1896, in _run_once
handle._run()
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
> File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\site-packages\apscheduler\executors\base_py3.py", line 30, in run_coroutine_job
retval = await job.func(*job.args, **job.kwargs)
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\site-packages\haruka_bot\plugins\pusher\dynamic_pusher.py", line 28, in dy_sched
await asyncio.sleep(1)
File "C:\Users\hakurei\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 605, in sleep
return await future
asyncio.exceptions.CancelledError
使用"加菜 西北风",机器人无回复后台报错。
07-30 18:59:59 [ERROR] nonebot | Running matcher <Matcher from nonebot_plugin_what2eat, type=message, priority=15, temp=False> failed.
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.9/multiprocessing/spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "/usr/lib/python3.9/multiprocessing/spawn.py", line 129, in _main
return self._bootstrap(parent_sentinel)
File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/usr/lib/python3.9/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.9/dist-packages/uvicorn/subprocess.py", line 76, in subprocess_started
target(sockets=sockets)
File "/usr/local/lib/python3.9/dist-packages/uvicorn/server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.9/dist-packages/nonebot/message.py", line 146, in _check_matcher
await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)
File "/usr/local/lib/python3.9/dist-packages/nonebot/message.py", line 196, in _run_matcher
await matcher.run(bot, event, state, stack, dependency_cache)
File "/usr/local/lib/python3.9/dist-packages/nonebot/internal/matcher.py", line 668, in run
await self.simple_run(bot, event, state, stack, dependency_cache)
File "/usr/local/lib/python3.9/dist-packages/nonebot/internal/matcher.py", line 635, in simple_run
await handler(
File "/usr/local/lib/python3.9/dist-packages/nonebot/dependencies/init.py", line 92, in call
return await self.call(**values)
File "/usr/local/lib/python3.9/dist-packages/nonebot_plugin_what2eat/init.py", line 69, in _
msg = eating_manager.add_basic_food(new_food)
File "/usr/local/lib/python3.9/dist-packages/nonebot_plugin_what2eat/data_source.py", line 150, in add_basic_food
status: FoodLoc = self._is_food_exists(new_food)
TypeError: _is_food_exists() missing 1 required positional argument: 'gid'
当我在一个全新的环境中启动(python3.11),插件加载错误(其余几个插件均正常),具体报错日志如下
05-08 04:34:15 [ERROR] nonebot | Failed to import "nonebot_plugin_what2eat"
Traceback (most recent call last):
File "/root/Ansel-Bot/bot.py", line 25, in <module>
nonebot.load_plugin('nonebot_plugin_what2eat')
File "/root/mambaforge/envs/nonebot/lib/python3.11/site-packages/nonebot/plugin/load.py", line 37, in load_plugin
return manager.load_plugin(module_path)
> File "/root/mambaforge/envs/nonebot/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 141, in load_plugin
module = importlib.import_module(name)
File "/root/mambaforge/envs/nonebot/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "/root/mambaforge/envs/nonebot/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 240, in exec_module
super().exec_module(module)
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/root/mambaforge/envs/nonebot/lib/python3.11/site-packages/nonebot_plugin_what2eat/__init__.py", line 6, in <module>
from .utils import eating_manager, Meals, GROUPS_ID
File "/root/mambaforge/envs/nonebot/lib/python3.11/site-packages/nonebot_plugin_what2eat/utils.py", line 24, in <module>
_GROUPS_ID = nonebot.get_driver().config.groups_id
AttributeError: 'Config' object has no attribute 'groups_id'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.