Merge pull request #8 from Si-Huan/master

update
This commit is contained in:
weilinfox 2020-08-25 23:59:43 +08:00 committed by GitHub
commit 8b6a49d441
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 133 additions and 5 deletions

View file

@ -18,6 +18,7 @@ MarkupSafe==1.1.1
mccabe==0.6.1 mccabe==0.6.1
more-itertools==8.2.0 more-itertools==8.2.0
pycodestyle==2.5.0 pycodestyle==2.5.0
pydub==0.24.1
pyflakes==2.1.1 pyflakes==2.1.1
pylint==2.4.4 pylint==2.4.4
redis==3.4.1 redis==3.4.1

View file

@ -2,7 +2,7 @@ from zzcore import StdAns, mysakuya
class Ans(StdAns): class Ans(StdAns):
NotAllowGroup = [204097403] NotAllowGroup = [204097403, 1107535671]
def CheckPermission(self): def CheckPermission(self):
if self.gid in self.NotAllowGroup: if self.gid in self.NotAllowGroup:

View file

@ -18,8 +18,8 @@ class Ans(StdAns):
resp = requests.get(url=url,params=params).json() resp = requests.get(url=url,params=params).json()
# print(resp) # print(resp)
musicid = resp['result']['songs'][0]['id'] musicid = resp['result']['songs'][0]['id']
musicname = resp['result']['songs'][0]['name'] # musicname = resp['result']['songs'][0]['name']
msg = '[CQ:share,url=https://music.163.com/song/' + str(musicid) + '/,title=' + str(musicname) + ']' msg = f'[CQ:music,type=163,id={musicid}]'
except Exception as e: except Exception as e:
print(e) print(e)
msg = '什么东西坏掉了,大概是网易云吧...不可能是咱!' msg = '什么东西坏掉了,大概是网易云吧...不可能是咱!'

View file

@ -30,8 +30,10 @@ class Ans(StdAns):
if resp['data']['song']['totalnum'] == 0: if resp['data']['song']['totalnum'] == 0:
return '啊嘞嘞好像没有诶qaq' return '啊嘞嘞好像没有诶qaq'
mid = resp['data']['song']['list'][0]['mid'] mid = resp['data']['song']['list'][0]['mid']
mname = resp['data']['song']['list'][0]['name'] # id = resp['data']['song']['list'][0]['id']
msg = '[CQ:share,url=https://y.qq.com/n/yqq/song/' + str(mid) + '.html,title=' + str(mname) + ']' 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: except Exception as e:
print(e) print(e)
msg = '什么东西坏掉了,大概是疼讯吧...不可能是咱!' msg = '什么东西坏掉了,大概是疼讯吧...不可能是咱!'

84
worker/run.py Normal file
View file

@ -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 <lang>
<your code>
支持的语言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

41
worker/talk.py Normal file
View file

@ -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