Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DoroWolf committed Jan 28, 2025
1 parent c9e5b6e commit 85be27d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions modules/wiki/utils/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async def get_user_info(msg: Bot.MessageSession, wikiurl, username):
wiki.wiki_info.interwiki[match_interwiki.group(1)],
match_interwiki.group(2),
)

data = {}
base_user_info = (
await wiki.get_json(
Expand All @@ -38,12 +39,14 @@ async def get_user_info(msg: Bot.MessageSession, wikiurl, username):
data["url"] = re.sub(
r"\$1", urllib.parse.quote("User:" + username), wiki.wiki_info.articlepath
)

groups = {}
get_groups = await wiki.get_json(
action="query", meta="allmessages", amprefix="group-"
)
for a in get_groups["query"]["allmessages"]:
groups[re.sub("^group-", "", a["name"])] = a["*"]

user_central_auth_data = {}
if "CentralAuth" in wiki.wiki_info.extensions:
user_central_auth_data = await wiki.get_json(
Expand All @@ -65,39 +68,40 @@ async def get_user_info(msg: Bot.MessageSession, wikiurl, username):
data["global_home"] = user_central_auth_data["query"]["globaluserinfo"]["home"]
for g in user_central_auth_data["query"]["globaluserinfo"]["groups"]:
data["global_users_groups"].append(groups[g] if g in groups else g)
data["registration_time"] = base_user_info["registration"]

data["registration_time"] = base_user_info.get("registration")
data["registration_time"] = (
msg.ts2strftime(strptime2ts(data["registration_time"]))
if data["registration_time"]
else msg.locale.t("message.unknown")
)
data["edited_count"] = str(base_user_info["editcount"])
data["gender"] = base_user_info["gender"]
data["edited_count"] = str(base_user_info.get("editcount"))
data["gender"] = base_user_info.get("gender")
if data["gender"] == "female":
data["gender"] = msg.locale.t("wiki.message.user.gender.female")
elif data["gender"] == "male":
data["gender"] = msg.locale.t("wiki.message.user.gender.male")
elif data["gender"] == "unknown":
else:
data["gender"] = msg.locale.t("message.unknown")
# if one day LGBTers...

if "blockedby" in base_user_info:
data["blocked_by"] = base_user_info["blockedby"]
data["blocked_time"] = base_user_info["blockedtimestamp"]
data["blocked_by"] = base_user_info.get("blockedby")
data["blocked_time"] = base_user_info.get("blockedtimestamp")
data["blocked_time"] = (
msg.ts2strftime(strptime2ts(data["blocked_time"]))
if data["blocked_time"]
else msg.locale.t("message.unknown")
)
data["blocked_expires"] = base_user_info.get("blockexpiry", None)
data["blocked_expires"] = base_user_info.get("blockexpiry")
if data["blocked_expires"]:
if data["blocked_expires"] != "infinite":
data["blocked_expires"] = msg.ts2strftime(
strptime2ts(data["blocked_expires"])
)
else:
data["blocked_expires"] = msg.locale.t("message.unknown")
data["blocked_reason"] = base_user_info["blockreason"]
data["blocked_reason"] = base_user_info.get("blockreason")
data["blocked_reason"] = (
data["blocked_reason"]
if data["blocked_reason"]
Expand Down

0 comments on commit 85be27d

Please sign in to comment.