summaryrefslogtreecommitdiff
path: root/ATRI/plugins/funny
diff options
context:
space:
mode:
authorLint Action <[email protected]>2021-07-31 08:17:46 +0000
committerLint Action <[email protected]>2021-07-31 08:17:46 +0000
commit36d26d1dc61c36b4601aaf75e148060c5bcb98a7 (patch)
tree3b466c4b0db4b9e160c5390a1d1c7ddb0322660f /ATRI/plugins/funny
parent336eb9d9e98b0bee952c27a50820dbdb350bcc03 (diff)
downloadATRI-36d26d1dc61c36b4601aaf75e148060c5bcb98a7.tar.gz
ATRI-36d26d1dc61c36b4601aaf75e148060c5bcb98a7.tar.bz2
ATRI-36d26d1dc61c36b4601aaf75e148060c5bcb98a7.zip
:rotating_light: 自动进行代码格式化
Diffstat (limited to 'ATRI/plugins/funny')
-rw-r--r--ATRI/plugins/funny/__init__.py16
-rw-r--r--ATRI/plugins/funny/data_source.py41
2 files changed, 31 insertions, 26 deletions
diff --git a/ATRI/plugins/funny/__init__.py b/ATRI/plugins/funny/__init__.py
index 4779dda..ea60375 100644
--- a/ATRI/plugins/funny/__init__.py
+++ b/ATRI/plugins/funny/__init__.py
@@ -10,6 +10,7 @@ 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 "该裙友"
@@ -18,6 +19,7 @@ async def _get_laugh(bot: Bot, event: MessageEvent):
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:
@@ -27,13 +29,16 @@ async def _me_re_you(bot: Bot, event: MessageEvent):
await me_re_you.finish(content)
-fake_msg = Funny().on_command("/fakemsg", "伪造假转发内容,格式:qq-name-content\n可构造多条,使用空格隔开,仅限群聊")
+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()
@@ -45,6 +50,7 @@ async def _perp_fake(bot: Bot, event: GroupMessageEvent, state: T_State):
else:
state["content"] = msg
+
@fake_msg.handle()
async def _ready_fake(bot: Bot, event: GroupMessageEvent, state: T_State):
user_id = event.get_user_id()
@@ -52,11 +58,12 @@ async def _ready_fake(bot: Bot, event: GroupMessageEvent, state: T_State):
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"]
@@ -64,7 +71,7 @@ async def _deal_fake(bot: Bot, event: GroupMessageEvent, state: T_State):
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)
@@ -73,12 +80,13 @@ 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)
diff --git a/ATRI/plugins/funny/data_source.py b/ATRI/plugins/funny/data_source.py
index f29b0be..89b1392 100644
--- a/ATRI/plugins/funny/data_source.py
+++ b/ATRI/plugins/funny/data_source.py
@@ -23,45 +23,46 @@ __doc__ = """
class Funny(Service):
-
def __init__(self):
Service.__init__(self, "乐", __doc__, rule=is_in_service("乐"))
-
+
@staticmethod
async def idk_laugh(name: str) -> str:
laugh_list = list()
-
+
file_name = "laugh.txt"
path = FUNNY_DIR / file_name
if not path.is_file():
logger.warning("未发现笑话相关数据,正在下载并保存...")
- url = "https://cdn.jsdelivr.net/gh/Kyomotoi/CDN@master/project/ATRI/laugh.txt"
+ url = (
+ "https://cdn.jsdelivr.net/gh/Kyomotoi/CDN@master/project/ATRI/laugh.txt"
+ )
res = await request.get(url)
context = await res.text() # type: ignore
with open(path, "w", encoding="utf-8") as w:
w.write(context)
logger.warning("完成")
-
+
with open(path, "r", 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]
@@ -70,7 +71,7 @@ class Funny(Service):
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/"
@@ -79,7 +80,7 @@ class Funny(Service):
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
@@ -88,11 +89,11 @@ class Funny(Service):
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
@@ -101,17 +102,13 @@ class Funny(Service):
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 = [
- "吃我吧 ❤",
- "(脸红)请...请享用咱吧......",
- "都可以哦~不能挑食呢~"
- ]
+ result = ["吃我吧 ❤", "(脸红)请...请享用咱吧......", "都可以哦~不能挑食呢~"]
return choice(result)
else:
a = f"JJr1hJ/{randint(0, 1145141919810)}"
@@ -121,9 +118,9 @@ class Funny(Service):
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