-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_plugin.py
109 lines (75 loc) · 2.58 KB
/
example_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from arclet.entari import (
Session,
MessageChain,
MessageCreatedEvent,
Plugin,
command,
filter_,
metadata,
keeping,
scheduler,
local_data,
# Entari,
)
from arclet.entari.filter import Interval
metadata(__file__)
plug = Plugin.current()
@plug.use("::startup")
async def prepare():
print(">> example: Preparing")
@plug.use("::cleanup")
async def cleanup():
print(">> example: Cleanup")
@plug.dispatch(MessageCreatedEvent)
@filter_.public().bind
async def _(session: Session):
if session.content == "test":
resp = await session.send("This message will recall in 5s...")
@scheduler.invoke(5)
async def _():
await session.message_delete(resp[0].id)
disp_message = plug.dispatch(MessageCreatedEvent)
@disp_message.on(auxiliaries=[filter_.public().to_me().and_(lambda sess: str(sess.content) == "aaa")])
async def _(session: Session):
return await session.send("Filter: public message, to me, and content is 'aaa'")
@disp_message
@filter_.public().to_me().not_(lambda sess: str(sess.content) != "aaa")
async def _(session: Session):
return await session.send("Filter: public message, to me, but content is not 'aaa'")
@command.on("add {a} {b}", [Interval(2, limit_prompt="太快了")])
def add(a: int, b: int):
return f"{a + b =}"
kept_data = keeping("foo", [], lambda x: x.clear())
@command.on("append {data}")
def append(data: str):
kept_data.append(data)
return f"Appended {data}"
@command.on("show")
async def show(session: Session):
res = await command.execute("echo 123")
await session.send_message(f"Execute `echo 123` Result: {res}")
return f"Data: {kept_data}"
TEST = 6
print([*Plugin.current()._scope.subscribers])
print(Plugin.current().subplugins)
print(local_data.get_temp_dir())
print(plug.config)
@plug.use("::before_send")
async def send_hook(message: MessageChain):
return message + "喵"
@plug.use("::config/reload")
async def config_reload():
print(">> Config Reloaded")
return True
@plug.use("::plugin/loaded_success")
async def loaded_success(event):
print(f">> Plugin {event.name} Loaded Successfully")
@plug.use("::plugin/unloaded")
async def unloaded(event):
print(f">> Plugin {event.name} Unloaded")
# @scheduler.cron("* * * * *")
# async def broadcast(app: Entari):
# for account in app.accounts.values():
# channels = [channel for guild in (await account.guild_list()).data for channel in (await account.channel_list(guild.id)).data]
# for channel in channels:
# await account.send_message(channel, "Hello, World!")