diff --git a/req.txt b/req.txt index 2026441..762ff19 100644 --- a/req.txt +++ b/req.txt @@ -18,6 +18,7 @@ MarkupSafe==1.1.1 mccabe==0.6.1 more-itertools==8.2.0 pycodestyle==2.5.0 +pydub==0.24.1 pyflakes==2.1.1 pylint==2.4.4 redis==3.4.1 diff --git a/worker/emmm.py b/worker/emmm.py index d327b83..614494f 100644 --- a/worker/emmm.py +++ b/worker/emmm.py @@ -2,7 +2,7 @@ from zzcore import StdAns, mysakuya class Ans(StdAns): - NotAllowGroup = [204097403] + NotAllowGroup = [204097403, 1107535671] def CheckPermission(self): if self.gid in self.NotAllowGroup: diff --git a/worker/music.py b/worker/music.py index 04df6ba..6cb0b54 100644 --- a/worker/music.py +++ b/worker/music.py @@ -18,8 +18,8 @@ class Ans(StdAns): resp = requests.get(url=url,params=params).json() # print(resp) musicid = resp['result']['songs'][0]['id'] - musicname = resp['result']['songs'][0]['name'] - msg = '[CQ:share,url=https://music.163.com/song/' + str(musicid) + '/,title=' + str(musicname) + ']' + # musicname = resp['result']['songs'][0]['name'] + msg = f'[CQ:music,type=163,id={musicid}]' except Exception as e: print(e) msg = '什么东西坏掉了,大概是网易云吧...不可能是咱!' diff --git a/worker/qymusic.py b/worker/qymusic.py index fc39aad..3d59627 100644 --- a/worker/qymusic.py +++ b/worker/qymusic.py @@ -30,8 +30,10 @@ class Ans(StdAns): if resp['data']['song']['totalnum'] == 0: return '啊嘞嘞好像没有诶qaq' mid = resp['data']['song']['list'][0]['mid'] - mname = resp['data']['song']['list'][0]['name'] - msg = '[CQ:share,url=https://y.qq.com/n/yqq/song/' + str(mid) + '.html,title=' + str(mname) + ']' + # id = resp['data']['song']['list'][0]['id'] + msg = f'[CQ:music,type=qq,id={mid}]' + # 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: print(e) msg = '什么东西坏掉了,大概是疼讯吧...不可能是咱!' diff --git a/worker/run.py b/worker/run.py new file mode 100644 index 0000000..4fd1af6 --- /dev/null +++ b/worker/run.py @@ -0,0 +1,84 @@ +import json +import requests +from zzcore import StdAns +from config import GLOTTOKEN + +LANGS = { + 'assembly': {'filename': 'main.assembly', 'url': 'https://run.glot.io/languages/assembly'}, + 'ats': {'filename': 'main.ats', 'url': 'https://run.glot.io/languages/ats'}, + 'bash': {'filename': 'main.bash', 'url': 'https://run.glot.io/languages/bash'}, + 'c': {'filename': 'main.c', 'url': 'https://run.glot.io/languages/c'}, + 'clojure': {'filename': 'main.clojure', 'url': 'https://run.glot.io/languages/clojure'}, + 'cobol': {'filename': 'main.cobol', 'url': 'https://run.glot.io/languages/cobol'}, + 'coffeescript': {'filename': 'main.coffeescript', 'url': 'https://run.glot.io/languages/coffeescript'}, + 'cpp': {'filename': 'main.cpp', 'url': 'https://run.glot.io/languages/cpp'}, + 'crystal': {'filename': 'main.crystal', 'url': 'https://run.glot.io/languages/crystal'}, + 'csharp': {'filename': 'main.csharp', 'url': 'https://run.glot.io/languages/csharp'}, + 'd': {'filename': 'main.d', 'url': 'https://run.glot.io/languages/d'}, + 'elixir': {'filename': 'main.elixir', 'url': 'https://run.glot.io/languages/elixir'}, + 'elm': {'filename': 'main.elm', 'url': 'https://run.glot.io/languages/elm'}, + 'erlang': {'filename': 'main.erlang', 'url': 'https://run.glot.io/languages/erlang'}, + 'fsharp': {'filename': 'main.fsharp', 'url': 'https://run.glot.io/languages/fsharp'}, + 'go': {'filename': 'main.go', 'url': 'https://run.glot.io/languages/go'}, + 'groovy': {'filename': 'main.groovy', 'url': 'https://run.glot.io/languages/groovy'}, + 'haskell': {'filename': 'main.haskell', 'url': 'https://run.glot.io/languages/haskell'}, + 'idris': {'filename': 'main.idris', 'url': 'https://run.glot.io/languages/idris'}, + 'java': {'filename': 'main.java', 'url': 'https://run.glot.io/languages/java'}, + 'javascript': {'filename': 'main.javascript', 'url': 'https://run.glot.io/languages/javascript'}, + 'julia': {'filename': 'main.julia', 'url': 'https://run.glot.io/languages/julia'}, + 'kotlin': {'filename': 'main.kotlin', 'url': 'https://run.glot.io/languages/kotlin'}, + 'lua': {'filename': 'main.lua', 'url': 'https://run.glot.io/languages/lua'}, + 'mercury': {'filename': 'main.mercury', 'url': 'https://run.glot.io/languages/mercury'}, + 'nim': {'filename': 'main.nim', 'url': 'https://run.glot.io/languages/nim'}, + 'ocaml': {'filename': 'main.ocaml', 'url': 'https://run.glot.io/languages/ocaml'}, + 'perl': {'filename': 'main.perl', 'url': 'https://run.glot.io/languages/perl'}, + 'perl6': {'filename': 'main.perl6', 'url': 'https://run.glot.io/languages/perl6'}, + 'php': {'filename': 'main.php', 'url': 'https://run.glot.io/languages/php'}, + 'python': {'filename': 'main.python', 'url': 'https://run.glot.io/languages/python'}, + 'ruby': {'filename': 'main.ruby', 'url': 'https://run.glot.io/languages/ruby'}, + 'rust': {'filename': 'main.rust', 'url': 'https://run.glot.io/languages/rust'}, + 'scala': {'filename': 'main.scala', 'url': 'https://run.glot.io/languages/scala'}, + 'swift': {'filename': 'main.swift', 'url': 'https://run.glot.io/languages/swift'}, + 'typescript': {'filename': 'main.typescript', 'url': 'https://run.glot.io/languages/typescript'} + } + +class Ans(StdAns): + + def GETMSG(self): + if len(self.parms) < 3: + return '''Usage: +/run + + +支持的语言:assembly ats bash c clojure cobol coffeescript cpp crystal csharp d elixir elm erlang fsharp go groovy haskell idris java javascript julia kotlin lua mercury nim ocaml perl perl6 php python ruby rust scala swift typescript +''' + lang = self.parms[1] + i = 6 + len(lang) + content = self.raw_msg['message'][i:] + try : + langconfig = LANGS[lang] + name = langconfig['filename'] + url = langconfig['url'] + '/latest' + except : + return f'不支持的语言 {lang}' + + msg = glot(name, content, url) + return msg + + + +def glot(name, content, url): + headers = { + 'Authorization': f'Token {GLOTTOKEN}', + 'Content-type': 'application/json', + } + + data = { + "files": [{ + "name": name, + "content": content, + }] + } + resp = requests.post(url=url, headers=headers, json=data).json() + r = f"stdout:\n{resp['stdout']}\nstderr:\n{resp['stderr']}\nerror:\n{resp['error']}" + return r \ No newline at end of file diff --git a/worker/talk.py b/worker/talk.py new file mode 100644 index 0000000..43e2580 --- /dev/null +++ b/worker/talk.py @@ -0,0 +1,41 @@ +from zzcore import StdAns + +from pydub import AudioSegment +from base64 import b64encode +import requests, io + +class Ans(StdAns): + def GETMSG(self): + if len(self.parms) < 2: + text = "想让我说点什么呢?" + else: + text = self.raw_msg['message'][5:] + + try: + b = tts(text) + msg = f'[CQ:record,file=base64://{str(b)}]' + except: + msg = '什么东西坏掉了,...咱不能说话了!' + return msg + +def tts(text): + url = "https://tts.baidu.com/text2audio" + params = { + 'cuid': 'baike', + 'lan': 'zh', + 'ctp': 1, + 'pdt': 301, + 'vol': 5, + 'rate': 32, + 'per': 5118, + 'tex': text, + } + + r = requests.get(url=url, params=params) + s = io.BytesIO(r.content) + r.close() + # s.seek(0,0) + song = AudioSegment.from_mp3(s) + amr = song.export(format="amr", parameters=["-ar", "8000"]) + b = b64encode(amr.read()).decode("utf-8") + return b \ No newline at end of file