Skip to content

Commit f5ac09b

Browse files
committed
fix: improve ban/unban commands
1 parent 73845b5 commit f5ac09b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

blackjackbot/commands/admin/commands.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,48 @@
1818
@admin_method
1919
def ban_user_cmd(update, context):
2020
"""Bans a user from using the bot"""
21+
usage_message = r"Please provide a valid userid\. Usage: `/ban <userid>`"
2122
# Try to get user_id from command
2223
if len(context.args) != 1:
23-
update.message.reply_text("Please provide a valid user_id - `/ban <user_id>`", parse_mode=ParseMode.MARKDOWN_V2)
24+
update.effective_message.reply_text(usage_message, parse_mode=ParseMode.MARKDOWN_V2)
2425
return
2526

2627
match = re.search(r"^\d+$", context.args[0])
2728
if not match:
28-
logger.error(f"The user_id did not match: {context.args}")
29+
logger.error(f"The user_id did not match. Args: {context.args}")
30+
update.effective_message.reply_text(usage_message, parse_mode=ParseMode.MARKDOWN_V2)
2931
return
3032
user_id = match.group(0)
3133

3234
db = Database()
3335
db.ban_user(user_id=user_id)
3436

3537
logger.info(f"Admin '{update.effective_user.id}' banned user '{user_id}'!")
36-
notify_admins(f"Admin '{update.effective_user.id}' banned user '{user_id}'!")
38+
notify_admins(f"Admin '{update.effective_user.id}' banned user '{user_id}'!", context)
3739

3840

3941
@admin_method
4042
def unban_user_cmd(update, context):
4143
"""Unbans a user from using the bot"""
44+
usage_message = r"Please provide a valid userid\. Usage: `/unban <userid>`"
45+
4246
# Try to get user_id from command
4347
if len(context.args) != 1:
44-
update.message.reply_text("Please provide a valid user_id - `/unban <user_id>`", parse_mode=ParseMode.MARKDOWN_V2)
48+
update.message.reply_text(usage_message, parse_mode=ParseMode.MARKDOWN_V2)
4549
return
4650

4751
match = re.search(r"^\d+$", context.args[0])
4852
if not match:
49-
logger.error(f"The user_id did not match: {context.args}")
53+
logger.error(f"The user_id did not match. Args: {context.args}")
54+
update.effective_message.reply_text(usage_message, parse_mode=ParseMode.MARKDOWN_V2)
5055
return
5156
user_id = match.group(0)
5257

5358
db = Database()
5459
db.unban_user(user_id=user_id)
5560

5661
logger.info(f"Admin '{update.effective_user.id}' unbanned user '{user_id}'!")
57-
notify_admins(f"Admin '{update.effective_user.id}' unbanned user '{user_id}'!")
62+
notify_admins(f"Admin '{update.effective_user.id}' unbanned user '{user_id}'!", context)
5863

5964

6065
@admin_method

0 commit comments

Comments
 (0)