|
5 | 5 |
|
6 | 6 | from blackjackbot.commands.admin import notify_admins |
7 | 7 | from blackjackbot.commands.util.decorators import admin_method |
| 8 | +from blackjackbot.errors import NoActiveGameException |
| 9 | +from blackjackbot.gamestore import GameStore |
8 | 10 | from blackjackbot.lang import reload_strings, Translator |
9 | 11 | from database import Database |
10 | 12 |
|
11 | 13 | logger = logging.getLogger(__name__) |
12 | 14 |
|
13 | 15 |
|
| 16 | +@admin_method |
| 17 | +def kill_game_cmd(update, context): |
| 18 | + """Kills the game for a certain chat/group""" |
| 19 | + if len(context.args) == 0: |
| 20 | + update.message.reply_text("Please provide a chat_id!") |
| 21 | + |
| 22 | + chat_id = context.args[0] |
| 23 | + # Input validation for chat_id |
| 24 | + if not re.match(r"^-?[0-9]+$", chat_id): |
| 25 | + update.message.reply_text("Sorry, the chat_id is invalid!") |
| 26 | + return |
| 27 | + |
| 28 | + chat_id = int(chat_id) |
| 29 | + |
| 30 | + try: |
| 31 | + _ = GameStore().get_game(chat_id=chat_id) |
| 32 | + except NoActiveGameException: |
| 33 | + update.message.reply_text("Sorry, there is no running game in a chat with that ID!") |
| 34 | + return |
| 35 | + |
| 36 | + logger.info("Admin '{0}' removed game in chat '{1}'".format(update.effective_user.id, chat_id)) |
| 37 | + GameStore().remove_game(chat_id=chat_id) |
| 38 | + update.message.reply_text("Alright, I killed the running game in '{0}'!".format(chat_id)) |
| 39 | + context.bot.send_message(chat_id=chat_id, text="The creator of this bot stopped your current game of BlackJack.") |
| 40 | + |
| 41 | + |
14 | 42 | @admin_method |
15 | 43 | def reload_languages_cmd(update, context): |
16 | 44 | reload_strings() |
| 45 | + update.message.reply_text("Reloaded languages & strings!") |
17 | 46 |
|
18 | 47 |
|
19 | 48 | @admin_method |
@@ -48,7 +77,7 @@ def answer_comment_cmd(update, context): |
48 | 77 |
|
49 | 78 | chat_id = user[0] |
50 | 79 |
|
51 | | - if not re.match(r"^\d+$", chat_id): |
| 80 | + if not re.match(r"^-?\d+$", chat_id): |
52 | 81 | update.message.reply_text("⚠ Malformed chat_id!") |
53 | 82 | logger.error("Malformed chat_id: {}".format(chat_id)) |
54 | 83 | return |
|
0 commit comments