From f5ceb8927f2e7f2a9e29d62c8e4cef876f917249 Mon Sep 17 00:00:00 2001 From: Kyomotoi <1172294279@qq.com> Date: Sat, 6 Feb 2021 00:32:26 +0800 Subject: =?UTF-8?q?=F0=9F=8F=97=20=F0=9F=92=A9=20=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=BB=93=E6=9E=84=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=95=A5b=20BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/plugins/funny.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ATRI/plugins/funny.py (limited to 'ATRI/plugins/funny.py') diff --git a/ATRI/plugins/funny.py b/ATRI/plugins/funny.py new file mode 100644 index 0000000..9d31ef6 --- /dev/null +++ b/ATRI/plugins/funny.py @@ -0,0 +1,47 @@ +from pathlib import Path +from random import choice, randint + +from nonebot.adapters.cqhttp import Bot, MessageEvent +from nonebot.plugin import on_command, on_message + +from ATRI.rule import ( + is_in_banlist, + is_in_dormant, + is_in_service +) + + +__plugin_name__ = "laugh" + +get_laugh = on_command( + "来句笑话", + rule=is_in_banlist() & is_in_dormant() + & is_in_service(__plugin_name__) +) + +@get_laugh.handle() +async def _get_laugh(bot: Bot, event: MessageEvent) -> None: + user_name = event.sender.nickname + laugh_list = [] + + FILE = Path('.') / 'ATRI' / 'data' / 'database' / 'funny' / 'laugh.txt' + with open(FILE, 'r', encoding='utf-8') as r: + for line in r: + laugh_list.append(line.strip('\n')) + + result = choice(laugh_list) + await get_laugh.finish(result.replace("%name", user_name)) + + +__plugin_name__ = "wty" + +me_to_you = on_message( + rule=is_in_banlist() & is_in_dormant() & is_in_service(__plugin_name__) +) + +@me_to_you.handle() +async def _me_to_you(bot: Bot, event: MessageEvent) -> None: + rd = randint(0, 4) + if rd == 1: + msg = str(event.get_message()) + await me_to_you.finish(msg.replace('我', '你')) -- cgit v1.2.3