def nextgame_start(update: Update, context: CallbackContext): user_id = update.effective_user.id database.insert_player_pm(user_id, True) context.args = context.args[0].split("_") if context.args else None if not context.args or context.args[0] != "nextgame": return try: chat_id = int(context.args[1]) new_id = database.get_new_id(chat_id) if new_id: chat_id = new_id lang = database.get_language_chat(chat_id) except ValueError: context.bot.send_message(user_id, get_string("en", "group_not_found")) return chat_details = database.get_group_title(chat_id) chat_link = helpers.chat_link(chat_details["title"], chat_details["link"]) new = database.insert_group_nextgame(chat_id, user_id) if new: context.bot.send_message(user_id, get_string( lang, "nextgame_added").format(chat_link), parse_mode=ParseMode.HTML, disable_web_page_preview=True) else: context.bot.send_message( user_id, get_string(lang, "nextgame_removed").format(chat_link), parse_mode=ParseMode.HTML, disable_web_page_preview=True)
def wrapper(*args, **kwargs): update = args[0] context = args[1] user_id = update.effective_user.id user_data = context.user_data if "lang" not in user_data: lang = database.get_language_player(user_id) user_data["lang"] = lang else: lang = user_data["lang"] query = update.callback_query chat_id = int(query.data.split("_")[1]) try: chat = context.bot.get_chat(chat_id) except BadRequest: new_chat_id = database.get_new_id(chat_id) if new_chat_id: chat = context.bot.get_chat(chat_id) else: query.edit_message_text(get_string(lang, "group_not_found")) return if not helpers.is_admin(context.bot, update.effective_user.id, chat): query.edit_message_text(get_string(lang, "no_admin_settings")) return return func(*args, **kwargs)
def start(update: Update, context: CallbackContext): user_id = update.effective_user.id database.insert_player_pm(user_id, True) user_data = context.user_data if "lang" not in user_data: lang = database.get_language_player(user_id) user_data["lang"] = lang else: lang = user_data["lang"] context.args = context.args[0].split("_") if context.args else None if not context.args or context.args[0] != "settings": return # not necessary, but pycharm won't believe me that... chat_id = 0 try: chat_id = int(context.args[1]) chat = context.bot.get_chat(chat_id) except ValueError: context.bot.send_message(user_id, get_string(lang, "group_not_found")) return except BadRequest: try: new_id = database.get_new_id(chat_id) if new_id: chat = context.bot.get_chat(int(new_id)) else: raise BadRequest except BadRequest: context.bot.send_message(user_id, get_string(lang, "group_not_found")) return database.insert_group_title(chat_id, chat.title, chat.link) if not helpers.is_admin(context.bot, update.effective_user.id, chat): update.effective_message.reply_text( get_string(lang, "no_admin_settings")) return buttons = group_settings_helpers.group_settings_buttons( get_string(lang, "group_setting_buttons"), chat_id) chat_link = helpers.chat_link(chat.title, chat.link) context.bot.send_message(user_id, get_string( lang, "group_setting_text").format(chat_link), reply_markup=InlineKeyboardMarkup(buttons), parse_mode=ParseMode.HTML, disable_web_page_preview=True)
def group_settings_buttons(settings, chat_id, ref=0): buttons = [] refresh_button = [] group_settings = database.get_all_settings(chat_id) if not group_settings: new_id = database.get_new_id(chat_id) if new_id: group_settings = database.get_all_settings(chat_id) else: return None for setting in settings: if setting == "language": buttons.append( InlineKeyboardButton( f"{settings[setting]}: {get_language(group_settings['lang'])}", callback_data= f"groupsettings_{str(chat_id)}_{setting}_{ref}")) elif setting == "deck": buttons.append( InlineKeyboardButton( f"{settings[setting]}: {group_settings['deck']}", callback_data= f"groupsettings_{str(chat_id)}_{setting}_{ref}")) elif setting == "refresh": refresh_button.append( InlineKeyboardButton( f"{settings[setting]} 🔄", callback_data= f"groupsettings_{str(chat_id)}_{setting}_{ref}")) elif group_settings[setting]: buttons.append( InlineKeyboardButton( f"{settings[setting]} ✅", callback_data= f"groupsettings_{str(chat_id)}_{setting}_{ref}")) else: buttons.append( InlineKeyboardButton( f"{settings[setting]} ❌", callback_data= f"groupsettings_{str(chat_id)}_{setting}_{ref}")) return build_menu(buttons, 2, header_buttons=refresh_button)