commit
643983a290
12 changed files with 460 additions and 19 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
env
|
||||
__pycache__
|
||||
.vscode
|
||||
config.py
|
5
main.py
5
main.py
|
@ -9,6 +9,5 @@ def whenmsg():
|
|||
ZZRouter(request.get_json())
|
||||
return ''
|
||||
|
||||
app.run(host='0.0.0.0', port=PORT)
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
app.run(host='0.0.0.0',port = PORT, debug=True)
|
||||
|
||||
|
|
12
route.py
12
route.py
|
@ -1,22 +1,26 @@
|
|||
from worker import emmm
|
||||
|
||||
|
||||
def ZZRouter(data):
|
||||
uid = data['user_id']
|
||||
gid = data['group_id']
|
||||
role = data['sender']['role']
|
||||
parms = str.split(data['message'][1:])
|
||||
if not parms:
|
||||
print(uid, gid, role, parms)
|
||||
if parms == []:
|
||||
parms[0] = 'help'
|
||||
worker = parms[0]
|
||||
|
||||
try:
|
||||
package = __import__(name='worker.'+ worker, fromlist=worker)
|
||||
Ans_ = getattr(package,'Ans')
|
||||
package = __import__(name='worker.' + worker, fromlist=worker)
|
||||
Ans_ = getattr(package, 'Ans')
|
||||
except:
|
||||
Ans_ = emmm.Ans
|
||||
|
||||
Ans = Ans_(parms,uid,gid,role,data)
|
||||
Ans = Ans_(parms, uid, gid, role, data)
|
||||
Message = Ans.CheckPermission()
|
||||
if Message == 0:
|
||||
Message = Ans.GETMSG()
|
||||
elif Message == -1:
|
||||
return
|
||||
Ans.sendmsg(Message)
|
|
@ -5,3 +5,5 @@ APIURL = 'http://127.0.0.1:5700/'
|
|||
AUTHORIZATION = ''
|
||||
|
||||
PORT = 5580
|
||||
|
||||
|
|
@ -1,13 +1,17 @@
|
|||
import random
|
||||
from zzcore import StdAns
|
||||
from zzcore import StdAns, mysakuya
|
||||
|
||||
class Ans(StdAns):
|
||||
def GETMSG(self):
|
||||
if len(self.parms) < 2:
|
||||
return '不加参数是坏文明!'
|
||||
|
||||
if mysakuya(self,self.raw_msg['message']) == False:
|
||||
return "不许你们说咲夜!!"
|
||||
|
||||
r = random.randint(1,3)
|
||||
if r == 1:
|
||||
msg = self.raw_msg['message'][5:]
|
||||
msg = self.raw_msg['message'][6:]
|
||||
elif r == 2:
|
||||
msg = "汝以为咱会复读的嘛!\n(╯' - ')╯︵ ┻━┻\n" + self.raw_msg['message'][5:]
|
||||
elif r == 3:
|
||||
|
|
|
@ -1,8 +1,20 @@
|
|||
from zzcore import StdAns
|
||||
from zzcore import StdAns, mysakuya
|
||||
|
||||
|
||||
class Ans(StdAns):
|
||||
NotAllowGroup = [204097403]
|
||||
|
||||
def CheckPermission(self):
|
||||
if self.gid in self.NotAllowGroup:
|
||||
return -1
|
||||
return 0
|
||||
|
||||
def GETMSG(self):
|
||||
if self.parms:
|
||||
|
||||
if mysakuya(self, self.raw_msg['message']) == False:
|
||||
return "咲夜是最完美的!!"
|
||||
|
||||
return '咱也不知道' + self.parms[0] + '是啥呢~'
|
||||
else:
|
||||
return '汝再调戏咱,咱可就生气了!!'
|
53
worker/inx.py
Normal file
53
worker/inx.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
from zzcore import StdAns
|
||||
import requests, time
|
||||
|
||||
class Ans(StdAns):
|
||||
def GETMSG(self):
|
||||
if len(self.parms) < 2:
|
||||
return '不加参数是坏文明!'
|
||||
cmd = self.parms[1]
|
||||
AllowCmd = ['start','stop']
|
||||
|
||||
if cmd in AllowCmd:
|
||||
if cmd == 'stop':
|
||||
self.DATASET({'status':'0'})
|
||||
return '我已知晓你希望 inx 停止.'
|
||||
if cmd == 'start':
|
||||
self.DATASET({'status':'1'})
|
||||
self.sendmsg('inx 启动!')
|
||||
pinx = 0
|
||||
pixic = 0
|
||||
pdji = 0
|
||||
while(self.DATAGET()['status'] == '1'):
|
||||
inx, ixic, dji = getMG()
|
||||
msg = '标普 500 : ' + inx + ' ' + emoji(pinx,inx) + '纳斯达克 : ' + ixic + ' ' + emoji(pixic,ixic) + '道琼斯 : ' + dji + ' ' + emoji(pdji,dji)
|
||||
self.sendmsg(msg)
|
||||
# print(msg)
|
||||
pinx = inx
|
||||
pixic = ixic
|
||||
pdji = dji
|
||||
time.sleep(16)
|
||||
|
||||
return "现在 inx 真的停了!"
|
||||
|
||||
else:
|
||||
return '汝是不是在inx后面添加了奇怪的参数,咱可只知道 start 和 stop。'
|
||||
|
||||
|
||||
def getMG():
|
||||
req = requests.get("https://hq.sinajs.cn/etag.php?_=1584712625172&list=gb_$inx,gb_$ixic,gb_$dji").text.split(';')
|
||||
inx = req[0].split(',')[2]
|
||||
ixic = req[1].split(',')[2]
|
||||
dji = req[2].split(',')[2]
|
||||
return inx, ixic, dji
|
||||
|
||||
def emoji(p,n):
|
||||
n = float(n)
|
||||
p = float(p)
|
||||
if n < p:
|
||||
emoji = '📉📉📉🎉\n'
|
||||
elif n > p:
|
||||
emoji = '📈📈📈😢\n'
|
||||
else :
|
||||
emoji = '⬜⬜⬜🌚\n'
|
||||
return emoji
|
|
@ -3,7 +3,7 @@ import re
|
|||
from subprocess import getoutput,call
|
||||
|
||||
class Ans(StdAns):
|
||||
AllowGroup = [959613860]
|
||||
AllowGroup = [959613860, 125733077, 204097403, 1140391080]
|
||||
def GETMSG(self):
|
||||
if len(self.parms) < 2:
|
||||
return '不加参数是坏文明!'
|
||||
|
|
|
@ -6,13 +6,16 @@ class Ans(StdAns):
|
|||
if len(self.parms) < 2:
|
||||
return '不加参数是坏文明!'
|
||||
|
||||
url = 'http://47.100.45.234/search'
|
||||
# url = 'https://api.imjad.cn/cloudmusic/'
|
||||
# url = 'https://music.jeeas.cn/v1/search'
|
||||
url = 'http://mc.sakuya.love:3000/search'
|
||||
params = {
|
||||
'keywords':self.raw_msg['message'][6:],
|
||||
'limit': 1,
|
||||
'keywords':self.raw_msg['message'][6:],
|
||||
}
|
||||
try:
|
||||
resp = requests.get(url=url,params=params).json()
|
||||
# print(resp)
|
||||
musicid = resp['result']['songs'][0]['id']
|
||||
msg = '[CQ:music,type=163,id='+ str(musicid)+']'
|
||||
except Exception as e:
|
||||
|
|
289
worker/pcr.py
Normal file
289
worker/pcr.py
Normal file
|
@ -0,0 +1,289 @@
|
|||
import json
|
||||
from zzcore import StdAns
|
||||
|
||||
AllowCMD = ['登记','申请出刀','报刀','挂树','查树','进度','查刀','新的一天','血量','boss','初始化','求助','迁移','踢人']
|
||||
|
||||
status = {
|
||||
'all_player':{
|
||||
'1318000868': {
|
||||
'id':'十六夜咲夜',
|
||||
'余刀': 3,
|
||||
'加时刀': 0,
|
||||
# 'SL':1
|
||||
},
|
||||
},
|
||||
'boss_num': 0,
|
||||
'boss_hp': 0,
|
||||
'dao':{
|
||||
'qq':1318000868,
|
||||
'类型':'普通刀',
|
||||
},
|
||||
'tree':[]
|
||||
}
|
||||
|
||||
class Ans(StdAns):
|
||||
AllowGroup = [125733077,1084566280,920863253]
|
||||
|
||||
def GETMSG(self):
|
||||
if len(self.parms) < 2:
|
||||
return '不加参数是坏文明!'
|
||||
|
||||
cmd = self.parms[1]
|
||||
if cmd not in AllowCMD:
|
||||
return '没有 ' + cmd + ' 这个命令,请检查。'
|
||||
|
||||
if cmd == '迁移':
|
||||
if self.uid != 1318000868:
|
||||
return '迁移数据请联系SiHuan'
|
||||
try:
|
||||
nowdata = json.loads(self.DATAGET()[self.parms[2]])
|
||||
except:
|
||||
return '获取原始数据出错!'
|
||||
self.DATASET({self.parms[3]:json.dumps(nowdata)})
|
||||
return '数据迁移完成! ' + self.parms[2] + '现在迁移到' + self.parms[3]
|
||||
|
||||
gid = str(self.gid)
|
||||
|
||||
try:
|
||||
nowdata = json.loads(self.DATAGET()[gid])
|
||||
except:
|
||||
if cmd == '初始化':
|
||||
nowdata = {}
|
||||
else:
|
||||
return '请管理员先初始化,初始化会将进度设置为第一周目第一个Boss,成员数据不会丢失。'
|
||||
|
||||
|
||||
if cmd == '初始化':
|
||||
if self.role not in ['owner','admin'] and self.uid != 1318000868:
|
||||
return '你没有权限执行初始化。'
|
||||
else:
|
||||
try:
|
||||
all_player = nowdata['all_player']
|
||||
except:
|
||||
all_player = {}
|
||||
|
||||
nowdata = {}
|
||||
nowdata['all_player'] = all_player
|
||||
nowdata['boss_num'] = 1
|
||||
nowdata['boss_hp'] = -1
|
||||
nowdata['dao'] = {
|
||||
'qq':0,
|
||||
'类型':'普通刀',
|
||||
}
|
||||
nowdata['tree'] = []
|
||||
self.DATASET({gid:json.dumps(nowdata)})
|
||||
return '初始化完成!请使用\n /pcr 血量 xxxx \n 来设置第一周目第一个Boss的总血量。'
|
||||
|
||||
if cmd == '登记':
|
||||
nickname = self.raw_msg['message'][8:]
|
||||
if nickname:
|
||||
player = {
|
||||
'id':nickname,
|
||||
'余刀': 3,
|
||||
'加时刀': 0,
|
||||
# 'SL':1
|
||||
}
|
||||
|
||||
nowdata['all_player'][str(self.uid)] = player
|
||||
self.DATASET({gid:json.dumps(nowdata)})
|
||||
|
||||
return '[CQ:at,qq=' + str(self.uid) + ']' + '游戏id设置为 ' + nickname
|
||||
|
||||
else:
|
||||
return '登记失败,请使用合法的游戏id。'
|
||||
|
||||
if cmd == '踢人':
|
||||
if self.role not in ['owner','admin'] and self.uid != 1318000868:
|
||||
return '你没有权限踢人。'
|
||||
else:
|
||||
tiqq = self.parms[2]
|
||||
try:
|
||||
nowplayer = nowdata['all_player'][tiqq]
|
||||
except:
|
||||
return '此人未登记!!!。'
|
||||
|
||||
if tiqq in nowdata['tree']:
|
||||
nowdata['tree'].remove(tiqq)
|
||||
if str(nowdata['dao']['qq']) == tiqq:
|
||||
nowdata['dao']['qq'] = 0
|
||||
|
||||
del nowdata['all_player'][tiqq]
|
||||
self.DATASET({gid: json.dumps(nowdata)})
|
||||
return nowplayer['id'] + '已被踢除。'
|
||||
|
||||
if cmd == '血量':
|
||||
if self.role not in ['owner','admin'] and self.uid != 1318000868:
|
||||
return '你没有权限设置血量。'
|
||||
else:
|
||||
try:
|
||||
hp = int(self.parms[2])
|
||||
except:
|
||||
return '血量应该是整数!'
|
||||
|
||||
nowdata['boss_hp'] = hp
|
||||
self.DATASET({gid:json.dumps(nowdata)})
|
||||
return '现在' + bossname(int(nowdata['boss_num'])) +'的血量被设置为' + str(hp)
|
||||
|
||||
if cmd == 'boss':
|
||||
if self.role not in ['owner','admin'] and self.uid != 1318000868:
|
||||
return '你没有权限设置boss。'
|
||||
else:
|
||||
try:
|
||||
boss = int(self.parms[2])
|
||||
except:
|
||||
return 'boss序号应该是整数!'
|
||||
|
||||
nowdata['boss_num'] = boss
|
||||
self.DATASET({gid:json.dumps(nowdata)})
|
||||
return '现在boss被设置为' + bossname(int(nowdata['boss_num']))
|
||||
|
||||
if cmd == '新的一天':
|
||||
if self.role not in ['owner','admin'] and self.uid != 1318000868:
|
||||
return '你没有权限新的一天。'
|
||||
else:
|
||||
for value in nowdata['all_player'].values():
|
||||
value['余刀'] = 3
|
||||
value['加时刀'] = 0
|
||||
# value['SL'] == 1
|
||||
nowdata['tree'] = []
|
||||
self.DATASET({gid:json.dumps(nowdata)})
|
||||
return '新的一天已经开始,大家各有3刀剩余了。'
|
||||
|
||||
|
||||
if cmd == '进度':
|
||||
return bossname(int(nowdata['boss_num'])) + '\n剩余血量:' + str(nowdata['boss_hp'])
|
||||
|
||||
if cmd == '申请出刀':
|
||||
try:
|
||||
nowplayer = nowdata['all_player'][str(self.uid)]
|
||||
except:
|
||||
return '您未登记。'
|
||||
|
||||
if self.uid in nowdata['tree']:
|
||||
return '您在树上了。'
|
||||
|
||||
daoqq = nowdata['dao']['qq']
|
||||
if daoqq != 0 and daoqq not in nowdata['tree']:
|
||||
return nowdata['all_player'][str(daoqq)]['id'] + '正在出刀,请等待他结算或挂树.'
|
||||
elif nowplayer['余刀'] + nowplayer['加时刀'] < 1:
|
||||
return '您已无刀可出。'
|
||||
else:
|
||||
nowdata['dao']['qq'] = self.uid
|
||||
if nowplayer['加时刀'] > 0:
|
||||
nowdata['dao']['类型'] = '加时刀'
|
||||
else:
|
||||
nowdata['dao']['类型'] = '普通刀'
|
||||
|
||||
self.DATASET({gid:json.dumps(nowdata)})
|
||||
return nowplayer['id'] + '出' + nowdata['dao']['类型'] + '讨伐' + bossname(int(nowdata['boss_num'])) + '\n剩余血量:' + str(nowdata['boss_hp'])
|
||||
|
||||
|
||||
if cmd == '报刀':
|
||||
try:
|
||||
nowplayer = nowdata['all_player'][str(self.uid)]
|
||||
except:
|
||||
return '您未登记。'
|
||||
if nowdata['dao']['qq'] != self.uid and self.uid not in nowdata['tree']:
|
||||
return '您未出刀,报个毛刀'
|
||||
try:
|
||||
jianhp = int(self.parms[2])
|
||||
except:
|
||||
return '打掉的血量应该是整数!'
|
||||
|
||||
newhp = nowdata['boss_hp'] - jianhp
|
||||
# BOSS 没死
|
||||
if newhp > 0:
|
||||
nowdata['boss_hp'] = newhp
|
||||
nowdata['dao']['qq'] = 0
|
||||
if nowdata['dao']['类型'] == '加时刀':
|
||||
nowplayer['加时刀'] = 0
|
||||
else:
|
||||
nowplayer['余刀'] = nowplayer['余刀'] - 1
|
||||
|
||||
nowdata['all_player'][str(self.uid)] = nowplayer
|
||||
if self.uid in nowdata['tree']:
|
||||
nowdata['tree'].remove(self.uid)
|
||||
self.DATASET({gid:json.dumps(nowdata)})
|
||||
|
||||
msg = nowplayer['id'] + '打了' + bossname(int(nowdata['boss_num'])) + str(jianhp) + '\n剩余血量:' + str(nowdata['boss_hp'])
|
||||
if self.uid in nowdata['tree']:
|
||||
msg = msg + '\n' + nowplayer['id'] + '自行下树'
|
||||
return msg
|
||||
#BOSS 死了
|
||||
else:
|
||||
nowdata['boss_hp'] = 0
|
||||
nowdata['boss_num'] = nowdata['boss_num'] + 1
|
||||
nowdata['dao']['qq'] = 0
|
||||
nowdata['tree'] = []
|
||||
if nowdata['dao']['类型'] == '加时刀':
|
||||
nowplayer['加时刀'] = 0
|
||||
else:
|
||||
nowplayer['余刀'] = nowplayer['余刀'] - 1
|
||||
nowplayer['加时刀'] = 1
|
||||
|
||||
nowdata['all_player'][str(self.uid)] = nowplayer
|
||||
if self.uid in nowdata['tree']:
|
||||
nowdata['tree'].remove(self.uid)
|
||||
self.DATASET({gid:json.dumps(nowdata)})
|
||||
|
||||
return nowplayer['id'] + '击杀了' + bossname(int(nowdata['boss_num'])-1) + '\n现在进入' + bossname(int(nowdata['boss_num'])) + '\n挂树的同学已经全部下树\n请使用\n /pcr 血量 xxxx \n 来设置新Boss的总血量'
|
||||
|
||||
|
||||
if cmd == '挂树':
|
||||
try:
|
||||
nowplayer = nowdata['all_player'][str(self.uid)]
|
||||
except:
|
||||
return '您未登记。'
|
||||
|
||||
if self.uid in nowdata['tree']:
|
||||
return '您已经在树上了。'
|
||||
|
||||
# elif nowplayer['SL'] == 1:
|
||||
elif nowdata['dao']['qq'] != self.uid:
|
||||
return '您未出刀,挂个毛树'
|
||||
else:
|
||||
nowdata['dao']['qq'] = 0
|
||||
# print(nowdata['tree'])
|
||||
# print(type(nowdata['tree']))
|
||||
nowdata['tree'].append(self.uid)
|
||||
# print(nowdata['tree'])
|
||||
# print(type(nowdata['tree']))
|
||||
self.DATASET({gid:json.dumps(nowdata)})
|
||||
return '已挂树'
|
||||
|
||||
if cmd == '查树':
|
||||
on_tree_players = ''
|
||||
for p in nowdata['tree']:
|
||||
on_tree_players = on_tree_players + nowdata['all_player'][str(p)]['id'] + '\n'
|
||||
return '树上的有\n' + on_tree_players
|
||||
|
||||
if cmd == '查刀':
|
||||
alldao = ''
|
||||
index = 1
|
||||
for key, value in nowdata['all_player'].items():
|
||||
alldao = alldao + str(index) + '. ' + value['id'] + ' ' + '🔪'*value['余刀'] + '🍴'*value['加时刀']
|
||||
if int(key) in nowdata['tree']:
|
||||
alldao = alldao + ' 在🌳上\n'
|
||||
else:
|
||||
alldao = alldao + '\n'
|
||||
index = index + 1
|
||||
return alldao
|
||||
|
||||
if cmd == '求助':
|
||||
on_tree_players = ''
|
||||
for p in nowdata['tree']:
|
||||
on_tree_players = on_tree_players + nowdata['all_player'][str(p)]['id'] + '\n'
|
||||
return '救命[CQ:at,qq=3178302597][CQ:at,qq=3430357110]\n' + on_tree_players + '都在🌳上'
|
||||
|
||||
|
||||
|
||||
def bossname(num):
|
||||
zm = int(num/5)+1
|
||||
z = num%5
|
||||
|
||||
if z == 0:
|
||||
z = 5
|
||||
zm = zm - 1
|
||||
|
||||
return '第'+ str(zm) + '周目第' + str(z) + 'Boss'
|
||||
|
40
worker/pixiv.py
Normal file
40
worker/pixiv.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
from zzcore import StdAns, mysakuya
|
||||
import requests
|
||||
|
||||
from config import LOLIKEY
|
||||
|
||||
class Ans(StdAns):
|
||||
AllowGroup = [973510746, 805197917,343700338,125733077,1084566280,920863253,798595664,655057127,196268763, 204097403, 247022495, 474907856]
|
||||
def GETMSG(self):
|
||||
url = 'https://api.lolicon.app/setu/'
|
||||
params = {
|
||||
'apikey': LOLIKEY,
|
||||
}
|
||||
|
||||
if len(self.parms) < 2:
|
||||
try:
|
||||
resp = requests.get(url=url,params=params).json()
|
||||
picurl = resp['data'][0]['url']
|
||||
msg = picurl
|
||||
except Exception as e:
|
||||
print(e)
|
||||
msg = '什么东西坏掉了,大概是Pixiv吧...不可能是咱!'
|
||||
return msg
|
||||
|
||||
else:
|
||||
keyword = self.raw_msg['message'][7:]
|
||||
|
||||
if mysakuya(self, keyword) == False:
|
||||
return "不许你们看咲夜的涩图!!"
|
||||
|
||||
params['keyword'] = keyword
|
||||
try:
|
||||
resp = requests.get(url=url,params=params).json()
|
||||
picurl = resp['data'][0]['url']
|
||||
msg = '[CQ:at,qq=' + str(self.uid) + ']' + '咱帮你🔍 ' + keyword + ' 找到了这个\n' + picurl
|
||||
# .replace('https://i.pixiv.cat', 'https://pximg.sihuan.workers.dev')
|
||||
# msg = picurl.replace('https://i.pixiv.cat', 'https://original.img.cheerfun.dev')
|
||||
except Exception as e:
|
||||
print(e)
|
||||
msg = '[CQ:at,qq=' + str(self.uid) + ']咱没查到 ' + keyword + ' 也有可能是Pixiv坏掉了'
|
||||
return msg
|
35
zzcore.py
35
zzcore.py
|
@ -1,7 +1,8 @@
|
|||
import requests
|
||||
import json
|
||||
import requests, json, redis
|
||||
from config import APIURL, ALLWORKERS, AUTHORIZATION
|
||||
from worker import emmm
|
||||
pool = redis.ConnectionPool(host='127.0.0.1', port=6379, decode_responses=True)
|
||||
r = redis.Redis(connection_pool=pool)
|
||||
|
||||
class StdAns():
|
||||
AllowGroup = []
|
||||
|
@ -18,6 +19,11 @@ class StdAns():
|
|||
self.role = role
|
||||
self.raw_msg = raw_msg
|
||||
|
||||
def DATAGET(self):
|
||||
return r.hgetall(self.parms[0])
|
||||
|
||||
def DATASET(self,data):
|
||||
r.hmset(self.parms[0],data)
|
||||
|
||||
def CheckPermission(self):
|
||||
if self.AllowGroup and self.gid not in self.AllowGroup:
|
||||
|
@ -43,4 +49,29 @@ class StdAns():
|
|||
'group_id' : self.gid,
|
||||
'message': msg
|
||||
}
|
||||
return requests.post(url = url, data = json.dumps(data),headers = Headers).json()['data']['message_id']
|
||||
|
||||
|
||||
def delmsg(self,msgid):
|
||||
url = APIURL + "delete_msg"
|
||||
Headers = {
|
||||
'content-type': 'application/json',
|
||||
'Authorization':'Bearer ' + AUTHORIZATION
|
||||
}
|
||||
data = {
|
||||
'message_id' : msgid,
|
||||
}
|
||||
requests.post(url = url, data = json.dumps(data),headers = Headers)
|
||||
|
||||
|
||||
def mysakuya(self, words):
|
||||
if self.uid == 1318000868:
|
||||
return True
|
||||
|
||||
if ('咲' in words and '夜' in words) or ('关' in words and '夜' in words) or ('十' in words and '六' in words and '夜' in words) or ('1' in words and '6' in words and '夜' in words):
|
||||
return False
|
||||
for sakuya in ['口关夜','十六夜咲夜','十六夜','十六','咲夜','Sakuya','sakuya','Izayoi Sakuya','Izayoi','izayoi','izayoi sakuya']:
|
||||
if sakuya in words:
|
||||
return False
|
||||
|
||||
return True
|
Loading…
Reference in a new issue