commit
9a94c542b9
22 changed files with 195 additions and 32 deletions
|
@ -2,7 +2,14 @@
|
|||
"anonymous": "None",
|
||||
"font": 1501544,
|
||||
"group_id": 959613000,
|
||||
"message": "/ping",
|
||||
"message": [
|
||||
{
|
||||
"data": {
|
||||
"text": "/ping"
|
||||
},
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"message_id": 2071,
|
||||
"message_type": "group",
|
||||
"post_type": "message",
|
||||
|
|
2
req.txt
2
req.txt
|
@ -6,6 +6,7 @@ chardet==3.0.4
|
|||
Click==7.0
|
||||
decorator==4.4.2
|
||||
entrypoints==0.3
|
||||
feedparser==6.0.2
|
||||
flake8==3.7.9
|
||||
Flask==1.1.1
|
||||
idna==2.9
|
||||
|
@ -39,6 +40,7 @@ python-dateutil==2.8.1
|
|||
pyzmq==19.0.2
|
||||
redis==3.4.1
|
||||
requests==2.23.0
|
||||
sgmllib3k==1.0.0
|
||||
six==1.14.0
|
||||
sxtwl==1.1.0
|
||||
toml==0.10.1
|
||||
|
|
2
route.py
2
route.py
|
@ -6,7 +6,7 @@ def ZZRouter(data):
|
|||
gid = data['group_id']
|
||||
role = data['sender']['role']
|
||||
mid = data['message_id']
|
||||
parms = str.split(data['message'][1:])
|
||||
parms = str.split(data['raw_message'][1:])
|
||||
print(uid, gid, role, parms)
|
||||
if parms == []:
|
||||
parms[0] = 'help'
|
||||
|
|
15
test.py
15
test.py
|
@ -1,10 +1,12 @@
|
|||
from worker import emmm
|
||||
debug = True
|
||||
|
||||
|
||||
def de(e):
|
||||
if debug:
|
||||
print('DEBUG '+str(e))
|
||||
|
||||
|
||||
print("开始测试咯,在 '>' 后面输入n你的消息,不用加 '/'")
|
||||
inp = input('>')
|
||||
while(inp):
|
||||
|
@ -12,14 +14,21 @@ while(inp):
|
|||
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 Exception as e:
|
||||
de(e)
|
||||
Ans_ = emmm.Ans
|
||||
de(Ans_)
|
||||
try:
|
||||
Ans = Ans_(parms,uid=0,gid=0,role='owner',mid=1001, raw_msg={'message':'/' + inp, 'message_id' : '1001'})
|
||||
Ans = Ans_(parms, uid=0, gid=0, role='owner', mid=1001, raw_msg={'message': [
|
||||
{
|
||||
"data": {
|
||||
"text": f"/{inp}"
|
||||
},
|
||||
"type": "text"
|
||||
}
|
||||
], 'message_id': '1001', 'raw_message': f"/{inp}"})
|
||||
Message = Ans.GETMSG()
|
||||
except Exception as e:
|
||||
Message = ' Error:\n'+str(e)
|
||||
|
|
|
@ -5,7 +5,7 @@ class Ans(StdAns):
|
|||
if len(self.parms) < 2:
|
||||
return '不加参数是坏文明!'
|
||||
try:
|
||||
msg = str(bc(self.raw_msg['message'][5:]))
|
||||
msg = str(bc(self.raw_msg['raw_message'][5:]))
|
||||
except Exception as e:
|
||||
msg = str(e)
|
||||
return msg
|
||||
|
|
|
@ -10,7 +10,7 @@ class Ans(StdAns):
|
|||
|
||||
url = 'https://api.cognitive.microsoft.com/bing/v7.0/search'
|
||||
params = {
|
||||
'q':self.raw_msg['message'][5:],
|
||||
'q':self.raw_msg['raw_message'][5:],
|
||||
'count': 1,
|
||||
'mkt': 'zh-CN'
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ class Ans(StdAns):
|
|||
|
||||
def GETMSG(self):
|
||||
groups = self.getgroups()
|
||||
text = self.raw_msg['message'][11:]
|
||||
text = self.raw_msg['raw_message'][11:]
|
||||
gid = self.gid
|
||||
|
||||
for g in groups:
|
||||
|
|
|
@ -6,14 +6,14 @@ class Ans(StdAns):
|
|||
if len(self.parms) < 2:
|
||||
return '不加参数是坏文明!'
|
||||
|
||||
if mysakuya(self,self.raw_msg['message']) == False:
|
||||
if mysakuya(self,self.raw_msg['raw_message']) == False:
|
||||
return "不许你们说咲夜!!"
|
||||
|
||||
r = random.randint(1,3)
|
||||
if r == 1:
|
||||
msg = self.raw_msg['message'][6:]
|
||||
msg = self.raw_msg['raw_message'][6:]
|
||||
elif r == 2:
|
||||
msg = "汝以为咱会复读的嘛!\n(╯' - ')╯︵ ┻━┻\n" + self.raw_msg['message'][5:]
|
||||
msg = "汝以为咱会复读的嘛!\n(╯' - ')╯︵ ┻━┻\n" + self.raw_msg['raw_message'][5:]
|
||||
elif r == 3:
|
||||
msg = '咱才不做复读机。→_→'
|
||||
return msg
|
|
@ -12,7 +12,7 @@ class Ans(StdAns):
|
|||
def GETMSG(self):
|
||||
if self.parms:
|
||||
|
||||
if mysakuya(self, self.raw_msg['message']) == False:
|
||||
if mysakuya(self, self.raw_msg['raw_message']) == False:
|
||||
return "咲夜是最完美的!!"
|
||||
|
||||
return '咱也不知道' + self.parms[0] + '是啥呢~'
|
||||
|
|
|
@ -6,7 +6,7 @@ class Ans(StdAns):
|
|||
if len(self.parms) < 2:
|
||||
return '不加参数是坏文明!'
|
||||
|
||||
if mysakuya(self, self.raw_msg['message']) == False:
|
||||
if mysakuya(self, self.raw_msg['raw_message']) == False:
|
||||
return "不许你们说咲夜!!"
|
||||
|
||||
msg = f"[CQ:reply,id={self.raw_msg['message_id']}]"
|
||||
|
|
|
@ -18,7 +18,7 @@ class Ans(StdAns):
|
|||
elif cmd == 'list':
|
||||
msg = getList()
|
||||
elif cmd == 'say':
|
||||
saywhat = self.raw_msg['message'][8:]
|
||||
saywhat = self.raw_msg['raw_message'][8:]
|
||||
msg = say(saywhat)
|
||||
else:
|
||||
msg = '汝是不是在mc后面添加了奇怪的参数,咱可只知道 status list 和 say。'
|
||||
|
|
|
@ -12,7 +12,7 @@ class Ans(StdAns):
|
|||
url = 'http://inuyasha.love:8001/search'
|
||||
params = {
|
||||
'limit': 1,
|
||||
'keywords':self.raw_msg['message'][6:],
|
||||
'keywords':self.raw_msg['raw_message'][6:],
|
||||
}
|
||||
try:
|
||||
resp = requests.get(url=url,params=params).json()
|
||||
|
|
|
@ -6,7 +6,7 @@ class Ans(StdAns):
|
|||
if len(self.parms) < 2:
|
||||
return '不加参数是坏文明!'
|
||||
|
||||
domain = self.raw_msg['message'][4:]
|
||||
domain = self.raw_msg['raw_message'][4:]
|
||||
try:
|
||||
answer = check_output(['nslookup',domain],shell=False,timeout=4)
|
||||
msg = bytes.decode(answer)
|
||||
|
|
|
@ -76,7 +76,7 @@ class Ans(StdAns):
|
|||
return '初始化完成!请使用\n /pcr 血量 xxxx \n 来设置第一周目第一个Boss的总血量。'
|
||||
|
||||
if cmd == '登记':
|
||||
nickname = self.raw_msg['message'][8:]
|
||||
nickname = self.raw_msg['raw_message'][8:]
|
||||
if nickname:
|
||||
player = {
|
||||
'id':nickname,
|
||||
|
|
|
@ -21,7 +21,7 @@ class Ans(StdAns):
|
|||
'flag_qc': 0,
|
||||
'p': 1,
|
||||
'n': 20,
|
||||
'w':self.raw_msg['message'][8:],
|
||||
'w':self.raw_msg['raw_message'][8:],
|
||||
}
|
||||
try:
|
||||
resp = requests.get(url=url,params=params).text
|
||||
|
@ -29,9 +29,9 @@ class Ans(StdAns):
|
|||
# print(resp)
|
||||
if resp['data']['song']['totalnum'] == 0:
|
||||
return '啊嘞嘞好像没有诶qaq'
|
||||
mid = resp['data']['song']['list'][0]['mid']
|
||||
# id = resp['data']['song']['list'][0]['id']
|
||||
msg = f'[CQ:music,type=qq,id={mid}]'
|
||||
# mid = resp['data']['song']['list'][0]['mid']
|
||||
id = resp['data']['song']['list'][0]['id']
|
||||
msg = f'[CQ:music,type=qq,id={id}]'
|
||||
# mname = resp['data']['song']['list'][0]['name']
|
||||
# msg = '[CQ:share,url=https://y.qq.com/n/yqq/song/' + str(mid) + '.html,title=' + str(mname) + ']'
|
||||
except Exception as e:
|
||||
|
|
110
worker/rss.py
Normal file
110
worker/rss.py
Normal file
|
@ -0,0 +1,110 @@
|
|||
from zzcore import StdAns
|
||||
|
||||
import feedparser, json, time
|
||||
|
||||
allowCMD = ['sub','unsub','list','disable', 'enable']
|
||||
|
||||
# allSub = {
|
||||
# 'https://farseerfc.me/feeds/atom.xml' : {
|
||||
# 'url' : 'https://farseerfc.me/feeds/atom.xml',
|
||||
# 'title' : 'Farseerfc的小窩',
|
||||
# 'lastUpdated' : 'Sat, 12 Dec 2020 22:55:52 +0800',
|
||||
# }
|
||||
# }
|
||||
|
||||
class Ans(StdAns):
|
||||
|
||||
def push(self,title,posttitle,posturl):
|
||||
msg = f'{title}\n{posttitle} {posturl}'
|
||||
self.sendmsg(msg)
|
||||
|
||||
def GETMSG(self):
|
||||
|
||||
if len(self.parms) < 2:
|
||||
return '不加参数是坏文明!'
|
||||
|
||||
gid = str(self.gid)
|
||||
cmd = self.parms[1]
|
||||
if cmd not in allowCMD:
|
||||
return f'咱不知道 {cmd} 是什么东西 ●﹏●'
|
||||
|
||||
try:
|
||||
nowdata = json.loads(self.DATAGET()[gid])
|
||||
except:
|
||||
nowdata ={
|
||||
'allSub' : {},
|
||||
'status' : False,
|
||||
}
|
||||
|
||||
if cmd == 'sub':
|
||||
if len(self.parms) < 3:
|
||||
return '汝想订阅什么呢?'
|
||||
|
||||
suburl = self.parms[2]
|
||||
try:
|
||||
d = feedparser.parse(suburl)
|
||||
title = d.feed.title
|
||||
lastUpdated = d.entries[0].published
|
||||
|
||||
except:
|
||||
return "咱好像没能成功订阅 (╥_╥)"
|
||||
|
||||
newsub = {
|
||||
'url': suburl,
|
||||
'title': title,
|
||||
'lastUpdated' : lastUpdated,
|
||||
}
|
||||
|
||||
nowdata['allSub'][suburl] = newsub
|
||||
|
||||
msg = f'《{title}》订阅成功'
|
||||
|
||||
elif cmd == 'unsub':
|
||||
if len(self.parms) < 3:
|
||||
return '汝想退订什么呢?'
|
||||
|
||||
suburl = self.parms[2]
|
||||
if suburl not in nowdata['allSub'].keys():
|
||||
return '汝没有订阅过这个!'
|
||||
|
||||
unsub = nowdata['allSub'].pop(suburl)
|
||||
|
||||
msg = f"《{unsub['title']}》已退订"
|
||||
|
||||
elif cmd == 'list':
|
||||
msg = '订阅列表'
|
||||
|
||||
for sub in nowdata['allSub'].values():
|
||||
msg += f"\n{sub['title']} {sub['url']}"
|
||||
|
||||
elif cmd == 'enable':
|
||||
nowdata['status'] = True
|
||||
self.DATASET({gid:json.dumps(nowdata)})
|
||||
self.sendmsg("订阅已启用,咱会每隔五分钟抓取订阅,有新内容就会推送哦")
|
||||
while(nowdata['status']):
|
||||
nowdata = json.loads(self.DATAGET()[gid])
|
||||
for sub in nowdata['allSub'].values():
|
||||
try:
|
||||
d = feedparser.parse(sub['url'])
|
||||
except:
|
||||
self.sendmsg(f"咱抓取不到 《{sub['title']}》!")
|
||||
continue
|
||||
if d.entries[0].published == sub['lastUpdated']:
|
||||
continue
|
||||
|
||||
newfeedtitle = d.entries[0].title
|
||||
newfeedlink = d.entries[0].link
|
||||
self.push(sub['title'], newfeedtitle, newfeedlink)
|
||||
nowdata['allSub'][sub['url']]['lastUpdated'] = d.entries[0].published
|
||||
self.DATASET({gid:json.dumps(nowdata)})
|
||||
time.sleep(300)
|
||||
|
||||
return '订阅已经真的停了!'
|
||||
|
||||
elif cmd == 'disable':
|
||||
nowdata['status'] = False
|
||||
msg = '咱不会再推送了!'
|
||||
|
||||
self.DATASET({gid:json.dumps(nowdata)})
|
||||
return msg
|
||||
|
|
@ -54,7 +54,7 @@ class Ans(StdAns):
|
|||
'''
|
||||
lang = self.parms[1]
|
||||
i = 6 + len(lang)
|
||||
content = self.raw_msg['message'][i:]
|
||||
content = self.raw_msg['raw_message'][i:]
|
||||
try :
|
||||
langconfig = LANGS[lang]
|
||||
name = langconfig['filename']
|
||||
|
@ -79,6 +79,6 @@ def glot(name, content, url):
|
|||
"content": content,
|
||||
}]
|
||||
}
|
||||
resp = requests.post(url=url, headers=headers, json=data).json()
|
||||
resp = requests.post(url=url, headers=headers, json=data, verify=False).json()
|
||||
r = f"stdout:\n{resp['stdout']}\nstderr:\n{resp['stderr']}\nerror:\n{resp['error']}"
|
||||
return r
|
|
@ -9,7 +9,7 @@ class Ans(StdAns):
|
|||
if len(self.parms) < 2:
|
||||
text = "想让我说点什么呢?"
|
||||
else:
|
||||
text = self.raw_msg['message'][5:]
|
||||
text = self.raw_msg['raw_message'][5:]
|
||||
|
||||
try:
|
||||
b = tts(text)
|
||||
|
|
24
worker/wait.py
Normal file
24
worker/wait.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
from zzcore import StdAns
|
||||
import re
|
||||
import requests
|
||||
|
||||
|
||||
class Ans(StdAns):
|
||||
def GETMSG(self):
|
||||
try:
|
||||
url = self.raw_msg['message'][1]['data']['url']
|
||||
resp = requests.get(
|
||||
f"https://trace.moe/api/search?url={url}").json()['docs'][0]
|
||||
except:
|
||||
return "There something wrong."
|
||||
|
||||
video_url = f"https://media.trace.moe/video/{resp['anilist_id']}/{resp['filename']}?t={resp['at']}&token={resp['tokenthumb']}"
|
||||
video_url = video_url.replace("&","&").replace("[","[").replace("]","]").replace(",",",")
|
||||
m, s = divmod(float(resp['at']), 60)
|
||||
h, m = divmod(m, 60)
|
||||
# print("%02d:%02d:%02d" % (h, m, s))
|
||||
text = f"[CQ:reply,id={self.raw_msg['message_id']}]{resp['title_native']}\n{resp['title_chinese']}\nEP#{resp['episode']} {h:02.0f}:{m:02.0f}:{s:02.0f}\n{int(resp['similarity']*100)}% similarity"
|
||||
|
||||
msg = f"[CQ:video,file={video_url}]"
|
||||
self.sendmsg(text)
|
||||
return msg
|
|
@ -13,7 +13,7 @@ class Ans(StdAns):
|
|||
return '不加参数是坏文明!'
|
||||
|
||||
try:
|
||||
res = wolframsearch(self.raw_msg['message'][9:])
|
||||
res = wolframsearch(self.raw_msg['raw_message'][9:])
|
||||
msg = next(res.results).text
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
|
|
@ -36,8 +36,9 @@ def getWeather(id='101120206'):
|
|||
}
|
||||
r = requests.get(url=url, params=params).json()
|
||||
tdw = r['daily'][0]
|
||||
ndw = r['daily'][1]
|
||||
weather = f"今日日间{wemoji(tdw['textDay'])},温度{tdw['tempMin']}~{tdw['tempMax']}℃,{tdw['windDirDay']}{tdw['windScaleDay']}级;夜间{wemoji(tdw['textNight'])},{tdw['windDirNight']}{tdw['windScaleNight']}级。明日日间{wemoji(ndw['textDay'])},温度{ndw['tempMin']}~{ndw['tempMax']}℃。"
|
||||
# ndw = r['daily'][1]
|
||||
# weather = f"今日日间{wemoji(tdw['textDay'])},温度{tdw['tempMin']}~{tdw['tempMax']}℃,{tdw['windDirDay']}{tdw['windScaleDay']}级;夜间{wemoji(tdw['textNight'])},{tdw['windDirNight']}{tdw['windScaleNight']}级。明日日间{wemoji(ndw['textDay'])},温度{ndw['tempMin']}~{ndw['tempMax']}℃。"
|
||||
weather = f"今日日间{wemoji(tdw['textDay'])},温度{tdw['tempMin']}~{tdw['tempMax']}℃,{tdw['windDirDay']}{tdw['windScaleDay']}级;夜间{wemoji(tdw['textNight'])},{tdw['windDirNight']}{tdw['windScaleNight']}级。"
|
||||
if float(tdw['precip']) > 0:
|
||||
weather += '\n记得收好衣服,出门带伞~'
|
||||
|
||||
|
@ -46,24 +47,26 @@ def getWeather(id='101120206'):
|
|||
|
||||
def calendar():
|
||||
|
||||
ymc = ["十一", "十二", "正", "二", "三", "四", "五", "六", "七", "八", "九", "十"]
|
||||
ymc = ["冬", "腊", "正", "二", "三", "四", "五", "六", "七", "八", "九", "十"]
|
||||
rmc = ["初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五",
|
||||
"十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"]
|
||||
zmc = ["一", "二", "三", "四", "五", "六", "天"]
|
||||
nowdate = datetime.now()
|
||||
kaoyandate = datetime(2021,12,21)
|
||||
djs = (kaoyandate - nowdate).days -1
|
||||
y = nowdate.year
|
||||
m = nowdate.month
|
||||
d = nowdate.day
|
||||
zc = int(nowdate.strftime("%W")) - 34
|
||||
zc = int(nowdate.strftime("%W")) - 1
|
||||
|
||||
z = zmc[nowdate.weekday()]
|
||||
|
||||
lunar = sxtwl.Lunar()
|
||||
lunarday = lunar.getDayBySolar(y, m, d)
|
||||
|
||||
lunardaychinese = f"{ymc[lunarday.Lmc]}月{rmc[lunarday.Ldi]}日"
|
||||
lunardaychinese = f"{ymc[lunarday.Lmc]}月{rmc[lunarday.Ldi]}"
|
||||
if lunarday.Lleap:
|
||||
lunardaychinese = "闰" + lunardaychinese
|
||||
|
||||
cal = f"{m}月{d}日,农历{lunardaychinese},本学期第{zc}周,星期{z}"
|
||||
cal = f"{m}月{d}日,{lunardaychinese},寒假第{zc}周,星期{z}\n\n距离 2022 考研还有 {djs} 天"
|
||||
return cal
|
||||
|
|
|
@ -49,6 +49,14 @@ class StdAns():
|
|||
}
|
||||
return requests.get(url = url, params=data).json()['data']['message_id']
|
||||
|
||||
def get_img(self,cache_name):
|
||||
url = APIURL + "get_image"
|
||||
|
||||
data = {
|
||||
'access_token' : AUTHORIZATION,
|
||||
'file': cache_name
|
||||
}
|
||||
return requests.get(url = url, params=data).json()['data']['url']
|
||||
|
||||
def delmsg(self,msgid):
|
||||
url = APIURL + "delete_msg"
|
||||
|
|
Loading…
Reference in a new issue