-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain2cq_test.py
46 lines (34 loc) · 1007 Bytes
/
main2cq_test.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
# -*- coding: utf-8 -*-
import json
import logging
import aiohttp
from aiocqhttp import CQHttp
centerURL = 'http://inter1.com/center/msg'
# 初始化日志格式
logging.basicConfig(
level=logging.INFO,
format='[%(asctime)s][%(levelname)s]%(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
bot = CQHttp()
@bot.on_message()
async def handle_msg(event):
if event.get('message'):
event['message'] = convert(event['message'])
# 频道消息过滤
if event.get("channel_id"):
return
async with aiohttp.ClientSession() as session:
async with session.post(centerURL,
data={"context": json.dumps(event)}) as res:
rs = await res.text()
if rs:
await bot.send(event, rs)
return
def convert(msg):
tmps = msg.replace('&', '&')
tmps = tmps.replace('[', '[')
tmps = tmps.replace(']', ']')
tmps = tmps.replace(',', ',')
return tmps
bot.run(host='127.0.0.1', port=8089)