From 29edd8c9960b02e49d7865e4828a8ed5ddeba333 Mon Sep 17 00:00:00 2001 From: SiHuan Date: Sat, 26 Dec 2020 20:09:56 +0800 Subject: [PATCH 01/26] add rss --- worker/rss.py | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 worker/rss.py diff --git a/worker/rss.py b/worker/rss.py new file mode 100644 index 0000000..8039316 --- /dev/null +++ b/worker/rss.py @@ -0,0 +1,107 @@ +from zzcore import StdAns + +import feedparser, json + +allowCMD = ['sub','unsub','list','get'] + +allSub = [ + { + '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.feed.updated + + 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']: + 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']: + try: + d = feedparser.parse(sub['url']) + except: + self.sendmsg(f"咱抓取不到 《{sub['title']}》!") + continue + if d.feed.updated == 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.feed.updated + self.DATASET({gid:json.dumps(nowdata)}) + + elif cmd == 'disable': + nowdata['status'] = False + msg = '咱不会再推送了!' + + self.DATASET({gid:json.dumps(nowdata)}) + return msg + \ No newline at end of file From 38e2b7bf129f7ec2e6e3e3e4dd247b2e72bbee8c Mon Sep 17 00:00:00 2001 From: SiHuan Date: Sat, 26 Dec 2020 20:17:57 +0800 Subject: [PATCH 02/26] fix rss --- worker/rss.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/worker/rss.py b/worker/rss.py index 8039316..61a844b 100644 --- a/worker/rss.py +++ b/worker/rss.py @@ -2,15 +2,15 @@ from zzcore import StdAns import feedparser, json -allowCMD = ['sub','unsub','list','get'] +allowCMD = ['sub','unsub','list','disable'] -allSub = [ - { - 'url' : 'https://farseerfc.me/feeds/atom.xml', - 'title' : 'Farseerfc的小窩', - 'lastUpdated' : 'Sat, 12 Dec 2020 22:55:52 +0800', - } -] +# 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): @@ -75,7 +75,7 @@ class Ans(StdAns): msg = '订阅列表' for sub in nowdata['allSub']: - msg += f'\n{sub.title} {sub.url}' + msg += f"\n{sub['title']} {sub['url']}" elif cmd == 'enable': nowdata['status'] = True From 569713567f4834acb20363e8d39b86cdd530f839 Mon Sep 17 00:00:00 2001 From: SiHuan Date: Sat, 26 Dec 2020 20:21:39 +0800 Subject: [PATCH 03/26] fix rss --- worker/rss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/rss.py b/worker/rss.py index 61a844b..44f1b57 100644 --- a/worker/rss.py +++ b/worker/rss.py @@ -69,7 +69,7 @@ class Ans(StdAns): unsub = nowdata['allSub'].pop(suburl) - msg = f'《{unsub.title}》已退订' + msg = f"《{unsub['title']}》已退订" elif cmd == 'list': msg = '订阅列表' From 4c21b1d6645eb33fb66f7cf020bbf955ec9ef21a Mon Sep 17 00:00:00 2001 From: SiHuan Date: Sat, 26 Dec 2020 20:25:34 +0800 Subject: [PATCH 04/26] fix rss --- worker/rss.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worker/rss.py b/worker/rss.py index 44f1b57..59375cd 100644 --- a/worker/rss.py +++ b/worker/rss.py @@ -74,7 +74,7 @@ class Ans(StdAns): elif cmd == 'list': msg = '订阅列表' - for sub in nowdata['allSub']: + for sub in nowdata['allSub'].values(): msg += f"\n{sub['title']} {sub['url']}" elif cmd == 'enable': @@ -83,7 +83,7 @@ class Ans(StdAns): self.sendmsg("订阅已启用,咱会每隔五分钟抓去订阅,有新内容就会推送哦") while(nowdata['status']): nowdata = json.loads(self.DATAGET()[gid]) - for sub in nowdata['allSub']: + for sub in nowdata['allSub'].values(): try: d = feedparser.parse(sub['url']) except: From 64c28953fa58a0b56f04ace40df6a3fc12320702 Mon Sep 17 00:00:00 2001 From: SiHuan Date: Sat, 26 Dec 2020 20:31:53 +0800 Subject: [PATCH 05/26] fix rss --- worker/rss.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/worker/rss.py b/worker/rss.py index 59375cd..36c561e 100644 --- a/worker/rss.py +++ b/worker/rss.py @@ -44,7 +44,7 @@ class Ans(StdAns): try: d = feedparser.parse(suburl) title = d.feed.title - lastUpdated = d.feed.updated + lastUpdated = d.entries[0].published except: return "咱好像没能成功订阅 (╥_╥)" @@ -89,13 +89,13 @@ class Ans(StdAns): except: self.sendmsg(f"咱抓取不到 《{sub['title']}》!") continue - if d.feed.updated == sub['lastUpdated']: + 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.feed.updated + nowdata['allSub'][sub['url']]['lastUpdated'] = d.entries[0].published self.DATASET({gid:json.dumps(nowdata)}) elif cmd == 'disable': From 562c433235c7d4d46eb76659376a30d27dba52db Mon Sep 17 00:00:00 2001 From: SiHuan Date: Sat, 26 Dec 2020 20:33:25 +0800 Subject: [PATCH 06/26] fix rss --- worker/rss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/rss.py b/worker/rss.py index 36c561e..a1679e6 100644 --- a/worker/rss.py +++ b/worker/rss.py @@ -2,7 +2,7 @@ from zzcore import StdAns import feedparser, json -allowCMD = ['sub','unsub','list','disable'] +allowCMD = ['sub','unsub','list','disable', 'enable'] # allSub = { # 'https://farseerfc.me/feeds/atom.xml' : { From 53f71d822a0d5db27d8b6825f872affc692b26e6 Mon Sep 17 00:00:00 2001 From: SiHuan Date: Sat, 26 Dec 2020 20:36:04 +0800 Subject: [PATCH 07/26] fix rss --- worker/rss.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/worker/rss.py b/worker/rss.py index a1679e6..7566f60 100644 --- a/worker/rss.py +++ b/worker/rss.py @@ -1,6 +1,6 @@ from zzcore import StdAns -import feedparser, json +import feedparser, json, time allowCMD = ['sub','unsub','list','disable', 'enable'] @@ -80,7 +80,7 @@ class Ans(StdAns): elif cmd == 'enable': nowdata['status'] = True self.DATASET({gid:json.dumps(nowdata)}) - self.sendmsg("订阅已启用,咱会每隔五分钟抓去订阅,有新内容就会推送哦") + self.sendmsg("订阅已启用,咱会每隔五分钟抓取订阅,有新内容就会推送哦") while(nowdata['status']): nowdata = json.loads(self.DATAGET()[gid]) for sub in nowdata['allSub'].values(): @@ -97,6 +97,7 @@ class Ans(StdAns): self.push(sub['title'], newfeedtitle, newfeedlink) nowdata['allSub'][sub['url']]['lastUpdated'] = d.entries[0].published self.DATASET({gid:json.dumps(nowdata)}) + time.sleep() elif cmd == 'disable': nowdata['status'] = False From de022d4dc11b3a3c6db9aea4004c3205fc754b12 Mon Sep 17 00:00:00 2001 From: SiHuan Date: Sat, 26 Dec 2020 20:47:52 +0800 Subject: [PATCH 08/26] fix rss --- worker/rss.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/worker/rss.py b/worker/rss.py index 7566f60..7c82b09 100644 --- a/worker/rss.py +++ b/worker/rss.py @@ -99,6 +99,8 @@ class Ans(StdAns): self.DATASET({gid:json.dumps(nowdata)}) time.sleep() + return '订阅已经真的停了!' + elif cmd == 'disable': nowdata['status'] = False msg = '咱不会再推送了!' From 0776c01a08581f136eafeed68a060c64e9e8c45a Mon Sep 17 00:00:00 2001 From: SiHuan Date: Sat, 26 Dec 2020 21:56:08 +0800 Subject: [PATCH 09/26] fix rss --- worker/rss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/rss.py b/worker/rss.py index 7c82b09..3f0b0ea 100644 --- a/worker/rss.py +++ b/worker/rss.py @@ -97,7 +97,7 @@ class Ans(StdAns): self.push(sub['title'], newfeedtitle, newfeedlink) nowdata['allSub'][sub['url']]['lastUpdated'] = d.entries[0].published self.DATASET({gid:json.dumps(nowdata)}) - time.sleep() + time.sleep(5000) return '订阅已经真的停了!' From 911796444b3489311b290a11a42cf6477c208c66 Mon Sep 17 00:00:00 2001 From: SiHuan Date: Sat, 26 Dec 2020 22:40:31 +0800 Subject: [PATCH 10/26] fix rss --- worker/rss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/rss.py b/worker/rss.py index 3f0b0ea..90546b9 100644 --- a/worker/rss.py +++ b/worker/rss.py @@ -97,7 +97,7 @@ class Ans(StdAns): self.push(sub['title'], newfeedtitle, newfeedlink) nowdata['allSub'][sub['url']]['lastUpdated'] = d.entries[0].published self.DATASET({gid:json.dumps(nowdata)}) - time.sleep(5000) + time.sleep(300) return '订阅已经真的停了!' From 27cb20fffed493690b1687e39ca2fc0ad866bf20 Mon Sep 17 00:00:00 2001 From: SiHuan Date: Wed, 13 Jan 2021 09:50:36 +0800 Subject: [PATCH 11/26] update zhaoan --- worker/zhaoan.py | 8 ++++---- zaoan.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 zaoan.py diff --git a/worker/zhaoan.py b/worker/zhaoan.py index df98571..678e2f7 100644 --- a/worker/zhaoan.py +++ b/worker/zhaoan.py @@ -46,7 +46,7 @@ def getWeather(id='101120206'): def calendar(): - ymc = ["十一", "十二", "正", "二", "三", "四", "五", "六", "七", "八", "九", "十"] + ymc = ["冬", "腊", "正", "二", "三", "四", "五", "六", "七", "八", "九", "十"] rmc = ["初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"] zmc = ["一", "二", "三", "四", "五", "六", "天"] @@ -54,16 +54,16 @@ def calendar(): 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}" return cal diff --git a/zaoan.py b/zaoan.py new file mode 100644 index 0000000..80b40f3 --- /dev/null +++ b/zaoan.py @@ -0,0 +1,36 @@ +import requests +import json + +url = 'http://127.0.0.1:5580/' +headers = {'Content-Type': 'application/json'} + +gids = [743539576, 959613860, 1107535671] + +data = { + "anonymous": "None", + "font": 1501544, + "group_id": 959613860, + "message": "/zhaoan", + "message_id": 2071, + "message_type": "group", + "post_type": "message", + "raw_message": "/zhaoan", + "self_id": 161795000, + "sender": { + "age": 18, + "area": "济宁", + "card": "", + "level": "活跃", + "nickname": "SiHuan", + "role": "owner", + "sex": "unknown", + "title": "", + "user_id": 1318000000 + }, + "sub_type": "normal", + "time": 1582805370, + "user_id": 1318000000 +} +for gid in gids: + data['group_id'] = gid + requests.post(url=url, headers=headers, data=json.dumps(data)) \ No newline at end of file From 224e404b34f8a0d25a06f041414c5281c381186e Mon Sep 17 00:00:00 2001 From: SiHuan Date: Wed, 13 Jan 2021 09:52:31 +0800 Subject: [PATCH 12/26] rm zaoan script --- zaoan.py | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 zaoan.py diff --git a/zaoan.py b/zaoan.py deleted file mode 100644 index 80b40f3..0000000 --- a/zaoan.py +++ /dev/null @@ -1,36 +0,0 @@ -import requests -import json - -url = 'http://127.0.0.1:5580/' -headers = {'Content-Type': 'application/json'} - -gids = [743539576, 959613860, 1107535671] - -data = { - "anonymous": "None", - "font": 1501544, - "group_id": 959613860, - "message": "/zhaoan", - "message_id": 2071, - "message_type": "group", - "post_type": "message", - "raw_message": "/zhaoan", - "self_id": 161795000, - "sender": { - "age": 18, - "area": "济宁", - "card": "", - "level": "活跃", - "nickname": "SiHuan", - "role": "owner", - "sex": "unknown", - "title": "", - "user_id": 1318000000 - }, - "sub_type": "normal", - "time": 1582805370, - "user_id": 1318000000 -} -for gid in gids: - data['group_id'] = gid - requests.post(url=url, headers=headers, data=json.dumps(data)) \ No newline at end of file From e29f3a4991a1173b191a5fb2ffbc4dadaf7a654b Mon Sep 17 00:00:00 2001 From: SiHuan Date: Thu, 14 Jan 2021 09:47:58 +0800 Subject: [PATCH 13/26] update zhaoan --- worker/zhaoan.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/worker/zhaoan.py b/worker/zhaoan.py index 678e2f7..085f02c 100644 --- a/worker/zhaoan.py +++ b/worker/zhaoan.py @@ -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记得收好衣服,出门带伞~' @@ -51,6 +52,8 @@ def calendar(): "十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"] zmc = ["一", "二", "三", "四", "五", "六", "天"] nowdate = datetime.now() + kaoyandate = datetime(2021,12,26) + djs = (kaoyandate - nowdate).days y = nowdate.year m = nowdate.month d = nowdate.day @@ -65,5 +68,5 @@ def calendar(): if lunarday.Lleap: lunardaychinese = "闰" + lunardaychinese - cal = f"{m}月{d}日,{lunardaychinese},寒假第{zc}周,星期{z}" + cal = f"{m}月{d}日,{lunardaychinese},寒假第{zc}周,星期{z}\n距离 2022 考研还有 {djs} 天" return cal From 2c9b435bad2701c77c965817829294eafc203677 Mon Sep 17 00:00:00 2001 From: SiHuan Date: Thu, 14 Jan 2021 09:50:41 +0800 Subject: [PATCH 14/26] update zhaoan --- worker/zhaoan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/zhaoan.py b/worker/zhaoan.py index 085f02c..bac6518 100644 --- a/worker/zhaoan.py +++ b/worker/zhaoan.py @@ -53,7 +53,7 @@ def calendar(): zmc = ["一", "二", "三", "四", "五", "六", "天"] nowdate = datetime.now() kaoyandate = datetime(2021,12,26) - djs = (kaoyandate - nowdate).days + djs = (kaoyandate - nowdate).days - 1 y = nowdate.year m = nowdate.month d = nowdate.day From 687ad02f697f778754384048fee17b2b1747a428 Mon Sep 17 00:00:00 2001 From: SiHuan Date: Thu, 14 Jan 2021 09:54:53 +0800 Subject: [PATCH 15/26] update zhaoan --- worker/zhaoan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/zhaoan.py b/worker/zhaoan.py index bac6518..aa7ffd5 100644 --- a/worker/zhaoan.py +++ b/worker/zhaoan.py @@ -68,5 +68,5 @@ def calendar(): if lunarday.Lleap: lunardaychinese = "闰" + lunardaychinese - cal = f"{m}月{d}日,{lunardaychinese},寒假第{zc}周,星期{z}\n距离 2022 考研还有 {djs} 天" + cal = f"{m}月{d}日,{lunardaychinese},寒假第{zc}周,星期{z}\n\n距离 2022 考研还有 {djs} 天" return cal From 6d0c37351dd2102552b1b52ff7f8c717dd1ce934 Mon Sep 17 00:00:00 2001 From: SiHuan Date: Thu, 14 Jan 2021 14:12:53 +0800 Subject: [PATCH 16/26] update zhaoan --- worker/zhaoan.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worker/zhaoan.py b/worker/zhaoan.py index aa7ffd5..06da5d3 100644 --- a/worker/zhaoan.py +++ b/worker/zhaoan.py @@ -52,8 +52,8 @@ def calendar(): "十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"] zmc = ["一", "二", "三", "四", "五", "六", "天"] nowdate = datetime.now() - kaoyandate = datetime(2021,12,26) - djs = (kaoyandate - nowdate).days - 1 + kaoyandate = datetime(2021,12,21) + djs = (kaoyandate - nowdate).days -1 y = nowdate.year m = nowdate.month d = nowdate.day From c8f2e9a226ff8ab28d386357a13d6370fad0aefb Mon Sep 17 00:00:00 2001 From: weilinfox Date: Tue, 26 Jan 2021 00:30:01 +0800 Subject: [PATCH 17/26] fix qymusic --- worker/qymusic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/worker/qymusic.py b/worker/qymusic.py index 3d59627..a616040 100644 --- a/worker/qymusic.py +++ b/worker/qymusic.py @@ -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: From 059f067505ac1d760b6eca74e7f9d8d56e65739d Mon Sep 17 00:00:00 2001 From: SiHuan Date: Tue, 26 Jan 2021 23:58:00 +0800 Subject: [PATCH 18/26] add wait --- route.py | 2 +- worker/wait.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 worker/wait.py diff --git a/route.py b/route.py index 1faa2d4..06c8257 100644 --- a/route.py +++ b/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['message'][0]['data']['text'][1:]) print(uid, gid, role, parms) if parms == []: parms[0] = 'help' diff --git a/worker/wait.py b/worker/wait.py new file mode 100644 index 0000000..3da9244 --- /dev/null +++ b/worker/wait.py @@ -0,0 +1,23 @@ +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']}" + + m, s = divmod(float(resp['at']), 60) + h, m = divmod(m, 60) + print("%02d:%02d:%02d" % (h, m, s)) + text = f"{resp['title_native']}\n{resp['title_chinese']}\nEP#{resp['episode']} {h:02.0f}:{m:02.0f}:{s:02.0f}\n{resp['similarity'][:5]} similarity" + + msg = f"[CQ:video,file={video_url}]\n{text}" + return msg \ No newline at end of file From 00b94259213be7887a44f63bcdb844d830ae0c3f Mon Sep 17 00:00:00 2001 From: SiHuan Date: Wed, 27 Jan 2021 10:05:06 +0800 Subject: [PATCH 19/26] core add get_img --- zzcore.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zzcore.py b/zzcore.py index 6117918..81b8fd5 100644 --- a/zzcore.py +++ b/zzcore.py @@ -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" From 816e0ef2c397c918a0524c5fa95afb15c332b6eb Mon Sep 17 00:00:00 2001 From: SiHuan Date: Wed, 27 Jan 2021 11:33:32 +0800 Subject: [PATCH 20/26] use array msg --- exmple.json | 9 ++++++++- test.py | 15 ++++++++++++--- worker/bbc.py | 2 +- worker/bing.py | 2 +- worker/broadcast.py | 2 +- worker/echo.py | 6 +++--- worker/emmm.py | 2 +- worker/hhsh.py | 2 +- worker/mc.py | 2 +- worker/music.py | 2 +- worker/ns.py | 2 +- worker/pcr.py | 2 +- worker/qymusic.py | 2 +- worker/run.py | 2 +- worker/talk.py | 2 +- worker/wait.py | 4 ++-- worker/wolfram.py | 2 +- 17 files changed, 38 insertions(+), 22 deletions(-) diff --git a/exmple.json b/exmple.json index bd8d1df..b06162b 100644 --- a/exmple.json +++ b/exmple.json @@ -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", diff --git a/test.py b/test.py index 8902ccc..665b303 100644 --- a/test.py +++ b/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) diff --git a/worker/bbc.py b/worker/bbc.py index b654691..064d4f8 100644 --- a/worker/bbc.py +++ b/worker/bbc.py @@ -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 diff --git a/worker/bing.py b/worker/bing.py index 0626aed..23fdd8f 100644 --- a/worker/bing.py +++ b/worker/bing.py @@ -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' } diff --git a/worker/broadcast.py b/worker/broadcast.py index 3a993e5..87bbd8e 100644 --- a/worker/broadcast.py +++ b/worker/broadcast.py @@ -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: diff --git a/worker/echo.py b/worker/echo.py index 4ac5437..859050a 100644 --- a/worker/echo.py +++ b/worker/echo.py @@ -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 \ No newline at end of file diff --git a/worker/emmm.py b/worker/emmm.py index 614494f..3d94263 100644 --- a/worker/emmm.py +++ b/worker/emmm.py @@ -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] + '是啥呢~' diff --git a/worker/hhsh.py b/worker/hhsh.py index 97df0ef..16af5c2 100644 --- a/worker/hhsh.py +++ b/worker/hhsh.py @@ -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']}]" diff --git a/worker/mc.py b/worker/mc.py index 5a36c1a..92a847c 100644 --- a/worker/mc.py +++ b/worker/mc.py @@ -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。' diff --git a/worker/music.py b/worker/music.py index 6cb0b54..4119840 100644 --- a/worker/music.py +++ b/worker/music.py @@ -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() diff --git a/worker/ns.py b/worker/ns.py index 99e2764..44c3dc4 100644 --- a/worker/ns.py +++ b/worker/ns.py @@ -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) diff --git a/worker/pcr.py b/worker/pcr.py index d9a9d4d..dc1bd58 100644 --- a/worker/pcr.py +++ b/worker/pcr.py @@ -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, diff --git a/worker/qymusic.py b/worker/qymusic.py index a616040..f22a38a 100644 --- a/worker/qymusic.py +++ b/worker/qymusic.py @@ -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 diff --git a/worker/run.py b/worker/run.py index 4fd1af6..ab41c91 100644 --- a/worker/run.py +++ b/worker/run.py @@ -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'] diff --git a/worker/talk.py b/worker/talk.py index 43e2580..ec0f305 100644 --- a/worker/talk.py +++ b/worker/talk.py @@ -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) diff --git a/worker/wait.py b/worker/wait.py index 3da9244..ab5eff4 100644 --- a/worker/wait.py +++ b/worker/wait.py @@ -13,10 +13,10 @@ class Ans(StdAns): 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)) + # print("%02d:%02d:%02d" % (h, m, s)) text = f"{resp['title_native']}\n{resp['title_chinese']}\nEP#{resp['episode']} {h:02.0f}:{m:02.0f}:{s:02.0f}\n{resp['similarity'][:5]} similarity" msg = f"[CQ:video,file={video_url}]\n{text}" diff --git a/worker/wolfram.py b/worker/wolfram.py index 9a0cdda..32769ce 100644 --- a/worker/wolfram.py +++ b/worker/wolfram.py @@ -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) From aad34a3e732775d737f057ed5b5184a78163a062 Mon Sep 17 00:00:00 2001 From: SiHuan Date: Wed, 27 Jan 2021 11:44:13 +0800 Subject: [PATCH 21/26] fix wait --- worker/wait.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/wait.py b/worker/wait.py index ab5eff4..c0f997b 100644 --- a/worker/wait.py +++ b/worker/wait.py @@ -17,7 +17,7 @@ class Ans(StdAns): m, s = divmod(float(resp['at']), 60) h, m = divmod(m, 60) # print("%02d:%02d:%02d" % (h, m, s)) - text = f"{resp['title_native']}\n{resp['title_chinese']}\nEP#{resp['episode']} {h:02.0f}:{m:02.0f}:{s:02.0f}\n{resp['similarity'][:5]} similarity" + text = f"{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}]\n{text}" return msg \ No newline at end of file From 7fdffc3dc29d7a277357cb804609a29bf112aa02 Mon Sep 17 00:00:00 2001 From: SiHuan Date: Wed, 27 Jan 2021 11:57:06 +0800 Subject: [PATCH 22/26] fix wait --- worker/wait.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/worker/wait.py b/worker/wait.py index c0f997b..73fbf81 100644 --- a/worker/wait.py +++ b/worker/wait.py @@ -19,5 +19,6 @@ class Ans(StdAns): # print("%02d:%02d:%02d" % (h, m, s)) text = f"{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}]\n{text}" + msg = f"[CQ:video,file={video_url}]" + self.sendmsg(text) return msg \ No newline at end of file From 929d7a4083ec71e9443ed1f7236c1c700bd901aa Mon Sep 17 00:00:00 2001 From: SiHuan Date: Wed, 27 Jan 2021 12:12:20 +0800 Subject: [PATCH 23/26] update wait --- worker/wait.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/wait.py b/worker/wait.py index 73fbf81..fe2bda1 100644 --- a/worker/wait.py +++ b/worker/wait.py @@ -17,7 +17,7 @@ class Ans(StdAns): m, s = divmod(float(resp['at']), 60) h, m = divmod(m, 60) # print("%02d:%02d:%02d" % (h, m, s)) - text = f"{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" + 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) From e194b4f64495ad988a9ddf3405a2626a1d88b79e Mon Sep 17 00:00:00 2001 From: SiHuan Date: Wed, 27 Jan 2021 14:42:24 +0800 Subject: [PATCH 24/26] update router --- route.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/route.py b/route.py index 06c8257..2f32226 100644 --- a/route.py +++ b/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'][0]['data']['text'][1:]) + parms = str.split(data['raw_message'][1:]) print(uid, gid, role, parms) if parms == []: parms[0] = 'help' From 4dd37d9f98c70eb22fa7f95c7c5e82a36cb9a1a0 Mon Sep 17 00:00:00 2001 From: SiHuan Date: Wed, 27 Jan 2021 16:08:36 +0800 Subject: [PATCH 25/26] update req --- req.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/req.txt b/req.txt index df00370..d1d9b3e 100644 --- a/req.txt +++ b/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 From 74611fb881ac1498b1a19c865acbce64a868e5de Mon Sep 17 00:00:00 2001 From: weilinfox Date: Mon, 15 Feb 2021 18:25:31 +0800 Subject: [PATCH 26/26] fix run.py ssl error --- worker/run.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worker/run.py b/worker/run.py index 4fd1af6..e46855d 100644 --- a/worker/run.py +++ b/worker/run.py @@ -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 \ No newline at end of file + return r