Skip to content

Commit 08285c8

Browse files
committed
upstream changes
1 parent 6345e86 commit 08285c8

File tree

4 files changed

+57
-16
lines changed

4 files changed

+57
-16
lines changed

bot/utils/msg_utils.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
from .log_utils import log, logger
2020

2121

22+
name_regex = "[^]]+"
23+
url_regex = "tg?://[^)]+"
24+
markup_regex = '\[(@{0})]\(\s*({1})\s*\)'.format(name_regex, url_regex)
25+
2226
def chat_is_allowed(event):
2327
if conf.ALLOWED_CHATS:
2428
return str(event.chat.id) in conf.ALLOWED_CHATS
@@ -27,6 +31,18 @@ def chat_is_allowed(event):
2731
return not bot.group_dict.get(str(event.chat.id), {}).get("disabled", False)
2832

2933

34+
def get_mention(string: str):
35+
if not string.startswith("@"):
36+
match = re.search(markup_regex, string)
37+
return match.groups(0)[1][13:] if match else None
38+
else:
39+
return string
40+
41+
42+
def is_mention(string: str):
43+
return bool(get_mention(string))
44+
45+
3046
def user_is_allowed(user: str | int):
3147
user = str(user)
3248
return not (
@@ -53,9 +69,9 @@ def user_is_sudoer(user: str | int):
5369
return bot.user_dict.get(user, {}).get("sudoer", False)
5470

5571

56-
async def get_user_info(user_name: str | int, id_only=False):
72+
async def get_user_info(user_id: str | int, id_only=False):
5773
try:
58-
user = await bot.client.get_users(user_name)
74+
user = await bot.client.get_users(user_id)
5975
return user.id if id_only else user
6076
except Exception:
6177
return

bot/workers/handlers/gi.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
chat_is_allowed,
3535
clean_reply,
3636
get_args,
37+
get_mention,
3738
get_msg_from_codes,
39+
get_user_info,
40+
is_mention,
3841
sanitize_text,
3942
user_is_allowed,
4043
user_is_privileged,
@@ -48,7 +51,7 @@ async def enka_handler(event, args, client):
4851
Requires character build for the specified uid to be public
4952
5053
Arguments:
51-
uid: {genshin player uid} (Required)
54+
uid/@mention: {genshin player uid} (Required)
5255
-c or --card or --character {character name}*: use quotes if the name has spaces eg:- "Hu tao"; Also supports lookups
5356
-cs or --cards or --characters {characters} same as -c but for multiple characters; delimited by commas
5457
-t <int> {template}: card generation template; currently only two templates exist; default 1
@@ -80,7 +83,7 @@ async def enka_handler(event, args, client):
8083
if not chat_is_allowed(event):
8184
return
8285
if not user_is_allowed(user):
83-
return await event.react("⛔")
86+
return
8487
try:
8588
arg, unknown = get_args(
8689
["--hide_uid", "store_true"],
@@ -111,11 +114,18 @@ async def enka_handler(event, args, client):
111114
)
112115
unknowns = unknown.split()
113116
invalid = str()
117+
mention = None
118+
mentioned_id = None
119+
r_mention = None
114120
uid = None
115121
for unkwn in unknowns:
116122
if unkwn.isdigit() and not uid:
117123
uid = unkwn
118124
continue
125+
elif (unkwn.startswith("@") or (unkwn.startswith("[@") and is_mention(unkwn))) and not mention:
126+
mention = get_mention(unkwn)
127+
r_mention = unkwn
128+
continue
119129
invalid += f"{unkwn} "
120130
invalid = invalid.rstrip()
121131
card = arg.c or arg.card or arg.character
@@ -135,6 +145,14 @@ async def enka_handler(event, args, client):
135145
if not vital_args:
136146
return await u_reply.edit("Updated enka assets.")
137147
await u_reply.delete()
148+
if mention and uid:
149+
await event.reply("`Ignoring your mention…`")
150+
elif mention:
151+
mentioned = await get_user_info(mention)
152+
not_found_err = "**No idea who {} is.**"
153+
if not mentioned:
154+
return await event.reply(not_found_err.format(r_mention))
155+
mentioned_id = mentioned.id
138156
if uid and save:
139157
will_save = True
140158
if bot.user_dict.get(user, {}).get("genshin_uid") == uid:
@@ -151,7 +169,7 @@ async def enka_handler(event, args, client):
151169
if not vital_args:
152170
return
153171
if not uid:
154-
uid = bot.user_dict.get(user, {}).get("genshin_uid", None)
172+
uid = bot.user_dict.get((mentioned_id or user), {}).get("genshin_uid", None)
155173
if delete:
156174
if not (saved_uid := bot.user_dict.get(user, {}).get("genshin_uid")):
157175
await event.reply("**No saved uid was found to delete!**")
@@ -166,7 +184,11 @@ async def enka_handler(event, args, client):
166184
if not uid:
167185
if invalid:
168186
await event.reply(f"`{invalid}`?")
169-
return await event.reply(f"**Please supply a UID**")
187+
if mention:
188+
err_msg = f"**Error:** {mentioned.mention()} hasn't saved their uid!"
189+
else:
190+
err_msg = "**Please supply a UID**"
191+
return await event.reply(err_msg)
170192
if invalid:
171193
await event.reply(f"**Warning:** No idea what '`{invalid}`' means.")
172194
if arg.t not in ("1", "2"):
@@ -180,7 +202,10 @@ async def enka_handler(event, args, client):
180202
await event.reply(characters)
181203
if not (card or cards or dump or prof):
182204
return
183-
status = await event.reply("`Fetching card(s), Please Wait…`")
205+
status_msg = "`Fetching card(s)"
206+
status_msg += f" for {mentioned.first_name}" if mention else str()
207+
status_msg += ", Please Wait…`"
208+
status = await event.reply(status_msg)
184209
if prof:
185210
cprofile, error = (
186211
await get_enka_profile(uid, card=True, template=arg.t, huid=hide_uid)

bot/workers/handlers/manage.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,15 @@ async def ban(event, args, client):
490490
if user_is_owner(ban_id):
491491
return await event.reply("**Why?**")
492492
if user_is_sudoer(ban_id):
493-
return await event.reply(f"@{ban_info.mention()} **is a Sudoer.**")
493+
return await event.reply(f"{ban_info.mention()} **is a Sudoer.**")
494494
if not user_is_allowed(ban_id):
495495
return await event.reply(
496496
f"@{ban_info.mention()} **has already been banned from using the bot.**"
497497
)
498498
bot.user_dict.setdefault(ban_id, {}).update(banned=True)
499499
await save2db2(bot.user_dict, "users")
500500
return await event.reply(
501-
f"@{ban_info.mention()} **has been banned from using the bot.**"
501+
f"{ban_info.mention()} **has been banned from using the bot.**"
502502
)
503503
except Exception:
504504
await logger(Exception)
@@ -531,14 +531,14 @@ async def unban(event, args, client):
531531
if user_is_owner(ban_id):
532532
return await event.reply("**Why?**")
533533
if user_is_sudoer(ban_id):
534-
return await event.reply(f"@{ban_info.mention()} **is a Sudoer.**")
534+
return await event.reply(f"{ban_info.mention()} **is a Sudoer.**")
535535
if user_is_allowed(ban_id):
536536
return await event.reply(
537-
f"@{ban_info.mention()} **was never banned from using the bot.**"
537+
f"{ban_info.mention()} **was never banned from using the bot.**"
538538
)
539539
bot.user_dict.setdefault(ban_id, {}).update(banned=False)
540540
await save2db2(bot.user_dict, "users")
541-
return await event.reply(f"@{ban_info.mention()}'s *ban has been lifted.*")
541+
return await event.reply(f"{ban_info.mention()}'s *ban has been lifted.*")
542542
except Exception:
543543
await logger(Exception)
544544

@@ -652,15 +652,15 @@ async def sudoers(event, args, client):
652652
return await event.reply("**Why?**")
653653
if arg.a:
654654
if user_is_sudoer(_id):
655-
return await event.reply(f"@{_info.mention()} **is already a Sudoer.**")
655+
return await event.reply(f"{_info.mention()} **is already a Sudoer.**")
656656
bot.user_dict.setdefault(_id, {}).update(sudoer=True)
657657
if arg.rm:
658658
if not user_is_sudoer(_id):
659-
return await event.reply(f"@{_id} **is not a Sudoer.**")
659+
return await event.reply(f"{_id} **is not a Sudoer.**")
660660
bot.user_dict.setdefault(_id, {}).update(sudoer=False)
661661
await save2db2(bot.user_dict, "users")
662662
await event.reply(
663-
f"@{_id} **has been successfully {'added to' if arg.a else 'removed from'} sudoers.**"
663+
f"{_id} **has been successfully {'added to' if arg.a else 'removed from'} sudoers.**"
664664
)
665665
except Exception:
666666
await logger(Exception)

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.4.0-alpha
1+
v0.4.1-alpha

0 commit comments

Comments
 (0)