-
Notifications
You must be signed in to change notification settings - Fork 0
/
mirai_main.py
43 lines (36 loc) · 1.68 KB
/
mirai_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
import mirai
import random
from mirai.api import MiraiApi
from mirai.application import MiraiApp
from mirai.message.chain import MessageChain
from mirai.message.element import Plain, Source
from mirai.event import GroupMessageEvent, FriendMessageEvent, BotUnmuteEvent
import requests
import time
def onGroupMessage(app: MiraiApp, event: GroupMessageEvent):
words = ['是的呢', '对', '对的', '说得好',
'是这样的', 'TQL', '没错', '嗯', '的确', '确实']
# ret = requests.get('https://chp.shadiao.app/api.php')
message = MessageChain.create([Plain(random.choice(words))])
if event.sender.group.id == 667481568:
app.sendGroupMessage(target=event.sender.group.id, message=message)
def onFriendMessage(app: MiraiApp, event: FriendMessageEvent):
words = ['是的呢', '对', '对的', '说得好',
'是这样的', 'TQL', '没错', '嗯', '的确', '确实']
message = MessageChain.create([Plain(random.choice(words))])
sender_id = event.sender.id
app.sendFriendMessage(target=sender_id, message=message)
def onBotUnmute(app: MiraiApp, event: BotUnmuteEvent):
message = MessageChain.create([Plain('嘻嘻我被放出来了')])
group_id = event.operator.group.id
app.sendGroupMessage(target=group_id, message=message)
def run_bot(host:str, authKey:str, account:str):
with MiraiApp(host, authKey, account) as app:
# 显示所有好友
for f in app.friendList():
print(f.nickname)
# 事件响应注册
app.register('GroupMessage', onGroupMessage)
app.register('FriendMessage', onFriendMessage)
app.register(BotUnmuteEvent, onBotUnmute)
app.blocking_start()