mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-12-01 01:25:07 +08:00
remove demo package
This commit is contained in:
parent
035782715f
commit
1625be957a
@ -1,22 +0,0 @@
|
|||||||
from os import path
|
|
||||||
|
|
||||||
import nonebot
|
|
||||||
from demo import config
|
|
||||||
|
|
||||||
nonebot.init(config)
|
|
||||||
|
|
||||||
|
|
||||||
@nonebot.scheduler.scheduled_job('interval', seconds=20)
|
|
||||||
async def cb():
|
|
||||||
bot_ = nonebot.get_bot()
|
|
||||||
try:
|
|
||||||
await bot_.send_private_msg(user_id=1002647525, message='哇')
|
|
||||||
except Exception as e:
|
|
||||||
nonebot.logger.exception(e)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
nonebot.load_builtin_plugins()
|
|
||||||
nonebot.load_plugins(path.join(path.dirname(__file__), 'plugins'),
|
|
||||||
'demo.plugins')
|
|
||||||
nonebot.run(host=config.HOST, port=config.PORT)
|
|
@ -1,11 +0,0 @@
|
|||||||
import re
|
|
||||||
|
|
||||||
from nonebot.default_config import *
|
|
||||||
|
|
||||||
HOST = '0.0.0.0'
|
|
||||||
SECRET = 'abc'
|
|
||||||
|
|
||||||
SUPERUSERS = {1002647525}
|
|
||||||
NICKNAME = {'奶茶', '小奶茶'}
|
|
||||||
COMMAND_START = {'', '/', '!', '/', '!', re.compile(r'^>+\s*')}
|
|
||||||
COMMAND_SEP = {'/', '.', re.compile(r'#|::?')}
|
|
@ -1,30 +0,0 @@
|
|||||||
from aiocqhttp import Error as CQHttpError
|
|
||||||
|
|
||||||
from nonebot import on_notice, NoticeSession, on_request, RequestSession
|
|
||||||
from nonebot.helpers import render_expression as __
|
|
||||||
|
|
||||||
GROUP_GREETING = (
|
|
||||||
'欢迎新同学 {name}[]![CQ:face,id=63][CQ:face,id=63][CQ:face,id=63]',
|
|
||||||
'[CQ:face,id=99]欢迎新成员~',
|
|
||||||
'欢迎 {name}👏👏~',
|
|
||||||
'[CQ:at,qq={user_id}] 欢迎欢迎👏',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@on_notice('group_increase')
|
|
||||||
async def _(session: NoticeSession):
|
|
||||||
if session.ctx['group_id'] not in (201865589, 672076603):
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
info = await session.bot.get_group_member_info(**session.ctx,
|
|
||||||
no_cache=True)
|
|
||||||
name = info['card'] or info['nickname'] or '新成员'
|
|
||||||
await session.send(__(GROUP_GREETING, name=name, **session.ctx))
|
|
||||||
except CQHttpError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@on_request('group')
|
|
||||||
async def _(session: RequestSession):
|
|
||||||
if session.ctx['group_id'] == 672076603:
|
|
||||||
await session.approve()
|
|
@ -1,20 +0,0 @@
|
|||||||
from nonebot import on_natural_language, NLPSession, NLPResult
|
|
||||||
|
|
||||||
_last_session = None
|
|
||||||
|
|
||||||
|
|
||||||
@on_natural_language(only_to_me=False)
|
|
||||||
async def _(session: NLPSession):
|
|
||||||
if session.ctx.get('group_id') != 672076603:
|
|
||||||
return None
|
|
||||||
|
|
||||||
global _last_session
|
|
||||||
result = None
|
|
||||||
if _last_session and \
|
|
||||||
_last_session.ctx['user_id'] != session.ctx['user_id'] and \
|
|
||||||
_last_session.msg == session.msg:
|
|
||||||
result = NLPResult(61.0, 'echo', {'message': _last_session.msg})
|
|
||||||
_last_session = None
|
|
||||||
else:
|
|
||||||
_last_session = session
|
|
||||||
return result
|
|
@ -1,44 +0,0 @@
|
|||||||
from nonebot import (
|
|
||||||
on_command, CommandSession,
|
|
||||||
on_natural_language, NLPSession, NLPResult
|
|
||||||
)
|
|
||||||
|
|
||||||
__plugin_name__ = '智能聊天'
|
|
||||||
__plugin_usage__ = r"""
|
|
||||||
智能聊天功能使用帮助
|
|
||||||
|
|
||||||
直接跟我聊天即可~
|
|
||||||
""".strip()
|
|
||||||
|
|
||||||
|
|
||||||
@on_command('tuling', aliases=('聊天', '对话'))
|
|
||||||
async def tuling(session: CommandSession):
|
|
||||||
message = session.get('message', prompt='我已经准备好啦,来跟我聊天吧~')
|
|
||||||
|
|
||||||
finish = message in ('结束', '拜拜', '再见')
|
|
||||||
if finish:
|
|
||||||
session.finish('拜拜啦,你忙吧,下次想聊天随时找我哦~')
|
|
||||||
return
|
|
||||||
|
|
||||||
# call tuling api
|
|
||||||
reply = f'你说了:{message}'
|
|
||||||
|
|
||||||
one_time = session.get_optional('one_time', False)
|
|
||||||
if one_time:
|
|
||||||
session.finish(reply)
|
|
||||||
else:
|
|
||||||
session.pause(reply)
|
|
||||||
|
|
||||||
|
|
||||||
@tuling.args_parser
|
|
||||||
async def _(session: CommandSession):
|
|
||||||
if session.current_key == 'message':
|
|
||||||
session.args[session.current_key] = session.current_arg_text.strip()
|
|
||||||
|
|
||||||
|
|
||||||
@on_natural_language
|
|
||||||
async def _(session: NLPSession):
|
|
||||||
return NLPResult(60.0, 'tuling', {
|
|
||||||
'message': session.msg,
|
|
||||||
'one_time': True
|
|
||||||
})
|
|
@ -1,14 +0,0 @@
|
|||||||
import nonebot
|
|
||||||
from nonebot import on_command, CommandSession
|
|
||||||
|
|
||||||
|
|
||||||
@on_command('usage', aliases=['使用帮助', '帮助', '使用方法'])
|
|
||||||
async def _(session: CommandSession):
|
|
||||||
plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))
|
|
||||||
arg = session.current_arg_text.strip().lower()
|
|
||||||
if not arg:
|
|
||||||
session.finish(
|
|
||||||
'我现在支持的功能有:\n\n' + '\n'.join(p.name for p in plugins))
|
|
||||||
for p in plugins:
|
|
||||||
if p.name.lower() == arg:
|
|
||||||
await session.send(p.usage)
|
|
@ -1,43 +0,0 @@
|
|||||||
from nonebot import (
|
|
||||||
CommandSession, CommandGroup,
|
|
||||||
on_natural_language, NLPSession, NLPResult
|
|
||||||
)
|
|
||||||
from nonebot.helpers import render_expression as __
|
|
||||||
|
|
||||||
from . import expressions as e
|
|
||||||
|
|
||||||
__plugin_name__ = '天气'
|
|
||||||
__plugin_usage__ = r"""
|
|
||||||
天气功能使用帮助
|
|
||||||
|
|
||||||
天气 [城市名称]
|
|
||||||
""".strip()
|
|
||||||
|
|
||||||
w = CommandGroup('weather')
|
|
||||||
|
|
||||||
|
|
||||||
@w.command('weather', aliases=('天气', '天气预报'))
|
|
||||||
async def weather(session: CommandSession):
|
|
||||||
city = session.get('city', prompt=__(e.WHICH_CITY))
|
|
||||||
await session.send(__(e.REPORT, city=city))
|
|
||||||
|
|
||||||
|
|
||||||
@weather.args_parser
|
|
||||||
async def _(session: CommandSession):
|
|
||||||
striped_arg = session.current_arg_text.strip()
|
|
||||||
if session.current_key:
|
|
||||||
session.args[session.current_key] = striped_arg
|
|
||||||
elif striped_arg:
|
|
||||||
session.args['city'] = striped_arg
|
|
||||||
|
|
||||||
|
|
||||||
@on_natural_language({'天气', '雨', '雪', '晴', '阴'}, only_to_me=False)
|
|
||||||
async def _(session: NLPSession):
|
|
||||||
if not ('?' in session.msg_text or '?' in session.msg_text):
|
|
||||||
return None
|
|
||||||
return NLPResult(90.0, ('weather', 'weather'), {})
|
|
||||||
|
|
||||||
|
|
||||||
@w.command('suggestion', aliases=('生活指数', '生活建议', '生活提示'))
|
|
||||||
async def suggestion(session: CommandSession):
|
|
||||||
await session.send('suggestion')
|
|
@ -1,12 +0,0 @@
|
|||||||
WHICH_CITY = (
|
|
||||||
'你想知道哪个城市的天气呢?',
|
|
||||||
'你要查询的城市是哪个呢?',
|
|
||||||
'你要查询哪个城市呢?',
|
|
||||||
'哪个城市呢?',
|
|
||||||
'请告诉我你要查询的城市~',
|
|
||||||
)
|
|
||||||
|
|
||||||
REPORT = (
|
|
||||||
'你查询了{city}的天气',
|
|
||||||
'{city}的天气是……',
|
|
||||||
)
|
|
Loading…
Reference in New Issue
Block a user