def query_game(bot, update): """Handler for the /query command""" chat = update.message.chat if update.message.chat.type == 'private': help_handler(bot, update) return try: game = gm.query_game(update.message.from_user, chat) except NoGameInChatError: send_async(bot, chat.id, text=_("No game is running at the moment. " "Create a new game with /new"), reply_to_message_id=update.message.message_id) except LobbyNotStartedError: send_async( bot, chat.id, text=_("The game is not started yet. " "Join the game with /join and start the game with /start"), reply_to_message_id=update.message.message_id) else: send_async(bot, chat.id, text=game_info_str(game), reply_to_message_id=update.message.message_id)
def new_game(bot, update): """Handler for the /new command""" chat_id = update.message.chat_id if update.message.chat.type == 'private': help_handler(bot, update) else: if update.message.chat_id in gm.remind_dict: for user in gm.remind_dict[update.message.chat_id]: send_async( bot, user, text=_("A new game has been started in {title}").format( title=update.message.chat.title)) del gm.remind_dict[update.message.chat_id] game = gm.new_game(update.message.chat) game.starter = update.message.from_user game.owner.append(update.message.from_user.id) game.mode = DEFAULT_GAMEMODE send_async(bot, chat_id, text=_("Created a new game! Join the game with /join " "and start the game with /start"))
def kill_game(bot, update): """Handler for the /kill command""" chat = update.message.chat user = update.message.from_user games = gm.chatid_games.get(chat.id) if update.message.chat.type == 'private': help_handler(bot, update) return if not games: send_async(bot, chat.id, text=_("There is no running game in this chat.")) return game = games[-1] if user_is_creator_or_admin(user, game, bot, chat): try: gm.end_game(chat, user) send_async(bot, chat.id, text=__("Game ended!", multi=game.translate)) except NoGameInChatError: send_async(bot, chat.id, text=_("The game is not started yet. " "Join the game with /join and start the game with /start"), reply_to_message_id=update.message.message_id) else: send_async(bot, chat.id, text=_("Only the game creator ({name}) and admin can do that.") .format(name=game.starter.first_name), reply_to_message_id=update.message.message_id)
def new_game(bot, update): """Handler for the /new command""" chat_id = update.message.chat_id if update.message.chat.type == 'private': help_handler(bot, update) else: if not chat_id in ALLOWED_GROUPS: send_async(bot, chat_id, text=_("Silakan main di @sumbarmaota! Bye 💋")) time.sleep(3) bot.leave_chat(chat_id) else: if update.message.chat_id in gm.remind_dict: for user in gm.remind_dict[update.message.chat_id]: send_async( bot, user, text=_("A new game has been started in {title}" ).format(title=update.message.chat.title)) del gm.remind_dict[update.message.chat_id] game = gm.new_game(update.message.chat) game.starter = update.message.from_user game.owner.append(update.message.from_user.id) game.mode = DEFAULT_GAMEMODE send_async(bot, chat_id, text=_("Created a new game! Join the game with /join " "and start the game with /start"))
def join_game(bot, update): """Handler for the /join command""" choice = [[ InlineKeyboardButton(text=_("Choose the mode!"), switch_inline_query_current_chat='') ]] user = update.message.from_user chat = update.message.chat games = gm.chatid_games.get(chat.id) game = games[-1] if update.message.chat.type == 'private': help_handler(bot, update) return try: gm.join_game(update.message.from_user, chat) except LobbyClosedError: send_async(bot, chat.id, text=_("The lobby is closed")) except NoGameInChatError: send_async(bot, chat.id, text=_("No game is running at the moment. " "Create a new game with /new"), reply_to_message_id=update.message.message_id) except AlreadyJoinedError: send_async(bot, chat.id, text=_("You already joined the game. Start the game " "with /start"), reply_to_message_id=update.message.message_id) except DeckEmptyError: send_async(bot, chat.id, text=_("There are not enough cards left in the deck for " "new players to join."), reply_to_message_id=update.message.message_id) else: if user.id in game.owner: send_async(bot, chat.id, text=_("Joined the game"), reply_markup=InlineKeyboardMarkup(choice), reply_to_message_id=update.message.message_id) if user.id not in game.owner: send_async(bot, chat.id, text=_("Joined the game"), reply_to_message_id=update.message.message_id)
def join_game(bot, update): #Start DB us = UserSetting.get(id=update.message.from_user.id) if not us: us = UserSetting(id=update.message.from_user.id) #Start DB """Handler for the /join command""" chat = update.message.chat if update.message.chat.type == 'private': help_handler(bot, update) return try: gm.join_game(update.message.from_user, chat) except LobbyClosedError: send_async(bot, chat.id, text=_("The lobby is closed")) except NoGameInChatError: send_async(bot, chat.id, text=_("No game is running at the moment. " "Create a new game with /new"), reply_to_message_id=update.message.message_id) except AlreadyJoinedError: send_async(bot, chat.id, text=_("You already joined the game. Start the game " "with /start"), reply_to_message_id=update.message.message_id) except DeckEmptyError: send_async(bot, chat.id, text=_("There are not enough cards left in the deck for " "new players to join."), reply_to_message_id=update.message.message_id) else: send_async(bot, chat.id, text=_("Joined the game"), reply_to_message_id=update.message.message_id)
def join_game(bot, update): """Handler for the /join command""" chat = update.message.chat if update.message.chat.type == 'private': help_handler(bot, update) return try: gm.join_game(update.message.from_user, chat) except LobbyClosedError: send_async(bot, chat.id, text="Abe bhag bihari", reply_to_message_id=update.message.message_id) except NoGameInChatError: send_async(bot, chat.id, text=_("kardi jatin bihari pruthi wali baat " "Naya game bana /new"), reply_to_message_id=update.message.message_id) except AlreadyJoinedError: send_async(bot, chat.id, text=_("kardi bihari wali baat, start kar aise /start"), reply_to_message_id=update.message.message_id) except DeckEmptyError: send_async(bot, chat.id, text=_("There are not enough cards left in the deck for " "new players to join."), reply_to_message_id=update.message.message_id) else: send_async(bot, chat.id, text=_("Has entered bihar"), reply_to_message_id=update.message.message_id)
def kill_game(bot, update): """Handler for the /kill command""" chat = update.message.chat user = update.message.from_user games = gm.chatid_games.get(chat.id) if update.message.chat.type == 'private': help_handler(bot, update) return if not games: send_async(bot, chat.id, text="Abe Bihari Game hi chalu nahi :|") return game = games[-1] if user_is_creator_or_admin(user, game, bot, chat): try: gm.end_game(chat, user) send_async(bot, chat.id, text=__("chalo hogaya aaj ka, back to bihar.", multi=game.translate)) except NoGameInChatError: send_async( bot, chat.id, text=_( "Kardi na bihari wali baat " "Join the game with /join and start the game with /start"), reply_to_message_id=update.message.message_id) else: send_async( bot, chat.id, text=_("Only the game creator ({name}) and admin can do that." ).format(name=game.starter.first_name), reply_to_message_id=update.message.message_id)
def start_game(bot, update, args, job_queue): """Handler for the /start command""" if update.message.chat.type != 'private': chat = update.message.chat try: game = gm.chatid_games[chat.id][-1] except (KeyError, IndexError): send_async(bot, chat.id, text=_("There is no game running in this chat. Create " "a new one with /new")) return if game.started: send_async(bot, chat.id, text=_("The game has already started")) elif len(game.players) < MIN_PLAYERS: send_async( bot, chat.id, text=__( "At least {minplayers} players must /join the game " "before you can start it").format(minplayers=MIN_PLAYERS)) else: # Set winning score player_num = len(game.players) if player_num == 2: game.win_score = SCORE_DUEL else: game.win_score = ADDITIONAL_POINT * player_num # Starting a game game.start() for player in game.players: player.draw_first_hand() first_message = (__( "First player: {name}\n" "Use /close to stop people from joining the game.\n" "Enable multi-translations with /enable_translations", multi=game.translate).format( name=display_name(game.current_player.user))) @run_async def send_first(): """Send the first card and player""" bot.sendSticker(chat.id, sticker=c.STICKERS[str(game.last_card)], timeout=TIMEOUT) bot.sendMessage(chat.id, text=first_message, timeout=TIMEOUT) send_first() start_player_countdown(bot, game, job_queue) elif len(args) and args[0] == 'select': players = gm.userid_players[update.message.from_user.id] groups = list() for player in players: title = player.game.chat.title if player is gm.userid_current[update.message.from_user.id]: title = '- %s -' % player.game.chat.title groups.append([ InlineKeyboardButton(text=title, callback_data=str(player.game.chat.id)) ]) send_async(bot, update.message.chat_id, text=_('Please select the group you want to play in.'), reply_markup=InlineKeyboardMarkup(groups)) else: help_handler(bot, update)
def kick_player(bot, update): """Handler for the /kick command""" if update.message.chat.type == 'private': help_handler(bot, update) return chat = update.message.chat user = update.message.from_user try: game = gm.chatid_games[chat.id][-1] except (KeyError, IndexError): send_async(bot, chat.id, text=_("No game is running at the moment. " "Create a new game with /new"), reply_to_message_id=update.message.message_id) return if not game.started: send_async( bot, chat.id, text=_("The game is not started yet. " "Join the game with /join and start the game with /start"), reply_to_message_id=update.message.message_id) return if user_is_creator_or_admin(user, game, bot, chat): if update.message.reply_to_message: kicked = update.message.reply_to_message.from_user try: gm.leave_game(kicked, chat) except NoGameInChatError: send_async( bot, chat.id, text=_("Player {name} is not found in the current game.". format(name=display_name(kicked))), reply_to_message_id=update.message.message_id) return except NotEnoughPlayersError: gm.end_game(chat, user) send_async(bot, chat.id, text=_("{0} was kicked by {1}".format( display_name(kicked), display_name(user)))) send_async(bot, chat.id, text=__("Game ended!", multi=game.translate)) return send_async(bot, chat.id, text=_("{0} was kicked by {1}".format( display_name(kicked), display_name(user)))) else: send_async( bot, chat.id, text= _("Please reply to the person you want to kick and type /kick again." ), reply_to_message_id=update.message.message_id) return send_async(bot, chat.id, text=__("Okay. Next Player: {name}", multi=game.translate).format( name=display_name(game.current_player.user)), reply_to_message_id=update.message.message_id) else: send_async( bot, chat.id, text=_("Only the game creator ({name}) and admin can do that." ).format(name=game.starter.first_name), reply_to_message_id=update.message.message_id)
def kick_player(bot, update): """Handler for the /kick command""" if update.message.chat.type == 'private': help_handler(bot, update) return chat = update.message.chat user = update.message.from_user try: game = gm.chatid_games[chat.id][-1] except (KeyError, IndexError): send_async(bot, chat.id, text=_("kardi jatin bihari pruthi wali baat " "Naya game bana /new "), reply_to_message_id=update.message.message_id) return if not game.started: send_async( bot, chat.id, text=_( "kardi bihari wali baat, /join karke start kar aise /start "), reply_to_message_id=update.message.message_id) return if user_is_creator_or_admin(user, game, bot, chat): if update.message.reply_to_message: kicked = update.message.reply_to_message.from_user try: gm.leave_game(kicked, chat) except NoGameInChatError: send_async( bot, chat.id, text=_("Player {name} is not found in the current game.". format(name=display_name(kicked))), reply_to_message_id=update.message.message_id) return except NotEnoughPlayersError: gm.end_game(chat, user) send_async(bot, chat.id, text=_("{0} was kicked by {1}".format( display_name(kicked), display_name(user)))) send_async(bot, chat.id, text=__("chalo hogaya aaj ka, back to bihar.", multi=game.translate)) return send_async(bot, chat.id, text="{1} ne {0} ko bihar bhej diya".format( display_name(kicked), display_name(user))) else: send_async( bot, chat.id, text= _("Please reply to the person you want to kick and type /kick again." ), reply_to_message_id=update.message.message_id) return send_async(bot, chat.id, text="Okay. Agla Bihari: {name}".format( name=display_name(me.current_player.user)), reply_to_message_id=update.message.message_id) else: send_async( bot, chat.id, text=_("Only the game creator ({name}) and admin can do that." ).format(name=game.starter.first_name), reply_to_message_id=update.message.message_id)