summaryrefslogtreecommitdiff
path: root/ATRI/plugins/funny
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2021-07-08 22:09:00 +0800
committerKyomotoi <[email protected]>2021-07-08 22:09:00 +0800
commitbe2747e4d4b820ca0f1f988d3b77a628da26fe7b (patch)
treee1a59dd79ecd973a7d704568dcdc018f1f1b651a /ATRI/plugins/funny
parenta4e1b9d1581d756ef79ad063d1c0bd6b2fd13c1d (diff)
downloadATRI-be2747e4d4b820ca0f1f988d3b77a628da26fe7b.tar.gz
ATRI-be2747e4d4b820ca0f1f988d3b77a628da26fe7b.tar.bz2
ATRI-be2747e4d4b820ca0f1f988d3b77a628da26fe7b.zip
🔖♻️🐛🔧🔥📝 更新版本:YHN-001-A03
🔖 更新版本至:YHN-001-A03 ✨ 新增插件: - 涩图 - 闲聊(文爱 ♻️ 重构: - Service - 所有插件 🐛 修复部分小bug 🔧 暂时移除部分设置 🔥 删除: - 插件:nsfw、wife。日后加回 - 插件 essential 中部分内容 📝 更新README
Diffstat (limited to 'ATRI/plugins/funny')
-rw-r--r--ATRI/plugins/funny/__init__.py86
-rw-r--r--ATRI/plugins/funny/data_source.py113
2 files changed, 199 insertions, 0 deletions
diff --git a/ATRI/plugins/funny/__init__.py b/ATRI/plugins/funny/__init__.py
new file mode 100644
index 0000000..de98381
--- /dev/null
+++ b/ATRI/plugins/funny/__init__.py
@@ -0,0 +1,86 @@
+from random import choice, randint
+
+from nonebot.typing import T_State
+from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
+from nonebot.adapters.cqhttp.message import Message
+
+from ATRI.utils.limit import FreqLimiter, DailyLimiter
+from.data_source import Funny
+
+
+get_laugh = Funny().on_command("来句笑话", "隐晦的笑话...")
+
+@get_laugh.handle()
+async def _get_laugh(bot: Bot, event: MessageEvent):
+ user_name = event.sender.nickname or "该裙友"
+ await get_laugh.finish(Funny().idk_laugh(user_name))
+
+
+me_re_you = Funny().on_regex(r"我", "我也不懂咋解释", block=False)
+
+@me_re_you.handle()
+async def _me_re_you(bot: Bot, event: MessageEvent):
+ if randint(0, 15) == 5:
+ msg = str(event.get_message())
+ content, is_ok = Funny().me_re_you(msg)
+ if is_ok:
+ await me_re_you.finish(content)
+
+
+fake_msg = Funny().on_command("/fakemsg", "伪造假转发内容,格式:qq-name-content\n可构造多条,使用空格隔开,仅限群聊")
+
+_fake_daliy_max = DailyLimiter(3)
+_fake_max_notice = "不能继续下去了!明早再来"
+_fake_flmt = FreqLimiter(60)
+_fake_flmt_notice = choice(["慢...慢一..点❤", "冷静1下", "歇会歇会~~"])
+
+@fake_msg.args_parser # type: ignore
+async def _perp_fake(bot: Bot, event: GroupMessageEvent, state: T_State):
+ msg = str(event.message).strip()
+ quit_list = ["算了", "罢了"]
+ if msg in quit_list:
+ await fake_msg.finish("好吧...")
+ if not msg:
+ await fake_msg.reject("内容呢?格式:qq-name-content\n可构造多条,以上仅为一条,使用空格隔开")
+ else:
+ state["content"] = msg
+
+@fake_msg.handle()
+async def _ready_fake(bot: Bot, event: GroupMessageEvent, state: T_State):
+ user_id = event.get_user_id()
+ if not _fake_daliy_max.check(user_id):
+ await fake_msg.finish(_fake_max_notice)
+ if not _fake_flmt.check(user_id):
+ await fake_msg.finish(_fake_flmt_notice)
+
+ msg = str(event.message).strip()
+ if msg:
+ state["content"] = msg
+
+@fake_msg.got("content", "内容呢?格式:qq-name-content\n可构造多条,以上仅为一条,使用空格隔开")
+async def _deal_fake(bot: Bot, event: GroupMessageEvent, state: T_State):
+ content = state["content"]
+ group_id = event.group_id
+ user_id = event.get_user_id()
+ node = Funny().fake_msg(content)
+ await bot.send_group_forward_msg(group_id=group_id, messages=node)
+
+ _fake_flmt.start_cd(user_id)
+ _fake_daliy_max.increase(user_id)
+
+
+eat_what = Funny().on_regex(r"大?[今明后]天(.*?)吃[什啥]么?", "我来决定你吃什么!")
+
+_eat_flmt = FreqLimiter(15)
+
+@eat_what.handle()
+async def _eat_what(bot: Bot, event: MessageEvent):
+ user_id = event.get_user_id()
+ if not _eat_flmt.check(user_id):
+ return
+
+ msg = str(event.get_message())
+ user_name = event.sender.nickname or "裙友"
+ eat = await Funny().eat_what(user_name, msg)
+ _eat_flmt.start_cd(user_id)
+ await eat_what.finish(Message(eat))
diff --git a/ATRI/plugins/funny/data_source.py b/ATRI/plugins/funny/data_source.py
new file mode 100644
index 0000000..a27cdb5
--- /dev/null
+++ b/ATRI/plugins/funny/data_source.py
@@ -0,0 +1,113 @@
+import re
+
+from pathlib import Path
+from random import choice, randint
+from nonebot.adapters.cqhttp.utils import unescape
+from nonebot.adapters.cqhttp.message import MessageSegment
+
+from ATRI.service import Service
+from ATRI.exceptions import RequestError
+from ATRI.utils import request, Translate
+from ATRI.rule import is_in_service
+
+
+__doc__ = """
+乐1乐,莫当真
+"""
+
+
+class Funny(Service):
+
+ def __init__(self):
+ Service.__init__(self, "乐", __doc__, rule=is_in_service("乐"))
+
+ @staticmethod
+ def idk_laugh(name: str) -> str:
+ laugh_list = list()
+
+ file_path = Path(".") / "ATRI" / "data" / "database" / "funny" / "laugh.txt"
+ with open(file_path, encoding="utf-8") as r:
+ for line in r:
+ laugh_list.append(line.strip("\n"))
+
+ rd: str = choice(laugh_list)
+ result = rd.replace("%name", name)
+ return result
+
+ @staticmethod
+ def me_re_you(msg: str) -> tuple:
+ if "我" in msg and "[CQ" not in msg:
+ return msg.replace("我", "你"), True
+ else:
+ return msg, False
+
+ @staticmethod
+ def fake_msg(text: str) -> list:
+ arg = text.split(" ")
+ node = list()
+
+ for i in arg:
+ args = i.split("-")
+ qq = args[0]
+ name = unescape(args[1])
+ repo = unescape(args[2])
+ dic = {"type": "node", "data": {"name": name, "uin": qq, "content": repo}}
+ node.append(dic)
+ return node
+
+ @staticmethod
+ async def eat_what(name: str, msg: str) -> str:
+ EAT_URL = "https://wtf.hiigara.net/api/run/"
+ params = {"event": "ManualRun"}
+ pattern_0 = r"大?[今明后]天(.*?)吃[什啥]么?"
+ pattern_1 = r"(今|明|后|大后)天"
+ arg = re.findall(pattern_0, msg)[0]
+ day = re.match(pattern_1, msg).group(0) # type: ignore
+
+ if arg == "中午":
+ a = f"LdS4K6/{randint(0, 1145141919810)}"
+ url = EAT_URL + a
+ try:
+ data = await request.post(url, params=params)
+ data = await data.json()
+ except RequestError:
+ raise RequestError("Request failed!")
+
+ text = Translate(data["text"]).to_simple().replace("今天", day)
+ get_a = re.search(r"非常(.*?)的", text).group(0) # type: ignore
+ result = text.replace(get_a, "")
+
+ elif arg == "晚上":
+ a = f"KaTMS/{randint(0, 1145141919810)}"
+ url = EAT_URL + a
+ try:
+ data = await request.post(url, params=params)
+ data = await data.json()
+ except RequestError:
+ raise RequestError("Request failed!")
+
+ result = Translate(data["text"]).to_simple().replace("今天", day)
+
+ else:
+ rd = randint(1, 10)
+ if rd == 5:
+ result = [
+ "吃我吧 ❤",
+ "(脸红)请...请享用咱吧......",
+ "都可以哦~不能挑食呢~"
+ ]
+ return choice(result)
+ else:
+ a = f"JJr1hJ/{randint(0, 1145141919810)}"
+ url = EAT_URL + a
+ try:
+ data = await request.post(url, params=params)
+ data = await data.json()
+ except RequestError:
+ raise RequestError("Request failed!")
+
+ text = Translate(data["text"]).to_simple().replace("今天", day)
+ get_a = re.match(r"(.*?)的智商", text).group(0) # type: ignore
+ result = text.replace(get_a, f"{name}的智商")
+
+ return result \ No newline at end of file