def get_help(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] args = update.effective_message.text.split(None, 1) # ONLY send help in PM if chat.type != chat.PRIVATE: update.effective_message.reply_text("Contact me in PM to get the list of possible commands.", reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton(text="Help", url="t.me/{}?start=help".format( bot.username))]])) return elif len(args) >= 2 and any(args[1].lower() == x for x in HELPABLE): module = args[1].lower() mod_name = tld(chat.id, HELPABLE[module].__mod_name__) help_txt = tld_help(chat.id, HELPABLE[module].__mod_name__) if help_txt == False: help_txt = HELPABLE[module].__help__ text = tld(chat.id, "Here is the help for the *{}* module:\n{}").format(mod_name, help_txt) send_help(chat.id, text, InlineKeyboardMarkup([[InlineKeyboardButton(text=tld(chat.id, "Back"), callback_data="help_back")]])) else: send_help(chat.id, tld(chat.id, "send-help").format(dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld( chat.id, "\nAll commands can either be used with `/` or `!`.\n" )))
def start(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] #query = update.callback_query #Unused variable if update.effective_chat.type == "private": if len(args) >= 1: if args[0].lower() == "help": send_help(update.effective_chat.id, tld(chat.id, "send-help").format( dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld( chat.id, "\nAll commands can either be used with `/` or `!`.\n" ))) elif args[0].lower().startswith("stngs_"): match = re.match("stngs_(.*)", args[0].lower()) chat = dispatcher.bot.getChat(match.group(1)) if is_user_admin(chat, update.effective_user.id): send_settings(match.group(1), update.effective_user.id, update, user=False) else: send_settings(match.group(1), update.effective_user.id, update, user=True) elif args[0][1:].isdigit() and "rules" in IMPORTED: IMPORTED["rules"].send_rules(update, args[0], from_pm=True) elif args[0].lower() == "controlpanel": control_panel(bot, update) else: send_start(bot, update) else: try: update.effective_message.reply_text("Hey there! I'm alive :3") except: print("Nut")
def get_id(bot: Bot, update: Update, args: List[str]): user_id = extract_user(update.effective_message, args) chat = update.effective_chat # type: Optional[Chat] if user_id: if update.effective_message.reply_to_message and update.effective_message.reply_to_message.forward_from: user1 = update.effective_message.reply_to_message.from_user user2 = update.effective_message.reply_to_message.forward_from update.effective_message.reply_text(tld(chat.id, "The original sender, {}, has an ID of `{}`.\nThe forwarder, {}, has an ID of `{}`.").format( escape_markdown(user2.first_name), user2.id, escape_markdown(user1.first_name), user1.id), parse_mode=ParseMode.MARKDOWN) else: user = bot.get_chat(user_id) update.effective_message.reply_text(tld(chat.id, "{}'s id is `{}`.").format(escape_markdown(user.first_name), user.id), parse_mode=ParseMode.MARKDOWN) else: chat = update.effective_chat # type: Optional[Chat] if chat.type == "private": update.effective_message.reply_text(tld(chat.id, "Your id is `{}`.").format(chat.id), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text(tld(chat.id, "This group's id is `{}`.").format(chat.id), parse_mode=ParseMode.MARKDOWN)
def markdown_help(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] update.effective_message.reply_text(tld(chat.id, "MARKDOWN_HELP-K"), parse_mode=ParseMode.HTML) update.effective_message.reply_text(tld(chat.id, "Try forwarding the following message to me, and you'll see!")) update.effective_message.reply_text(tld(chat.id, "/save test This is a markdown test. _italics_, *bold*, `code`, " "[URL](example.com) [button](buttonurl:github.com) " "[button2](buttonurl://google.com:same)"))
def __user_info__(user_id, chat_id): if user_id == dispatcher.bot.id: return tld( chat_id, "I've seen them in... Wow. Are they stalking me? They're in all the same places I am... oh. It's me." ) num_chats = sql.get_user_num_chats(user_id) return tld( chat_id, "I've seen them in <code>{}</code> chats in total.").format(num_chats)
def check_afk(bot, update, user_id, fst_name): chat = update.effective_chat # type: Optional[Chat] if sql.is_afk(user_id): user = sql.check_afk_status(user_id) if not user.reason: res = tld(chat.id, f"{fst_name} is AFK!") else: res = tld( chat.id, f"{fst_name} is AFK! says its because of:\n{user.reason}") update.effective_message.reply_text(res)
def flood(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] limit = sql.get_flood_limit(chat.id) if limit == 0: update.effective_message.reply_text( tld(chat.id, "I'm not currently enforcing flood control!")) else: update.effective_message.reply_text( tld( chat.id, "I'm currently muting users if they send more than {} consecutive messages." ).format(limit))
def set_flood(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] if len(args) >= 1: val = args[0].lower() if val == "off" or val == "no" or val == "0": sql.set_flood(chat.id, 0) message.reply_text(tld(chat.id, "Antiflood has been disabled.")) elif val.isdigit(): amount = int(val) if amount <= 0: sql.set_flood(chat.id, 0) message.reply_text(tld(chat.id, "Antiflood has been disabled.")) return "<b>{}:</b>" \ "\n#SETFLOOD" \ "\n<b>Admin:</b> {}" \ "\nDisabled antiflood.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) elif amount < 3: message.reply_text( tld( chat.id, "Antiflood has to be either 0 (disabled), or a number bigger than 3 (enabled)!" )) return "" else: sql.set_flood(chat.id, amount) message.reply_text( tld(chat.id, "Antiflood has been updated and set to {}").format( amount)) return "<b>{}:</b>" \ "\n#SETFLOOD" \ "\n<b>Admin:</b> {}" \ "\nSet antiflood to <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), amount) else: message.reply_text( tld( chat.id, "Unrecognized argument - please use a number, 'off', or 'no'." )) return ""
def help_button(bot: Bot, update: Update): query = update.callback_query chat = update.effective_chat # type: Optional[Chat] mod_match = re.match(r"help_module\((.+?)\)", query.data) prev_match = re.match(r"help_prev\((.+?)\)", query.data) next_match = re.match(r"help_next\((.+?)\)", query.data) back_match = re.match(r"help_back", query.data) try: if mod_match: module = mod_match.group(1) mod_name = tld(chat.id, HELPABLE[module].__mod_name__) help_txt = tld_help(chat.id, HELPABLE[module].__mod_name__) if help_txt == False: help_txt = HELPABLE[module].__help__ text = tld(chat.id, "Here is the help for the *{}* module:\n{}").format(mod_name, help_txt) query.message.reply_text(text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton(text=tld(chat.id, "Back"), callback_data="help_back")]])) elif prev_match: curr_page = int(prev_match.group(1)) query.message.reply_text(tld(chat.id, "send-help").format( dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld(chat.id, "\nAll commands can either be used with `/` or `!`.\n") ), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(paginate_modules(chat.id, curr_page - 1, HELPABLE, "help"))) elif next_match: next_page = int(next_match.group(1)) query.message.reply_text(tld(chat.id, "send-help").format( dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld(chat.id, "\nAll commands can either be used with `/` or `!`.\n") ), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(paginate_modules(chat.id, next_page + 1, HELPABLE, "help"))) elif back_match: query.message.reply_text(text=tld(chat.id, "send-help").format( dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld(chat.id, "\nAll commands can either be used with `/` or `!`.\n") ), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(paginate_modules(chat.id, 0, HELPABLE, "help"))) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "Message is not modified": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Message can't be deleted": pass else: LOGGER.exception("Exception in help buttons. %s", str(query.data))
def locale(bot, update, args): chat = update.effective_chat if len(args) > 0: locale = args[0].lower() if locale in list_locales: if locale in ('en', 'ru', 'ua', 'es', 'tr', 'id'): switch_to_locale(chat.id, locale) update.message.reply_text( tld(chat.id, 'Switched to {} successfully!').format( list_locales[locale])) else: update.message.reply_text("{} is not supported yet!".format( list_locales[locale])) else: update.message.reply_text( "Is that even a valid language code? Use an internationally accepted ISO code!" ) else: LANGUAGE = prev_locale(chat.id) if LANGUAGE: locale = LANGUAGE.locale_name native_lang = list_locales[locale] update.message.reply_text( "Current locale for this chat is: *{}*".format(native_lang), parse_mode=ParseMode.MARKDOWN) else: update.message.reply_text( "Current locale for this chat is: *English*", parse_mode=ParseMode.MARKDOWN)
def setlog(bot: Bot, update: Update): message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] if chat.type == chat.CHANNEL: message.reply_text( tld( chat.id, "Now, forward the /setlog to the group you want to tie this channel to!" )) elif message.forward_from_chat: sql.set_chat_log_channel(chat.id, message.forward_from_chat.id) try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception( "Error deleting message in log channel. Should work anyway though." ) try: bot.send_message( message.forward_from_chat.id, tld( chat.id, "This channel has been set as the log channel for {}." ).format(chat.title or chat.first_name)) except Unauthorized as excp: if excp.message == "Forbidden: bot is not a member of the channel chat": bot.send_message( chat.id, tld(chat.id, "Successfully set log channel!")) else: LOGGER.exception("ERROR in setting the log channel.") bot.send_message(chat.id, tld(chat.id, "Successfully set log channel!")) else: message.reply_text( tld( chat.id, "*The steps to set a log channel are:*\n" " • add bot to the desired channel\n" " • send /setlog to the channel\n" " • forward the /setlog to the group\n"), ParseMode.MARKDOWN)
def unsetlog(bot: Bot, update: Update): message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] log_channel = sql.stop_chat_logging(chat.id) if log_channel: try: bot.send_message( log_channel, tld(chat.id, "Channel has been unlinked from {}").format( chat.title)) message.reply_text(tld(chat.id, "Log channel has been un-set.")) except: print("Nut") else: message.reply_text(tld(chat.id, "No log channel has been set yet!"))
def add_blacklist(bot: Bot, update: Update): msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] words = msg.text.split(None, 1) conn = connected(bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": exit(1) else: chat_name = chat.title if len(words) > 1: text = words[1] to_blacklist = list( set(trigger.strip() for trigger in text.split("\n") if trigger.strip())) for trigger in to_blacklist: sql.add_to_blacklist(chat_id, trigger.lower()) if len(to_blacklist) == 1: msg.reply_text(tld( chat.id, "Added <code>{}</code> to the blacklist in <b>{}</b>!").format( html.escape(to_blacklist[0]), chat_name), parse_mode=ParseMode.HTML) else: msg.reply_text(tld( chat.id, "Added <code>{}</code> to the blacklist in <b>{}</b>!").format( len(to_blacklist)), chat_name, parse_mode=ParseMode.HTML) else: msg.reply_text( tld(chat.id, "Tell me what words you would like to add to the blacklist."))
def paginate_modules(chat_id, page_n: int, module_dict: Dict, prefix, chat=None) -> List: if not chat: modules = sorted([ EqInlineKeyboardButton(tld(chat_id, x.__mod_name__), callback_data="{}_module({})".format( prefix, x.__mod_name__.lower())) for x in module_dict.values() ]) else: modules = sorted([ EqInlineKeyboardButton(tld(chat_id, x.__mod_name__), callback_data="{}_module({},{})".format( prefix, chat, x.__mod_name__.lower())) for x in module_dict.values() ]) pairs = list(zip(modules[::2], modules[1::2])) if len(modules) % 2 == 1: pairs.append((modules[-1], )) max_num_pages = ceil(len(pairs) / 7) modulo_page = page_n % max_num_pages # can only have a certain amount of buttons side by side if len(pairs) > 7: pairs = pairs[modulo_page * 7:7 * (modulo_page + 1)] + [ (EqInlineKeyboardButton( "<<", callback_data="{}_prev({})".format(prefix, modulo_page)), EqInlineKeyboardButton("⬅️ Back", callback_data="bot_start"), EqInlineKeyboardButton(">>", callback_data="{}_next({})".format( prefix, modulo_page))) ] else: pairs += [[ EqInlineKeyboardButton("⬅️ Back", callback_data="bot_start") ]] return pairs
def afk(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] args = update.effective_message.text.split(None, 1) if len(args) >= 2: reason = args[1] else: reason = "" sql.set_afk(update.effective_user.id, reason) fname = update.effective_user.first_name update.effective_message.reply_text(tld(chat.id, f"{fname} is now AFK!"))
def stop_filter(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] args = update.effective_message.text.split(None, 1) conn = connected(bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "local notes" else: chat_name = chat.title if len(args) < 2: return chat_filters = sql.get_chat_triggers(chat_id) if not chat_filters: update.effective_message.reply_text( tld(chat.id, "No filters are active in {}!").format(chat_name)) return for keyword in chat_filters: if keyword == args[1]: sql.remove_filter(chat_id, args[1]) update.effective_message.reply_text( tld(chat.id, "Yep, I'll stop replying to that in *{}*.").format( chat_name), parse_mode=telegram.ParseMode.MARKDOWN) raise DispatcherHandlerStop update.effective_message.reply_text( tld( chat.id, "That's not a current filter - run /filters for all active filters." ))
def check_flood(bot: Bot, update: Update) -> str: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] if not user: # ignore channels return "" # ignore admins if is_user_admin(chat, user.id): sql.update_flood(chat.id, None) return "" should_ban = sql.update_flood(chat.id, user.id) if not should_ban: return "" try: bot.restrict_chat_member(chat.id, user.id, can_send_messages=False) msg.reply_text( tld( chat.id, "I like to leave the flooding to natural disasters. But you, you were just a " "disappointment. *Muted*!")) return "<b>{}:</b>" \ "\n#MUTED" \ "\n<b>User:</b> {}" \ "\nFlooded the group.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) except BadRequest: msg.reply_text( tld( chat.id, "I can't mute people here, give me permissions first! Until then, I'll disable antiflood." )) sql.set_flood(chat.id, 0) return "<b>{}:</b>" \ "\n#INFO" \ "\nDon't have mute permissions, so automatically disabled antiflood.".format(chat.title)
def blacklist(bot: Bot, update: Update, args: List[str]): msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if chat.type == "private": exit(1) else: chat_id = update.effective_chat.id chat_name = chat.title filter_list = tld( chat.id, "<b>Current blacklisted words in {}:</b>\n").format(chat_name) all_blacklisted = sql.get_chat_blacklist(chat_id) if len(args) > 0 and args[0].lower() == 'copy': for trigger in all_blacklisted: filter_list += "<code>{}</code>\n".format(html.escape(trigger)) else: for trigger in all_blacklisted: filter_list += " • <code>{}</code>\n".format(html.escape(trigger)) split_text = split_message(filter_list) for text in split_text: if filter_list == tld( chat.id, "<b>Current blacklisted words in {}:</b>\n").format( chat_name): #We need to translate msg.reply_text(tld( chat.id, "There are no blacklisted messages in <b>{}</b>!").format( chat_name), parse_mode=ParseMode.HTML) return msg.reply_text(text, parse_mode=ParseMode.HTML)
def antispam(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] if len(args) > 0: if args[0].lower() in ["on", "yes"]: sql.enable_antispam(chat.id) update.effective_message.reply_text( tld( chat.id, "I've enabled antispam security in this group. This will help protect you " "from spammers, unsavoury characters, and the biggest trolls." )) elif args[0].lower() in ["off", "no"]: sql.disable_antispam(chat.id) update.effective_message.reply_text( tld( chat.id, "I've disabled antispam security in this group. GBans wont affect your users " "anymore. You'll be less protected from any trolls and spammers " "though! And i am little disappointed too. 😶")) else: update.effective_message.reply_text( tld( chat.id, "Give me some arguments to choose a setting! on/off, yes/no!\n\n" "Your current setting is: {}\n" "When True, any gbans that happen will also happen in your group. " "When False, they won't, leaving you at the possible mercy of " "spammers.").format(sql.does_chat_gban(chat.id)))
def list_handlers(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title filter_list = tld(chat.id, "*List of filters in {}:*\n") else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = tld(chat.id, "local filters") filter_list = tld(chat.id, "*local filters:*\n") else: chat_name = chat.title filter_list = tld(chat.id, "*Filters in {}*:\n") all_handlers = sql.get_chat_triggers(chat_id) if not all_handlers: update.effective_message.reply_text( tld(chat.id, "No filters in {}!").format(chat_name)) return for keyword in all_handlers: entry = " • `{}`\n".format(escape_markdown(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text( filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN) filter_list = entry else: filter_list += entry update.effective_message.reply_text(filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN)
def __user_info__(user_id, chat_id): is_gbanned = sql.is_user_gbanned(user_id) is_gmuted = sql.is_user_gmuted(user_id) if not user_id in SUDO_USERS: text = tld(chat_id, "Globally banned: <b>{}</b>") if is_gbanned: text = text.format(tld(chat_id, "Yes")) user = sql.get_gbanned_user(user_id) if user.reason: text += tld(chat_id, "\nReason: {}").format(html.escape(user.reason)) else: text = text.format(tld(chat_id, "No")) text += tld(chat_id, "\nGlobally muted: <b>{}</b>") if is_gmuted: text = text.format(tld(chat_id, "Yes")) user = sql.get_gmuted_user(user_id) if user.reason: text += tld(chat_id, "\nReason: {}").format(html.escape(user.reason)) else: text = text.format(tld(chat_id, "No")) return text else: return ""
def allow_connections(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] if chat.type != chat.PRIVATE: if len(args) >= 1: var = args[0] print(var) if var == "no": sql.set_allow_connect_to_chat(chat.id, False) update.effective_message.reply_text( tld(chat.id, "Disabled connections to this chat for users")) elif var == "yes": sql.set_allow_connect_to_chat(chat.id, True) update.effective_message.reply_text( tld(chat.id, "Enabled connections to this chat for users")) else: update.effective_message.reply_text( tld(chat.id, "Please enter on/yes/off/no in group!")) else: update.effective_message.reply_text( tld(chat.id, "Please enter on/yes/off/no in group!")) else: update.effective_message.reply_text( tld(chat.id, "Please enter on/yes/off/no in group!"))
def no_longer_afk(bot: Bot, update: Update): user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] if not user: # ignore channels return res = sql.rm_afk(user.id) if res: firstname = update.effective_user.first_name try: update.effective_message.reply_text( tld(chat.id, f"{firstname} is no longer AFK!")) except: return
def slap(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message if msg.from_user.username: curr_user = "******" + escape_markdown(msg.from_user.username) else: curr_user = "******".format(msg.from_user.first_name, msg.from_user.id) user_id = extract_user(update.effective_message, args) if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user if slapped_user.username: user2 = "@" + escape_markdown(slapped_user.username) else: user2 = "[{}](tg://user?id={})".format(slapped_user.first_name, slapped_user.id) # if no target found, bot targets the sender else: user1 = "[{}](tg://user?id={})".format(bot.first_name, bot.id) user2 = curr_user temp = random.choice(tld(chat.id, "SLAP_TEMPLATES-K")) item = random.choice(tld(chat.id, "ITEMS-K")) hit = random.choice(tld(chat.id, "HIT-K")) throw = random.choice(tld(chat.id, "THROW-K")) itemp = random.choice(tld(chat.id, "ITEMP-K")) itemr = random.choice(tld(chat.id, "ITEMR-K")) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw, itemp=itemp, itemr=itemr) #user1=user1, user2=user2, item=item_ru, hits=hit_ru, throws=throw_ru, itemp=itemp_ru, itemr=itemr_ru reply_text(repl, parse_mode=ParseMode.MARKDOWN)
def runs(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] update.effective_message.reply_text(random.choice(tld(chat.id, "RUNS-K")))
def insults(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] text = random.choice(tld(chat.id, "INSULTS-K")) update.effective_message.reply_text(text)
def control_panel(bot, update): chat = update.effective_chat user = update.effective_user # ONLY send help in PM if chat.type != chat.PRIVATE: update.effective_message.reply_text( "Contact me in PM to access the control panel.", reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="Control Panel", url=f"t.me/{bot.username}?start=controlpanel") ]])) return #Support to run from command handler query = update.callback_query if query: try: query.message.delete() except BadRequest as ee: update.effective_message.reply_text( f"Failed to delete query, {ee}") M_match = re.match(r"cntrl_panel_M", query.data) U_match = re.match(r"cntrl_panel_U", query.data) G_match = re.match(r"cntrl_panel_G", query.data) back_match = re.match(r"help_back", query.data) else: M_match = "kyne : none of a Kind" #LMAO, don't uncomment if M_match: text = "*Control panel* 🛠" keyboard = [[ InlineKeyboardButton(text="👤 My settings", callback_data="cntrl_panel_U(1)") ]] #Show connected chat and add chat settings button conn = connected(bot, update, chat, user.id, need_admin=False) if conn: chatG = bot.getChat(conn) #admin_list = chatG.get_administrators() #Unused variable #If user admin member = chatG.get_member(user.id) if member.status in ('administrator', 'creator'): text += f"\nConnected chat - *{chatG.title}* (you {member.status})" keyboard += [[ InlineKeyboardButton(text="👥 Group settings", callback_data="cntrl_panel_G_back") ]] elif user.id in SUDO_USERS: text += f"\nConnected chat - *{chatG.title}* (you sudo)" keyboard += [[ InlineKeyboardButton(text="👥 Group settings (SUDO)", callback_data="cntrl_panel_G_back") ]] else: text += f"\nConnected chat - *{chatG.title}* (you aren't an admin!)" else: text += "\nNo chat connected!" keyboard += [[ InlineKeyboardButton(text="⬅️ Back", callback_data="bot_start") ]] update.effective_message.reply_text( text, reply_markup=InlineKeyboardMarkup(keyboard), parse_mode=ParseMode.MARKDOWN) elif U_match: mod_match = re.match(r"cntrl_panel_U_module\((.+?)\)", query.data) back_match = re.match(r"cntrl_panel_U\((.+?)\)", query.data) chatP = update.effective_chat # type: Optional[Chat] if mod_match: module = mod_match.group(1) R = CHAT_SETTINGS[module].__user_settings__(bot, update, user) text = "You has the following settings for the *{}* module:\n\n".format( CHAT_SETTINGS[module].__mod_name__) + R[0] keyboard = R[1] keyboard += [[ InlineKeyboardButton(text="⬅️ Back", callback_data="cntrl_panel_U(1)") ]] query.message.reply_text( text=text, arse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(keyboard)) elif back_match: text = "*User control panel* 🛠" query.message.reply_text(text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules( user.id, 0, USER_SETTINGS, "cntrl_panel_U"))) elif G_match: mod_match = re.match(r"cntrl_panel_G_module\((.+?)\)", query.data) prev_match = re.match(r"cntrl_panel_G_prev\((.+?)\)", query.data) next_match = re.match(r"cntrl_panel_G_next\((.+?)\)", query.data) back_match = re.match(r"cntrl_panel_G_back", query.data) chatP = chat conn = connected(bot, update, chat, user.id) if conn: chat = bot.getChat(conn) else: query.message.reply_text(text="Error with connection to chat") exit(1) if mod_match: module = mod_match.group(1) R = CHAT_SETTINGS[module].__chat_settings__( bot, update, chat, chatP, user) if type(R) is list: text = R[0] keyboard = R[1] else: text = R keyboard = [] text = "*{}* has the following settings for the *{}* module:\n\n".format( escape_markdown(chat.title), CHAT_SETTINGS[module].__mod_name__) + text keyboard += [[ InlineKeyboardButton(text="Back", callback_data="cntrl_panel_G_back") ]] query.message.reply_text( text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(keyboard)) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text(tld( user.id, "send-group-settings").format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, 0, CHAT_SETTINGS, "cntrl_panel_G", chat=chat_id))) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text(tld( user.id, "send-group-settings").format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, 0, CHAT_SETTINGS, "cntrl_panel_G", chat=chat_id))) elif back_match: text = "Control Panel :3" query.message.reply_text(text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules( user.id, 0, CHAT_SETTINGS, "cntrl_panel_G")))
def gdpr(bot: Bot, update: Update): update.effective_message.reply_text(tld(update.effective_chat.id, "Deleting identifiable data...")) for mod in GDPR: mod.__gdpr__(update.effective_user.id) update.effective_message.reply_text(tld(update.effective_chat.id, "send_gdpr"), parse_mode=ParseMode.MARKDOWN)
def info(bot: Bot, update: Update, args: List[str]): msg = update.effective_message # type: Optional[Message] user_id = extract_user(update.effective_message, args) chat = update.effective_chat # type: Optional[Chat] if user_id: user = bot.get_chat(user_id) elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and (not args or ( len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities( [MessageEntity.TEXT_MENTION]))): msg.reply_text(tld(chat.id, "I can't extract a user from this.")) return else: return text = tld(chat.id, "<b>User info</b>:") text += "\nID: <code>{}</code>".format(user.id) text += tld(chat.id, "\nFirst Name: {}").format(html.escape(user.first_name)) if user.last_name: text += tld(chat.id, "\nLast Name: {}").format(html.escape(user.last_name)) if user.username: text += tld(chat.id, "\nUsername: @{}").format(html.escape(user.username)) text += tld(chat.id, "\nUser link: {}\n").format(mention_html(user.id, "link")) if user.id == OWNER_ID: text += tld(chat.id, "\n\nAy, This guy is my owner. I would never do anything against him!") else: if user.id == int(254318997): text += tld(chat.id, "\nThis person.... He is my god.") if user.id in SUDO_USERS: text += tld(chat.id, "\nThis person is one of my sudo users! " \ "Nearly as powerful as my owner - so watch it.") else: if user.id in SUPPORT_USERS: text += tld(chat.id, "\nThis person is one of my support users! " \ "Not quite a sudo user, but can still gban you off the map.") if user.id in WHITELIST_USERS: text += tld(chat.id, "\nThis person has been whitelisted! " \ "That means I'm not allowed to ban/kick them.") for mod in USER_INFO: mod_info = mod.__user_info__(user.id, chat.id).strip() if mod_info: text += "\n\n" + mod_info update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def settings_button(bot: Bot, update: Update): query = update.callback_query user = update.effective_user chatP = update.effective_chat # type: Optional[Chat] mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data) prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data) next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data) back_match = re.match(r"stngs_back\((.+?)\)", query.data) try: if mod_match: chat_id = mod_match.group(1) module = mod_match.group(2) chat = bot.get_chat(chat_id) text = "*{}* has the following settings for the *{}* module:\n\n".format(escape_markdown(chat.title), CHAT_SETTINGS[ module].__mod_name__) + \ CHAT_SETTINGS[module].__chat_settings__(bot, update, chat, chatP, user) query.message.reply_text( text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="Back", callback_data="stngs_back({})".format(chat_id)) ]])) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text(tld( user.id, "send-group-settings").format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, 0, CHAT_SETTINGS, "stngs", chat=chat_id))) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text(tld( user.id, "send-group-settings").format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, 0, CHAT_SETTINGS, "stngs", chat=chat_id))) elif back_match: chat_id = back_match.group(1) chat = bot.get_chat(chat_id) query.message.reply_text(text=tld(user.id, "send-group-settings").format( escape_markdown(chat.title)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(user.id, 0, CHAT_SETTINGS, "stngs", chat=chat_id))) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "Message is not modified": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Message can't be deleted": pass else: LOGGER.exception("Exception in settings buttons. %s", str(query.data))