-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
33 lines (29 loc) · 1.18 KB
/
bot.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
import datetime
import botpy
import yaml
from functions import on_startswith_options, on_fullmatch_options
from switch_case_decorator import SwitchCaseDecorator
from botpy.types.message import Message
from message import Event
from botpy import logger
class MyClient(botpy.Client):
async def on_at_message_create(self, message: Message):
talk = message.content
Event.message = message
# print(message)
Event.channel_id = message.channel_id
Event.user_id = message.author.id
Event.message_id = message.id
Event.client = self
talk = str(talk).replace(f'<@!{self.robot.id}> ', '').rstrip() # 去除@bot前缀
msg = f'[INFO] [{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}] {talk}'
print(msg)
decorator = SwitchCaseDecorator(on_startswith_options, on_fullmatch_options)
await decorator.match_sequence(talk)
with open('config.yml', 'r', encoding='utf-8') as yml:
yml = yaml.load(yml, yaml.FullLoader)['account']
appid = yml['app-id']
token = yml['token']
client = MyClient(intents=botpy.Intents.all())
client.run(appid=appid, token=token)
print(123)