XZZ/route.py

49 lines
1.4 KiB
Python
Raw Normal View History

2020-02-27 21:47:36 +08:00
from worker import emmm
2020-08-03 22:10:17 +08:00
from zzcore import DM
2020-08-03 23:17:56 +08:00
from config import DAAPI
2020-02-27 21:47:36 +08:00
2020-08-03 23:20:13 +08:00
import requests
2020-06-18 19:25:32 +08:00
2020-02-27 21:47:36 +08:00
def ZZRouter(data):
2020-08-03 22:10:17 +08:00
2020-08-03 12:04:06 +08:00
if data['post_type'] != 'message' or data['message_type'] != 'group' or data['message'][0] != '/':
2020-08-03 23:20:13 +08:00
if data['user_id'] == 1318000868 :
return
2020-08-03 23:17:56 +08:00
if len(data['raw_message']) == 54 and data['raw_message'][:15] == '[CQ:image,file=': # use re
url = data['message'][58:][:-1]
r = requests.post(
"https://api.deepai.org/api/image-similarity",
data={
'image1': 'https://img.vim-cn.com/fa/4a7f3996e3601e98bd3c1b245fcb88e05f32ec.jpg',
'image2': url,
},
headers={'api-key': DAAPI}
)
if r.json()['output']['distance'] < 10:
DM(data['message_id'])
2020-08-02 23:13:31 +08:00
return
2020-08-03 12:04:06 +08:00
2020-02-27 21:47:36 +08:00
uid = data['user_id']
gid = data['group_id']
role = data['sender']['role']
parms = str.split(data['message'][1:])
2020-06-18 19:25:32 +08:00
print(uid, gid, role, parms)
2020-03-16 17:18:32 +08:00
if parms == []:
2020-03-02 14:17:30 +08:00
parms[0] = 'help'
2020-02-27 21:47:36 +08:00
worker = parms[0]
try:
2020-06-18 19:25:32 +08:00
package = __import__(name='worker.' + worker, fromlist=worker)
Ans_ = getattr(package, 'Ans')
2020-02-27 21:47:36 +08:00
except:
Ans_ = emmm.Ans
2020-06-18 19:25:32 +08:00
Ans = Ans_(parms, uid, gid, role, data)
2020-02-27 21:47:36 +08:00
Message = Ans.CheckPermission()
if Message == 0:
Message = Ans.GETMSG()
2020-06-18 19:25:32 +08:00
elif Message == -1:
2020-06-18 19:35:09 +08:00
return
Ans.sendmsg(Message)