-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (31 loc) · 1.09 KB
/
main.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
from importlib import import_module
import hikari
import yaml
from models import Record, session_scope
with open('config.yaml') as cfile:
config = yaml.load(cfile, Loader=yaml.CLoader)
commands = {}
for command in config['commands']:
commands[command] = getattr(import_module(f'.{command}', package='commands'), command)
bot = hikari.GatewayBot(
token=config['BOT_TOKEN'],
intents=hikari.Intents.ALL
)
@bot.listen()
async def ping(event: hikari.GuildMessageCreateEvent) -> None:
if event.is_bot or not event.content:
return
if event.content.startswith(config['prefix']):
command, *args = event.content.strip(config['prefix']).split(" ")
if command in commands:
with session_scope() as s:
record = Record(
username=event.message.author.username,
command=command,
message=' '.join(args)
)
s.add(record)
s.commit()
await commands[command](event, command, config, *args)
if __name__ == "__main__":
bot.run()