-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction_utils.py
53 lines (40 loc) · 1.45 KB
/
action_utils.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
import go_cqhttp_api
import settings
from ChatGPT_chat_demo import ChatGPT_use,QQ_box
from apikey import api_key
import threading
action_status = {}
Chatbot = ChatGPT_use(api_key=api_key)
CQ_at_me = f'[CQ:at,qq={settings.myqq}] '
def at_me(message):
if CQ_at_me in message:
return True
else:
return False
def send_gpt_response(user_id, msg):
# 获取chatgpt返回
response = QQ_box(Chatbot, msg)
# 发送给该用户
go_cqhttp_api.send_private_msg(user_id, response)
def action_follow_rec(data):
message_type = data.get('message_type', None)
if message_type == 'group':
sender_info = data.get('sender', None)
group_id = data.get('group_id', None)
message = data.get('message', None)
if at_me(message) and group_id in settings.group_list:
# 群里被@到的操作
# 获取chatgpt返回
response = ""
# 发送到该群
go_cqhttp_api.send_group_msg(group_id, response)
return
elif message_type == 'private':
if data["sender"]["user_id"] in settings.private_list:
user_id = data['sender']['user_id']
nickname = data['sender']['nickname']
msg = data['message']
# 发送给该用户,用线程做,避免go-cqhttp以为断连重复报告
t1 = threading.Thread(target=send_gpt_response, args=(user_id, msg))
t1.start()
return