Skip to content

Commit 7ebe67b

Browse files
Merge pull request #276 from nullqwertyuiop/Ariadne
✨ Update
2 parents b07d1fe + 8714a32 commit 7ebe67b

File tree

5 files changed

+26536
-311
lines changed

5 files changed

+26536
-311
lines changed

sagiri_bot/handler/handlers/emoji_mix.py

-295
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from aiohttp import ClientSession
2+
from graia.ariadne import Ariadne
3+
from graia.ariadne.event.message import GroupMessage
4+
from graia.ariadne.message.chain import MessageChain
5+
from graia.ariadne.message.element import Image, Plain
6+
from graia.ariadne.message.parser.twilight import (
7+
Twilight,
8+
FullMatch,
9+
UnionMatch,
10+
RegexResult,
11+
)
12+
from graia.saya import Channel
13+
from graia.saya.builtins.broadcast import ListenerSchema
14+
15+
from sagiri_bot.control import (
16+
FrequencyLimit,
17+
Function,
18+
BlackListControl,
19+
UserCalledCountControl,
20+
)
21+
from sagiri_bot.core.app_core import AppCore
22+
from .util import ALL_EMOJI, get_mix_emoji_url
23+
24+
channel = Channel.current()
25+
26+
channel.name("EmojiMix")
27+
channel.author("nullqwertyuiop")
28+
channel.author("SAGIRI-kawaii")
29+
channel.author("from: MeetWq")
30+
channel.description("一个生成emoji融合图的插件,发送 '{emoji1}+{emoji2}' 即可")
31+
32+
core = AppCore.get_core_instance()
33+
config = core.get_config()
34+
proxy = config.proxy if config.proxy != "proxy" else ""
35+
36+
37+
@channel.use(
38+
ListenerSchema(
39+
listening_events=[GroupMessage],
40+
inline_dispatchers=[
41+
Twilight(
42+
[
43+
UnionMatch(*ALL_EMOJI) @ "emoji1",
44+
FullMatch("+"),
45+
UnionMatch(*ALL_EMOJI) @ "emoji2",
46+
]
47+
)
48+
],
49+
decorators=[
50+
FrequencyLimit.require("emoji_mix", 2),
51+
Function.require(channel.module, notice=True),
52+
BlackListControl.enable(),
53+
UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS),
54+
],
55+
)
56+
)
57+
async def emoji_mix(
58+
app: Ariadne, event: GroupMessage, emoji1: RegexResult, emoji2: RegexResult
59+
):
60+
emoji1: str = emoji1.result.asDisplay()
61+
emoji2: str = emoji2.result.asDisplay()
62+
try:
63+
async with ClientSession() as session:
64+
assert (link := get_mix_emoji_url(emoji1, emoji2)), "无法获取合成链接"
65+
async with session.get(link, proxy=proxy) as resp:
66+
assert resp.status == 200, "图片获取失败"
67+
image = await resp.read()
68+
return await app.sendGroupMessage(
69+
event.sender.group, MessageChain([Image(data_bytes=image)])
70+
)
71+
except AssertionError as err:
72+
err_text = err.args[0]
73+
except Exception as err:
74+
err_text = str(err)
75+
return await app.sendGroupMessage(
76+
event.sender.group, MessageChain([Plain(err_text)])
77+
)

0 commit comments

Comments
 (0)