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_setting(update: Update, context: CallbackContext): chat_id = update.effective_chat.id lang = database.get_language_chat(chat_id) if not helpers.is_admin(context.bot, update.effective_user.id, update.effective_chat): update.effective_message.reply_text( get_string(lang, "no_admin_settings")) return user_id = update.effective_user.id user_lang = database.get_language_player(user_id) pm = database.get_pm_player(user_id) context.user_data["lang"] = user_lang database.insert_group_title(chat_id, update.effective_chat.title, update.effective_chat.link) if pm: try: # yes, its not a string, I don't change the functions name for this you f****r chat_link = helpers.chat_link(update.effective_chat.title, update.effective_chat.link) buttons = group_settings_helpers.group_settings_buttons( get_string(user_lang, "group_setting_buttons"), chat_id) context.bot.send_message( user_id, get_string(user_lang, "group_setting_text").format(chat_link), reply_markup=InlineKeyboardMarkup(buttons), parse_mode=ParseMode.HTML, disable_web_page_preview=True) # this means the bot was blocked wtf except Unauthorized: update.effective_message.reply_text( get_string(lang, "admin_blocked_bot")) database.insert_player_pm(user_id, False) else: button = [[ InlineKeyboardButton( get_string(lang, "no_pm_settings_button"), url=f"https://t.me/thechameleonbot?start=settings_{chat_id}") ]] update.effective_message.reply_text( get_string(lang, "no_pm_settings"), reply_markup=InlineKeyboardMarkup(button))
def nextgame_command(update: Update, context: CallbackContext): user_id = update.effective_user.id chat_id = update.effective_chat.id pm = database.get_pm_player(user_id) new = database.insert_group_nextgame(chat_id, user_id) if "lang" not in context.chat_data: context.chat_data["lang"] = database.get_language_chat(chat_id) lang = context.chat_data["lang"] chat_link = helpers.chat_link(update.effective_chat.title, update.effective_chat.link) database.insert_group_title(chat_id, update.effective_chat.title, update.effective_chat.link) if pm: try: 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) except Unauthorized: update.effective_message.reply_text( get_string(lang, "nextgame_block")) database.insert_player_pm(user_id, False) else: button = [[ InlineKeyboardButton( get_string(lang, "no_pm_settings_button"), url=f"https://t.me/thechameleonbot?start=nextgame_{chat_id}") ]] update.effective_message.reply_text( get_string(lang, "nextgame_pm"), reply_markup=InlineKeyboardMarkup(button))
def update_id(update, _): database.insert_group_title(update.effective_chat.id, update.new_chat_title)
def change_title(update: Update, _): chat_id = update.effective_chat.id title = update.effective_message.new_chat_title link = update.effective_chat.link database.insert_group_title(chat_id, title, link)