This commit is contained in:
SiHuan 2020-02-28 22:58:14 +08:00
parent e37892e637
commit d3be48dd87
2 changed files with 33 additions and 2 deletions

10
test.py
View file

@ -1,4 +1,9 @@
from worker import emmm
debug = True
def de(e):
if debug:
print('DEBUG '+str(e))
print("开始测试咯,在 '>' 后面输入n你的消息不用加 '/'")
inp = input('>')
@ -9,9 +14,10 @@ while(inp):
try:
package = __import__(name='worker.'+ worker, fromlist=worker)
Ans_ = getattr(package,'Ans')
except:
except Exception as e:
# de(e)
Ans_ = emmm.Ans
# de(Ans_)
try:
Ans = Ans_(parms,uid=0,gid=0,role='owner',raw_msg={'message':'/' + inp})
Message = Ans.GETMSG()

25
worker/bing.py Normal file
View file

@ -0,0 +1,25 @@
from zzcore import StdAns
from config import BINGKEY
import requests
class Ans(StdAns):
def GETMSG(self):
if len(self.parms) < 2:
return '不加参数是坏文明!'
url = 'https://api.cognitive.microsoft.com/bing/v7.0/search'
params = {
'q':self.raw_msg['message'][5:],
'count': 1,
}
headers = {
'Ocp-Apim-Subscription-Key': BINGKEY,
}
try:
resp = requests.get(url=url,params=params,headers=headers).json()
result = resp['webPages']['value'][0]
msg = '咱帮你🔍到了这个\nTitle: ' + result['name']+'\nLink: '+result['displayUrl']+'\n'+result['snippet']
except:
msg = '什么东西坏掉了,大概是bing吧...不可能是咱!'
return msg