Special namespace supported
This commit is contained in:
parent
fb60d2f619
commit
25e855e0c3
5 changed files with 60 additions and 33 deletions
23
bot.py
23
bot.py
|
@ -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 pathexist(h):
|
||||
await app.sendGroupMessage(group, [Plain(Userp(h,h2)),Image.fromFileSystem("/home/oasisakari/botassests/usercard/"+h2+".png")])
|
||||
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('检测到此次为第一次访问该Wiki,下载资源可能会耗费一定的时间,请耐心等待。')])
|
||||
await app.sendGroupMessage(group, [Plain(Userp(h,h2)),Image.fromFileSystem("/home/oasisakari/botassests/usercard/"+h2+".png")])
|
||||
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 pathexist(h):
|
||||
await app.sendFriendMessage(friend, [Plain(Userp(h,h2)),Image.fromFileSystem("/home/oasisakari/botassests/usercard/"+h2+".png")])
|
||||
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(friend, [Plain('检测到此次为第一次访问该Wiki,下载资源可能会耗费一定的时间,请耐心等待。')])
|
||||
await app.sendFriendMessage(friend, [Plain(Userp(h,h2)),Image.fromFileSystem("/home/oasisakari/botassests/usercard/"+h2+".png")])
|
||||
await app.sendFriendMessage(group, [Plain('没有找到此用户。')])
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
|
||||
|
|
|
@ -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
11
userp/checkuser.py
Normal 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
|
35
wikim/m.py
35
wikim/m.py
|
@ -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,21 +19,25 @@ async def m(lang,str1):
|
|||
y = sorted(x.keys())[0]
|
||||
z = x[y]['fullurl']
|
||||
if int(y) == -1:
|
||||
try:
|
||||
if lang =='en':
|
||||
h = re.match(r'https://minecraft.gamepedia.com/(.*)', z, re.M | re.I)
|
||||
searchurl = 'https://minecraft.gamepedia.com/api.php?action=query&generator=search&gsrsearch='+h.group(1)+'&gsrsort=just_match&gsrenablerewrites&prop=info&gsrlimit=1&format=json'
|
||||
else:
|
||||
h = re.match(r'https://minecraft-(.*).gamepedia.com/(.*)', z, re.M | re.I)
|
||||
searchurl = 'https://minecraft-'+h.group(1)+'.gamepedia.com/api.php?action=query&generator=search&gsrsearch='+h.group(2)+'&gsrsort=just_match&gsrenablerewrites&prop=info&gsrlimit=1&format=json'
|
||||
f = requests.get(searchurl)
|
||||
g = json.loads(f.text)
|
||||
j=g['query']['pages']
|
||||
b = sorted(j.keys())[0]
|
||||
m = j[b]['title']
|
||||
return ('找不到条目,您是否要找的是:'+m+'?')
|
||||
except Exception:
|
||||
return('找不到条目。')
|
||||
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)
|
||||
searchurl = 'https://minecraft.gamepedia.com/api.php?action=query&generator=search&gsrsearch='+h.group(1)+'&gsrsort=just_match&gsrenablerewrites&prop=info&gsrlimit=1&format=json'
|
||||
else:
|
||||
h = re.match(r'https://minecraft-(.*).gamepedia.com/(.*)', z, re.M | re.I)
|
||||
searchurl = 'https://minecraft-'+h.group(1)+'.gamepedia.com/api.php?action=query&generator=search&gsrsearch='+h.group(2)+'&gsrsort=just_match&gsrenablerewrites&prop=info&gsrlimit=1&format=json'
|
||||
f = requests.get(searchurl)
|
||||
g = json.loads(f.text)
|
||||
j=g['query']['pages']
|
||||
b = sorted(j.keys())[0]
|
||||
m = j[b]['title']
|
||||
return ('找不到条目,您是否要找的是:'+m+'?')
|
||||
except Exception:
|
||||
return('找不到条目。')
|
||||
else:
|
||||
try:
|
||||
if lang =='en':
|
||||
|
|
|
@ -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,14 +12,18 @@ def Wiki(path1,pagename):
|
|||
z = x[y]['fullurl']
|
||||
if int(y) == -1:
|
||||
try:
|
||||
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)
|
||||
g = json.loads(f.text)
|
||||
j = g['query']['pages']
|
||||
b = sorted(j.keys())[0]
|
||||
m = j[b]['title']
|
||||
return ('找不到条目,您是否要找的是:' + m +'?')
|
||||
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)
|
||||
g = json.loads(f.text)
|
||||
j = g['query']['pages']
|
||||
b = sorted(j.keys())[0]
|
||||
m = j[b]['title']
|
||||
return ('找不到条目,您是否要找的是:' + m +'?')
|
||||
except Exception:
|
||||
return ('找不到条目。')
|
||||
else:
|
||||
|
|
Reference in a new issue