Archived
1
0
Fork 0

Special namespace supported

This commit is contained in:
yzhh 2020-06-15 19:27:34 +08:00
parent fb60d2f619
commit 25e855e0c3
5 changed files with 60 additions and 33 deletions

7
bot.py
View file

@ -17,6 +17,7 @@ from newbie import new
from newbee import newnew
from mcbv import mcbv
from mcdv import mcdv
from userp import checkuser
qq = 2052142661 # 字段 qq 的值
authKey = '1145141919810' # 字段 authKey 的值
mirai_api_http_locate = 'localhost:11919/ws' # httpapi所在主机的地址端口,如果 setting.yml 文件里字段 "enableWebsocket" 的值为 "true" 则需要将 "/" 换成 "/ws", 否则将接收不到消息.
@ -86,11 +87,14 @@ async def msg(app: Mirai, group: Group,member: Member, message: MessageChain):
h2 = re.sub('_', ' ', h2)
except Exception as e:
print(str(e))
if checkuser(h,h2) == True:
if pathexist(h):
await app.sendGroupMessage(group, [Plain(Userp(h,h2)),Image.fromFileSystem("/home/oasisakari/botassests/usercard/"+h2+".png")])
else:
await app.sendGroupMessage(group, [Plain('检测到此次为第一次访问该Wiki下载资源可能会耗费一定的时间请耐心等待。')])
await app.sendGroupMessage(group, [Plain(Userp(h,h2)),Image.fromFileSystem("/home/oasisakari/botassests/usercard/"+h2+".png")])
else:
await app.sendGroupMessage(group, [Plain('没有找到此用户。')])
except Exception as e:
print(str(e))
@ -162,11 +166,14 @@ async def msg(app: Mirai, friend: Friend, message: MessageChain):
h2 = re.sub('_', ' ', h2)
except Exception as e:
print(str(e))
if checkuser(h,h2) == True:
if pathexist(h):
await app.sendFriendMessage(friend, [Plain(Userp(h,h2)),Image.fromFileSystem("/home/oasisakari/botassests/usercard/"+h2+".png")])
else:
await app.sendFriendMessage(friend, [Plain('检测到此次为第一次访问该Wiki下载资源可能会耗费一定的时间请耐心等待。')])
await app.sendFriendMessage(friend, [Plain(Userp(h,h2)),Image.fromFileSystem("/home/oasisakari/botassests/usercard/"+h2+".png")])
else:
await app.sendFriendMessage(group, [Plain('没有找到此用户。')])
except Exception as e:
print(str(e))

View file

@ -39,6 +39,6 @@ def Userp(path,Username):
h = '/Userprofile:' +User
return(metaurl+urllib.parse.quote(h.encode('UTF-8')))
except Exception:
return ('没有找到此用户。')
return ('N')
except Exception as e:
return ('发生错误:'+str(e))

11
userp/checkuser.py Normal file
View file

@ -0,0 +1,11 @@
import requests
import json
async def checkuser(path,username):
url = 'https://'+path+'.gamepedia.com/api.php?action=query&list=users&ususers='+username+'&usprop=groups%7Cblockinfo%7Cregistration%7Ceditcount%7Cgender&format=json'
q = requests.get(url)
w = json.loads(q.text)
miss = file['query']['users'][0]['missing']
if not miss:
return True
else:
return False

View file

@ -3,6 +3,7 @@ import requests
import json
import re
import asyncio
import urllib
async def m(lang,str1):
if lang =='en':
metaurl = 'https://minecraft.gamepedia.com/api.php?action=query&format=json&prop=info&inprop=url&redirects&titles='
@ -18,6 +19,10 @@ async def m(lang,str1):
y = sorted(x.keys())[0]
z = x[y]['fullurl']
if int(y) == -1:
miss = x[y]['missing']
if not miss:
return ('您要的'+pagename+''+urllib.parse.quote(pagename.encode('UTF-8')))
else:
try:
if lang =='en':
h = re.match(r'https://minecraft.gamepedia.com/(.*)', z, re.M | re.I)

View file

@ -1,7 +1,7 @@
import json
import re
import requests
import urllib
def Wiki(path1,pagename):
metaurl = path1 +'/api.php?action=query&format=json&prop=info&inprop=url&redirects&titles=' + pagename
metatext = requests.get(metaurl, timeout=10)
@ -12,6 +12,10 @@ def Wiki(path1,pagename):
z = x[y]['fullurl']
if int(y) == -1:
try:
miss = x[y]['missing']
if not miss:
return ('您要的'+pagename+''+urllib.parse.quote(pagename.encode('UTF-8')))
else:
h = re.match(path1+r'/(.*)', z, re.M | re.I)
searchurl = path1+'/api.php?action=query&generator=search&gsrsearch=' + h.group(1) + '&gsrsort=just_match&gsrenablerewrites&prop=info&gsrlimit=1&format=json'
f = requests.get(searchurl)