async def newbie(table, id): get_wiki_url = get_start_wiki(table, id) if get_wiki_url: url = get_wiki_url + '?action=query&list=logevents&letype=newusers&format=json' async with aiohttp.ClientSession() as session: async with session.get(url, timeout=aiohttp.ClientTimeout(total=20)) as req: if req.status != 200: return f"请求时发生错误:{req.status}" else: text1 = await req.text() file = json.loads(text1) d = [] for x in file['query']['logevents']: d.append(x['title']) print(str(d)) m = '\n'.join(d) y = await check([m]) print(str(y)) f = re.findall(r'.*\n.*\n.*\n.*\n.*', str(y)) g = '这是当前的新人列表:\n' + f[0] + '\n...仅显示前5条内容' if g.find('<吃掉了>') != -1 or g.find('<全部吃掉了>') != -1: return (g + '\n检测到外来信息介入,请前往日志查看所有消息。Special:日志?type=newusers') else: return (g)
async def main(kwargs: dict): command = re.sub('^user ', '', kwargs['trigger_msg']) commandsplit = command.split(' ') mode = None metaurl = None username = None if Group in kwargs: id = kwargs[Group].id if Friend in kwargs: id = kwargs[Friend].id if '-r' in commandsplit: mode = '-r' commandsplit.remove('-r') command = ' '.join(commandsplit) if '-p' in commandsplit: mode = '-p' commandsplit.remove('-p') command = ' '.join(commandsplit) match_gpsite = re.match(r'~(.*?) (.*)', command) if match_gpsite: metaurl = f'https://{match_gpsite.group(1)}.gamepedia.com/api.php' username = match_gpsite.group(2) else: match_interwiki = re.match(r'(.*?):(.*)', command) if match_interwiki: if Group in kwargs: table = 'custom_interwiki_group' if Friend in kwargs: table = 'custon_interwiki_self' get_iw = get_custom_interwiki(table, id, match_interwiki.group(1)) if get_iw: metaurl = get_iw username = match_interwiki.group(2) else: if Group in kwargs: table = 'start_wiki_link_group' if Friend in kwargs: table = 'start_wiki_link_self' get_url = get_start_wiki(table, id) if get_url: metaurl = get_url username = command else: await sendMessage(kwargs, '未设置起始Interwiki。') result = await GetUser(metaurl, username, mode) if result: matchimg = re.match('.*\[\[uimgc:(.*)]]', result) if matchimg: if Group in kwargs: mth = UploadMethods.Group if Friend in kwargs: mth = UploadMethods.Friend imgchain = MessageChain.create([Image.fromLocalFile(matchimg.group(1), method=mth)]) result = re.sub('\[\[uimgc:.*]]', '', result) msgchain = MessageChain.create([Plain(result)]) msgchain = msgchain.plusWith(imgchain) else: msgchain = MessageChain.create([Plain(result)]) await sendMessage(kwargs, msgchain)
async def rc(table, id): get_wiki_url = get_start_wiki(table, id) if get_wiki_url: url = get_wiki_url + '?action=query&list=recentchanges&rcprop=title|user|timestamp&rctype=edit|new&format=json' async with aiohttp.ClientSession() as session: async with session.get(url, timeout=aiohttp.ClientTimeout(total=20)) as req: if req.status != 200: return f"请求时发生错误:{req.status}" else: text1 = await req.text() file = json.loads(text1) d = [] for x in file['query']['recentchanges'][:5]: d.append(x['title'] + ' - ' + x['user'] + ' ' + UTC8(x['timestamp'], 'onlytime')) m = '\n'.join(d) print(m) y = await check([m]) print(y) if y.find('<吃掉了>') != -1 or y.find('<全部吃掉了>') != -1: msg = y + '\n...仅显示前5条内容\n检测到外来信息介入,请前往最近更改查看所有消息。Special:最近更改' else: msg = y + '\n...仅显示前5条内容' return msg else: return '未设定起始Wiki。'
async def ab(table, id): get_wiki_url = get_start_wiki(table, id) if get_wiki_url: url = get_wiki_url + '?action=query&list=abuselog&aflprop=user|title|action|result|filter|timestamp&format=json' async with aiohttp.ClientSession() as session: async with session.get( url, timeout=aiohttp.ClientTimeout(total=20)) as req: if req.status != 200: return f"请求时发生错误:{req.status}" else: text1 = await req.text() file = json.loads(text1) d = [] for x in file['query']['abuselog'][:5]: d.append('•' + x['title'] + ' - ' + x['user'] + '于' + UTC8(x['timestamp'], 'onlytimenoutc') + '\n过滤器名:' + x['filter'] + '\n处理结果:' + x['result']) y = await check(d) if y.find('<吃掉了>') != -1 or y.find('<全部吃掉了>') != -1: return y + '\n...仅显示前5条内容\n检测到外来信息介入,请前往滥用日志查看所有消息。Special:滥用日志\n[一分钟后撤回本消息]' else: return y + '\n...仅显示前5条内容\n[一分钟后撤回本消息]' else: return '未设定起始Wiki。'
async def regex_proc(kwargs: dict, display): mains = re.findall(r'\[\[(.*?)\]\]', display, re.I) templates = re.findall(r'\{\{(.*?)\}\}', display, re.I) find_dict = {} global_status = 'done' for main in mains: if main == '' or main in find_dict: pass else: find_dict.update({main: 'main'}) for template in templates: if template == '' or template in find_dict: pass else: find_dict.update({template: 'template'}) if find_dict != {}: waitlist = [] imglist = [] urllist = {} msglist = MessageChain.create([]) waitmsglist = MessageChain.create([]) if Group in kwargs: table = 'start_wiki_link_group' target = kwargs[Group].id mth = UploadMethods.Group if Friend in kwargs: table = 'start_wiki_link_self' target = kwargs[Friend].id mth = UploadMethods.Friend for find in find_dict: if find_dict[find] == 'template': template = True else: template = False get_link = database.get_start_wiki(table, target) if not get_link: if Group in kwargs: prompt = '没有指定起始Wiki,请管理员在群内发送~wiki_start_site <域名>来设定起始Wiki。\n例子:~wiki_start_site https://minecraft-zh.gamepedia.com/' if Friend in kwargs: prompt = '没有指定起始Wiki,请发送~wiki_start_site <域名>来设定起始Wiki。\n例子:~wiki_start_site https://minecraft-zh.gamepedia.com/' msg = {} msg['text'] = prompt status = 'done' else: iw = None matchinterwiki = re.match(r'(.*?):(.*)', find) if matchinterwiki: if Group in kwargs: iw_table = 'custom_interwiki_group' if Friend in kwargs: iw_table = 'custom_interwiki_self' get_custom_iw = modules.wiki.database.get_custom_interwiki( iw_table, target, matchinterwiki.group(1)) if get_custom_iw: get_link = get_custom_iw find = re.sub( matchinterwiki.group(1) + ':', '', find) iw = matchinterwiki.group(1) # fandom addon if matchinterwiki.group(1) == 'w': matchinterwiki = re.match(r'(.*?):(.*)', matchinterwiki.group(2)) if matchinterwiki: if matchinterwiki.group(1) == 'c': check_fandom_addon_enable = check_enable_modules( kwargs[Group].id, 'wiki_fandom_addon') if check_fandom_addon_enable: matchinterwiki = re.match( r'(.*?):(.*)', matchinterwiki.group(2)) if matchinterwiki: get_link = f'https://{matchinterwiki.group(1)}.fandom.com/api.php' find = matchinterwiki.group(2) iw = matchinterwiki.group(1) msg = await modules.wiki.wikilib.wikilib().main( get_link, find, interwiki=iw, template=template) status = msg['status'] if status == 'wait': global_status = 'wait' waitlist.append(msg['title']) waitmsglist = waitmsglist.plusWith( MessageChain.create([ Plain(('\n' if msglist != MessageChain.create([]) else '') + msg['text']) ])) if status == 'warn': global_status = 'warn' msglist = msglist.plusWith( MessageChain.create([ Plain(('\n' if msglist != MessageChain.create([]) else '') + msg['text']) ])) if status == 'done': msglist = msglist.plusWith( MessageChain.create([ Plain(('\n' if msglist != MessageChain.create([]) else '') + (msg['url'] + '\n' if 'url' in msg else '') + msg['text']) ])) if 'net_image' in msg: imglist.append(msg['net_image']) if 'apilink' in msg: get_link = msg['apilink'] if 'url' in msg: urllist.update({msg['url']: get_link}) if msglist != MessageChain.create([]): await sendMessage(kwargs, msglist) if imglist != []: imgchain = MessageChain.create([]) for img in imglist: imgchain = imgchain.plusWith( MessageChain.create( [Image.fromNetworkAddress(img, method=mth)])) await sendMessage(kwargs, imgchain) if urllist != {}: print(urllist) check_options = check_enable_modules_self( kwargs[Member].id if Group in kwargs else kwargs[Friend].id, 'wiki_infobox') if check_options: infoboxchain = MessageChain.create([]) for url in urllist: get_infobox = await get_infobox_pic(urllist[url], url) if get_infobox: infoboxchain = infoboxchain.plusWith( MessageChain.create([ Image.fromLocalFile(get_infobox, method=mth) ])) if infoboxchain != MessageChain.create([]): await sendMessage(kwargs, infoboxchain, Quote=False) if global_status == 'warn': if Group in kwargs: trigger = kwargs[Member].id if Friend in kwargs: trigger = kwargs[Friend].id warn_someone(trigger) if waitmsglist != MessageChain.create([]): send = await sendMessage(kwargs, waitmsglist) wait = await wait_confirm(kwargs) if wait: nwaitlist = [] for waits in waitlist: waits1 = f'[[{waits}]]' nwaitlist.append(waits1) await regex_proc(kwargs, '\n'.join(nwaitlist)) else: await revokeMessage(send)
async def wiki_loader(kwargs: dict): command = kwargs['trigger_msg'] command = re.sub(r'^wiki ', '', command) if Group in kwargs: start_table = 'start_wiki_link_group' if Friend in kwargs: start_table = 'start_wiki_link_self' get_link = database.get_start_wiki(start_table, kwargs[Group].id) if not get_link: if Group in kwargs: prompt = '没有指定起始Wiki,请管理员在群内发送~wiki_start_site <域名>来设定起始Wiki。\n例子:~wiki_start_site https://minecraft-zh.gamepedia.com/' if Friend in kwargs: prompt = '没有指定起始Wiki,请发送~wiki_start_site <域名>来设定起始Wiki。\n例子:~wiki_start_site https://minecraft-zh.gamepedia.com/' await sendMessage(kwargs, MessageChain.create([Plain(prompt)])) else: iw = None co = False if Group in kwargs: check_gamepedia_addon_enable = check_enable_modules( kwargs[Group].id, 'wiki_gamepedia_addon') if check_gamepedia_addon_enable: matchsite = re.match(r'~(.*?) (.*)', command) if matchsite: get_link = 'https://' + matchsite.group( 1) + '.gamepedia.com/api.php' iw = 'gp:' + matchsite.group(1) co = True command = matchsite.group(2) matchgp = re.match(r'^gp:(.*?):(.*)', command) if matchgp: get_link = 'https://' + matchgp.group( 1) + '.gamepedia.com/api.php' iw = 'gp:' + matchgp.group(1) co = True command = matchsite.group(2) print(co) matchinterwiki = re.match(r'(.*?):(.*)', command) if matchinterwiki and not co: if Group in kwargs: get_custom_iw = database.get_custom_interwiki( 'custom_interwiki_group', kwargs[Group].id, matchinterwiki.group(1)) if Friend in kwargs: get_custom_iw = database.get_custom_interwiki( 'custom_interwiki_self', kwargs[Friend].id, matchinterwiki.group(1)) if get_custom_iw: iw = matchinterwiki.group(1) get_link = get_custom_iw command = re.sub(matchinterwiki.group(1) + ':', '', command) msg = await wikilib.wikilib().main(get_link, command, interwiki=iw) if msg['status'] == 'done': msgchain = MessageChain.create([ Plain((msg['url'] + '\n' if 'url' in msg else '') + msg['text']) ]) if 'net_image' in msg: try: if Group in kwargs: mth = UploadMethods.Group elif Friend in kwargs: mth = UploadMethods.Friend imgchain = MessageChain.create([ Image.fromNetworkAddress(msg['net_image'], method=mth) ]) msgchain = msgchain.plusWith(imgchain) except: pass await sendMessage(kwargs, msgchain) if 'apilink' in msg: get_link = msg['apilink'] if 'url' in msg: check_options = check_enable_modules_self( kwargs[Member].id if Group in kwargs else kwargs[Friend].id, 'wiki_infobox') print(check_options) if check_options: pic = await get_infobox_pic(get_link, msg['url']) if Group in kwargs: mth = UploadMethods.Group elif Friend in kwargs: mth = UploadMethods.Friend imgchain = MessageChain.create( [Image.fromLocalFile(pic, method=mth)]) await sendMessage(kwargs, imgchain) elif msg['status'] == 'wait': await sendMessage(kwargs, MessageChain.create([Plain(msg['text'])])) wait = await wait_confirm(kwargs) if wait: msg = await wikilib.wikilib().main(get_link, msg['title']) await sendMessage(kwargs, MessageChain.create([Plain(msg['title'])])) elif msg['status'] == 'warn': if Group in kwargs: trigger = kwargs[Member].id if Friend in kwargs: trigger = kwargs[Friend].id warn_someone(trigger) await sendMessage(kwargs, MessageChain.create([Plain(msg['text'])]))