-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcqhttp_api.py
More file actions
58 lines (47 loc) · 1.49 KB
/
cqhttp_api.py
File metadata and controls
58 lines (47 loc) · 1.49 KB
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
# CQHTTP API wrapper
from config import *
import aiohttp
import json
async def cqhttp_api(api: str, post_data: dict):
async with aiohttp.request(
method="POST", url=f"http://{GO_CQHTTP_HOST}:{GO_CQHTTP_PORT}/{api}",
data=post_data
) as response:
return await response.json()
async def send_group_msg(group_id, message: str):
return await cqhttp_api(
'send_msg',
{'message_type': 'group', 'group_id': group_id, 'message': message}
)
async def send_private_msg(user_id, message: str):
return await cqhttp_api(
'send_msg',
{'message_type': 'private', 'user_id': user_id, 'message': message}
)
async def send_group_forward_msg(group_id, messages: list[str], sender_name: str):
nodes = []
for message in messages:
nodes.append(
{
'type': 'node',
'data': {
'name': sender_name,
'uin': GO_CQHTTP_USER_ID,
'content': [
{
'type': 'text',
'data': {'text': message}
}
]
}
}
)
return await cqhttp_api(
'send_group_forward_msg',
{'message_type': 'group', 'group_id': group_id, 'messages': json.dumps(nodes)}
)
async def delete_msg(message_id):
return await cqhttp_api(
'delete_msg',
{'message_id': message_id}
)