-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_plugin_afk.py
44 lines (37 loc) · 1.5 KB
/
example_plugin_afk.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
import hvicorn
from typing import Dict, Optional
afked_users: Dict[str, Optional[str]] = {}
def plugin_init(
bot: hvicorn.Bot,
command_prefix: str = "/afk",
on_afk: str = "You are marked AfK.",
afk_tip: str = "{nick} is now AfK.",
already_afk: str = "You are already AfKed.",
reason: str = "Reason: {reason}",
welcome_back: str = "Welcome back.",
):
def mark_afk(ctx: hvicorn.CommandContext):
reason = ctx.args if ctx.args else None
if ctx.sender.nick in afked_users.keys():
return ctx.respond(already_afk)
afked_users.update({ctx.sender.nick: reason})
return ctx.respond(on_afk)
def back_check(event):
if "nick" not in dir(event):
return
if "text" in dir(event) and event.text.startswith(command_prefix):
return
if event.nick in afked_users.keys():
del afked_users[event.nick]
return bot.send_message(f"@{event.nick} {welcome_back}")
def on_chat(event: hvicorn.ChatPackage):
for user in afked_users.items():
if f"@{user[0]}" in event.text:
bot.send_message(
f"@{event.nick} {afk_tip.format(nick=user[0])}"
+ (" " + reason.format(reason=user[1]) if user[1] else "")
)
return # only processes the first
bot.register_command(command_prefix, mark_afk)
bot.register_global_function(back_check)
bot.register_event_function(hvicorn.ChatPackage, on_chat)