From 1625be957a396f4275fae4e1bdbd9c0872aca720 Mon Sep 17 00:00:00 2001 From: Richard Chien Date: Mon, 16 Mar 2020 17:42:32 +0800 Subject: [PATCH] remove demo package --- demo/__init__.py | 22 --------------- demo/config.py | 11 -------- demo/plugins/groupadmin.py | 30 -------------------- demo/plugins/repeater.py | 20 ------------- demo/plugins/tuling.py | 44 ----------------------------- demo/plugins/usage.py | 14 --------- demo/plugins/weather/__init__.py | 43 ---------------------------- demo/plugins/weather/expressions.py | 12 -------- 8 files changed, 196 deletions(-) delete mode 100644 demo/__init__.py delete mode 100644 demo/config.py delete mode 100644 demo/plugins/groupadmin.py delete mode 100644 demo/plugins/repeater.py delete mode 100644 demo/plugins/tuling.py delete mode 100644 demo/plugins/usage.py delete mode 100644 demo/plugins/weather/__init__.py delete mode 100644 demo/plugins/weather/expressions.py diff --git a/demo/__init__.py b/demo/__init__.py deleted file mode 100644 index 4338d4fb..00000000 --- a/demo/__init__.py +++ /dev/null @@ -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) diff --git a/demo/config.py b/demo/config.py deleted file mode 100644 index 9982e59a..00000000 --- a/demo/config.py +++ /dev/null @@ -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'#|::?')} diff --git a/demo/plugins/groupadmin.py b/demo/plugins/groupadmin.py deleted file mode 100644 index 720e157b..00000000 --- a/demo/plugins/groupadmin.py +++ /dev/null @@ -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() diff --git a/demo/plugins/repeater.py b/demo/plugins/repeater.py deleted file mode 100644 index 22c3f524..00000000 --- a/demo/plugins/repeater.py +++ /dev/null @@ -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 diff --git a/demo/plugins/tuling.py b/demo/plugins/tuling.py deleted file mode 100644 index eee5ed1b..00000000 --- a/demo/plugins/tuling.py +++ /dev/null @@ -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 - }) diff --git a/demo/plugins/usage.py b/demo/plugins/usage.py deleted file mode 100644 index c2d8b9a2..00000000 --- a/demo/plugins/usage.py +++ /dev/null @@ -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) diff --git a/demo/plugins/weather/__init__.py b/demo/plugins/weather/__init__.py deleted file mode 100644 index a6d53124..00000000 --- a/demo/plugins/weather/__init__.py +++ /dev/null @@ -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') diff --git a/demo/plugins/weather/expressions.py b/demo/plugins/weather/expressions.py deleted file mode 100644 index a89cd9b5..00000000 --- a/demo/plugins/weather/expressions.py +++ /dev/null @@ -1,12 +0,0 @@ -WHICH_CITY = ( - '你想知道哪个城市的天气呢?', - '你要查询的城市是哪个呢?', - '你要查询哪个城市呢?', - '哪个城市呢?', - '请告诉我你要查询的城市~', -) - -REPORT = ( - '你查询了{city}的天气', - '{city}的天气是……', -)