-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
107 lines (78 loc) · 3.32 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
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
from datetime import datetime
import botpy
from botpy import logging
from botpy.message import DirectMessage, GroupMessage, C2CMessage, Message
from group_event.c2c_message_create import handle_c2c_message_create
from group_event.group_at_message_create import handle_group_at_message_create
from guild_event.guild_at_message_create import handle_guild_at_message_create
from guild_event.guild_c2c_message_create import handle_guild_c2c_message_create
from handle_at_message import HandleAtMessage
_log = logging.get_logger()
class AxTBot(botpy.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# 定义Bot版本
self.version = "1.2"
# 初始化计时器
self.start_time = datetime.now()
# 初始化消息计数器
self.group_message_number = 0
self.friend_message_number = 0
self.guild_group_message_number = 0
self.guild_friend_message_number = 0
self.handle_at_message = HandleAtMessage(self)
# 获取运行时间
def get_run_time(self):
current_time = datetime.now()
elapsed = current_time - self.start_time
seconds = elapsed.total_seconds()
days = int(seconds // 86400)
hours = int((seconds % 86400) // 3600)
minutes = int((seconds % 3600) // 60)
seconds = int(seconds % 60)
return f"{days}天 {hours}时 {minutes}分 {seconds}秒"
def get_version(self):
return self.version
def get_group_message_number(self):
return self.group_message_number
def get_friend_message_number(self):
return self.friend_message_number
def get_guild_group_message_number(self):
return self.guild_group_message_number
def get_guild_friend_message_number(self):
return self.guild_friend_message_number
# 公域 | 原生 | 群聊at消息
async def on_group_at_message_create(self, message: GroupMessage):
self.group_message_number += 1
await handle_group_at_message_create(self, message)
# await self.handle_at_message.send_message(message)
# 公域 | 原生 | 私聊消息
async def on_c2c_message_create(self, message: C2CMessage):
self.friend_message_number += 1
await handle_c2c_message_create(self, message)
# await self.handle_at_message.send_message(message)
# 公域 | 频道 | at消息
async def on_at_message_create(self, message: Message):
self.guild_group_message_number += 1
await handle_guild_at_message_create(self, message)
# await self.handle_at_message.send_message(message)
# 公域 | 频道 | 私聊消息
async def on_direct_message_create(self, message: DirectMessage):
self.guild_friend_message_number += 1
await handle_guild_c2c_message_create(self, message)
# await self.handle_at_message.send_message(message)
def run_client(appid, secret):
intents = botpy.Intents(
public_messages=True,
public_guild_messages=True,
direct_message=True,
guilds=True,
guild_message_reactions=True,
guild_messages=False,
guild_members=False,
interaction=False,
message_audit=True
)
AxTBot(intents=intents, is_sandbox=False).run(appid=appid, secret=secret)
if __name__ == '__main__':
run_client("APPID", "APPSECRET")