-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.py
65 lines (54 loc) · 2.35 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
"""
:Author: NekoRabi
:Update Time: 2022/9/18 2:57
:Describe: Bot入口函数
:Version: v0.6.5
"""
import nest_asyncio
from mirai import MessageEvent
from mirai.models import FlashImage, Source
from core import *
from plugin import *
from utils import *
from utils.bufferpool import cmdbuffer
nest_asyncio.apply()
if __name__ == '__main__':
config = load_config()
if config.get('setting', {}).get('general_help', True):
create_helpimg()
settings = config['settings']
botname = config['botconfig']['botname']
print(f"机器人{botname}启动中\tQQ : {bot.qq}")
# 聊天记录存储
@bot.on(MessageEvent)
def add_event_log(event: MessageEvent):
if isinstance(event, GroupMessage):
# infodict = dict(type=event.type,senderid=event.sender.id,sendername=event.sender.get_name(),
# groupname=event.group.name,groupid=event.group.id,message=event.message_chain)
# qqlogger.info(infodict)
msgchain = []
for item in event.message_chain:
if type(item) != Source:
msgchain.append(item)
_info = {'groupid': event.group.id, 'groupname': event.group.name, 'membername': event.sender.member_name,
'message': msgchain}
root_logger.info(_info)
elif isinstance(event, FriendMessage):
msgchain = []
for item in event.message_chain:
if type(item) != Source:
msgchain.append(item)
_info = {'friendid': event.sender.id, 'friendname': event.sender.nickname, 'message': msgchain}
root_logger.info(_info)
# @bot.on(MessageEvent)
# async def save_flashimage(event: MessageEvent):
# if type(event) in [GroupMessage, FriendMessage]:
# if FlashImage in event.message_chain and settings['saveflashimg']:
# flashimg = event.message_chain.get_first(FlashImage)
# try:
# await flashimg.download(directory='./data/flashimages')
# except Exception as _e:
# print(f'闪照保存发生错误: {_e}')
scheduler.add_job(cmdbuffer.clearcache, 'cron', hour='0')
scheduler.add_job(cleaner.do_clean, 'cron', hour='0')
bot.run(port=config.get("runport", 17580))