diff --git a/modules/bilibili/__init__.py b/modules/bilibili/__init__.py index 04d813c2..854941e8 100644 --- a/modules/bilibili/__init__.py +++ b/modules/bilibili/__init__.py @@ -13,7 +13,7 @@ bili = module('bilibili', alias='bili', developers=['DoroWolf'], @bili.command(' [-i] {{bilibili.help}}', options_desc={'-i': '{bilibili.help.option.i}'}) -async def _(msg: Bot.MessageSession, bid: str, get_detail=False): +async def _(msg: Bot.MessageSession, bid: str, get_detail = False): if msg.parsed_msg.get('-i', False): get_detail = True if bid[:2].upper() == "BV": diff --git a/modules/meme/__init__.py b/modules/meme/__init__.py index 419bc4d3..a5b23522 100644 --- a/modules/meme/__init__.py +++ b/modules/meme/__init__.py @@ -25,9 +25,7 @@ async def _(msg: Bot.MessageSession, term: str): chk = await check(res_moegirl, res_nbnhhsh, res_urban) res = '' for i in chk: - if not i['status']: - i = '[???] ' + msg.locale.t('check.redacted') - res += i + '\n' - else: - res += i['content'] + '\n' - await msg.finish(res) + res += i['content'] + '\n' + res = res.replace("<吃掉了>", msg.locale.t("check.redacted")) + res = res.replace("<全部吃掉了>", msg.locale.t("check.redacted.all")) + await msg.finish(res.strip()) diff --git a/modules/meme/jiki.py b/modules/meme/jiki.py index 5083f43c..8b5e4101 100644 --- a/modules/meme/jiki.py +++ b/modules/meme/jiki.py @@ -1,5 +1,3 @@ -import traceback - from bs4 import BeautifulSoup from config import CFG @@ -40,5 +38,4 @@ async def jiki(term: str, locale: Locale): count = str(result) if results < 15 else '15+' return f'[{locale.t("meme.message.jiki")}] {locale.t("meme.message.result", result=count)}{title}\n{content}\n{str(Url(link))}' except Exception: - traceback.print_exc() return f'[{locale.t("meme.message.jiki")}] {locale.t("meme.message.error")}' diff --git a/modules/meme/nbnhhsh.py b/modules/meme/nbnhhsh.py index 6a63c121..a1c80765 100644 --- a/modules/meme/nbnhhsh.py +++ b/modules/meme/nbnhhsh.py @@ -1,5 +1,3 @@ -import traceback - import ujson as json from core.logger import Logger @@ -32,5 +30,4 @@ async def nbnhhsh(term: str, locale: Locale): else: return f'[{locale.t("meme.message.nbnhhsh")}] {locale.t("meme.message.not_found")}' except Exception: - traceback.print_exc() return f'[{locale.t("meme.message.nbnhhsh")}] {locale.t("meme.message.error")}' diff --git a/modules/meme/urban.py b/modules/meme/urban.py index 240d1594..f36567f4 100644 --- a/modules/meme/urban.py +++ b/modules/meme/urban.py @@ -1,5 +1,3 @@ -import traceback - import ujson as json from config import CFG @@ -41,7 +39,6 @@ async def urban(term: str, locale: Locale): link = data[0]['permalink'] return f'[{locale.t("meme.message.urban")}] {locale.t("meme.message.result", result=count)}\n{word}\n{definition}\nExample: {example}\n{str(Url(link))}' except Exception: - traceback.print_exc() return f'[{locale.t("meme.message.urban")}] {locale.t("meme.message.error")}' diff --git a/modules/tweet/__init__.py b/modules/tweet/__init__.py index efc65ceb..15236859 100644 --- a/modules/tweet/__init__.py +++ b/modules/tweet/__init__.py @@ -16,7 +16,6 @@ web_render_local = CFG.get_url('web_render_local') t = module('tweet', developers=['Dianliang233'], desc='{tweet.help.desc}', - exclude_from=['QQ', 'QQ|Group', 'Kook'], alias=['x'] ) diff --git a/modules/user/__init__.py b/modules/user/__init__.py index 439fa4e2..cc2159bc 100644 --- a/modules/user/__init__.py +++ b/modules/user/__init__.py @@ -5,11 +5,16 @@ from core.component import module from modules.wiki.utils.dbutils import WikiTargetInfo from .user import get_user_info -usr = module('user', developers=['OasisAkari'], recommend_modules='wiki') +usr = module('user', + developers=['OasisAkari'], + recommend_modules='wiki', + options_desc={'-r': '{user.help.option.r}') -@usr.command(' {{user.help.desc}}') -async def user(msg: Bot.MessageSession, username: str): +@usr.command(' [-r] {{user.help.desc}}') +async def user(msg: Bot.MessageSession, username: str, gp_mode = False): + if msg.parsed_msg.get('-r', False): + gp_mode = True target = WikiTargetInfo(msg) get_url = target.get_start_wiki() if get_url: @@ -17,8 +22,7 @@ async def user(msg: Bot.MessageSession, username: str): if match_interwiki: interwikis = target.get_interwikis() if match_interwiki.group(1) in interwikis: - return await msg.finish( - await get_user_info(msg, interwikis[match_interwiki.group(1)], match_interwiki.group(2))) - await msg.finish(await get_user_info(msg, get_url, username)) + await get_user_info(msg, interwikis[match_interwiki.group(1)], match_interwiki.group(2), gp_mode) + await get_user_info(msg, get_url, username, gp_mode) else: await msg.finish(msg.locale.t('wiki.message.not_set')) diff --git a/modules/user/locales/en_us.json b/modules/user/locales/en_us.json index a2e42778..a860bb4e 100644 --- a/modules/user/locales/en_us.json +++ b/modules/user/locales/en_us.json @@ -1,5 +1,6 @@ { "user.help.desc": "Get information about a MediaWiki user.", + "user.help.option.r": "Get extra information from Gamepedia site.", "user.message.blocked": "${user} is being blocked!", "user.message.blocked.detail": "Blocked by ${blocked_by}. Time from ${blocked_time} to ${blocked_expires}", "user.message.blocked.reason": "Reason: ", diff --git a/modules/user/locales/zh_cn.json b/modules/user/locales/zh_cn.json index a716e9e6..13bf98d6 100644 --- a/modules/user/locales/zh_cn.json +++ b/modules/user/locales/zh_cn.json @@ -1,5 +1,6 @@ { "user.help.desc": "获取一个 MediaWiki 用户的信息。", + "user.help.option.r": "获取来自 Gamepedia 网站的更多信息。", "user.message.blocked": "${user} 正在被封禁中!", "user.message.blocked.detail": "被 ${blocked_by} 封禁,时间从 ${blocked_time} 到 ${blocked_expires}", "user.message.blocked.reason": "理由:", @@ -24,4 +25,4 @@ "user.message.users_groups": "用户组:", "user.message.wiki_unavailable": "${wikiurl} 不可用。", "user.message.wikipoints": "Wikipoints:" -} +} \ No newline at end of file diff --git a/modules/user/locales/zh_tw.json b/modules/user/locales/zh_tw.json index 7e37bf78..07aeb185 100644 --- a/modules/user/locales/zh_tw.json +++ b/modules/user/locales/zh_tw.json @@ -1,5 +1,6 @@ { "user.help.desc": "取得一個 MediaWiki 使用者的資訊。", + "user.help.option.r": "取得來自 Gamepedia 網站的更多資訊。", "user.message.blocked": "${user} 正在被封鎖中!", "user.message.blocked.detail": "被 ${blocked_by} 封鎖,時間從 ${blocked_time} 到 ${blocked_expires}", "user.message.blocked.reason": "理由:", diff --git a/modules/user/user.py b/modules/user/user.py index ff905cee..c248bdd4 100644 --- a/modules/user/user.py +++ b/modules/user/user.py @@ -5,13 +5,14 @@ import urllib.parse from bs4 import BeautifulSoup as bs from core.builtins import Plain, MessageSession +from core.dirty_check import check_bool, rickroll from core.logger import Logger from core.utils.http import get_url from modules.wiki.utils.wikilib import WikiLib from modules.wiki.utils.time import strptime2ts -async def get_user_info(msg: MessageSession, wikiurl, username): +async def get_user_info(msg: MessageSession, wikiurl, username, gp_mode=False): wiki = WikiLib(wikiurl) if not await wiki.check_wiki_available(): return [Plain(msg.locale.t('user.message.wiki_unavailable', wikiurl=wikiurl))] @@ -20,7 +21,7 @@ async def get_user_info(msg: MessageSession, wikiurl, username): if match_interwiki: if match_interwiki.group(1) in wiki.wiki_info.interwiki: return await get_user_info(msg, wiki.wiki_info.interwiki[match_interwiki.group(1)], - match_interwiki.group(2)) + match_interwiki.group(2), gp_mode) data = {} base_user_info = (await wiki.get_json(action='query', list='users', ususers=username, usprop='groups|blockinfo|registration|editcount|gender'))['query']['users'][0] @@ -61,7 +62,7 @@ async def get_user_info(msg: MessageSession, wikiurl, username): data['gender'] = msg.locale.t('unknown') # if one day LGBTers... - try: + if gp_mode: gp_clawler = bs(await get_url(re.sub(r'\$1', 'UserProfile:' + username, wiki.wiki_info.articlepath), 200, logging_err_resp=False), 'html.parser') dd = gp_clawler.find('div', class_='section stats').find_all('dd') @@ -75,8 +76,7 @@ async def get_user_info(msg: MessageSession, wikiurl, username): data['friends_count'] = dd[7].text data['wikipoints'] = gp_clawler.find('div', class_='score').text data['url'] = re.sub(r'\$1', urllib.parse.quote('UserProfile:' + username), wiki.wiki_info.articlepath) - except ValueError: - pass + if 'blockedby' in base_user_info: data['blocked_by'] = base_user_info['blockedby'] data['blocked_time'] = base_user_info['blockedtimestamp'] @@ -161,5 +161,7 @@ async def get_user_info(msg: MessageSession, wikiurl, username): if url := data.get('url', False): msgs.append(url) - if msgs: - return [Plain('\n'.join(msgs))] + res = '\n'.join(msgs) + if await check_bool(res): + await msg.finish(rickroll(msg)) + await msg.finish(res) \ No newline at end of file diff --git a/modules/wiki/utils/wikilib.py b/modules/wiki/utils/wikilib.py index b130fc94..d5e9bb68 100644 --- a/modules/wiki/utils/wikilib.py +++ b/modules/wiki/utils/wikilib.py @@ -10,7 +10,7 @@ import ujson as json import core.utils.html2text as html2text from config import Config, CFG from core.builtins import Url -from core.dirty_check import check +from core.dirty_check import check_bool from core.logger import Logger from core.utils.http import get_url from core.utils.i18n import Locale, default_locale @@ -774,10 +774,8 @@ class WikiLib: checklist.append(page_info.before_title) if page_info.desc: checklist.append(page_info.desc) - chk = await check(*checklist) - for x in chk: - if not x['status']: - ban = True + if not await check_bool(*checklist) + ban = True if ban: page_info.status = False page_info.title = page_info.before_title = None