def invite(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: chatP = dispatcher.bot.getChat(conn) else: chatP = update.effective_chat if chat.type == "private": exit(1) if chatP.username: update.effective_message.reply_text(chatP.username) elif chatP.type == chatP.SUPERGROUP or chatP.type == chatP.CHANNEL: bot_member = chatP.get_member(bot.id) if bot_member.can_invite_users: invitelink = chatP.invite_link #print(invitelink) if not invitelink: invitelink = bot.exportChatInviteLink(chatP.id) update.effective_message.reply_text(invitelink) else: update.effective_message.reply_text( tld( chat.id, "I don't have access to the invite link, try changing my permissions!" )) else: update.effective_message.reply_text( tld( chat.id, "I can only give you invite links for supergroups and channels, sorry!" ))
def adminlist(bot, 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: chatP = dispatcher.bot.getChat(conn) else: chatP = update.effective_chat if chat.type == "private": exit(1) administrators = chatP.get_administrators() text = tld(chat.id, "Admins in") + " *{}*:".format( chatP.title or tld(chat.id, "this chat")) for admin in administrators: user = admin.user status = admin.status if status == "creator": name = user.first_name + (user.last_name or "") + tld( chat.id, " (Creator)") else: name = user.first_name + (user.last_name or "") text += f"\nā¢ `{name}`" update.effective_message.reply_text(text, parse_mode=ParseMode.MARKDOWN)
def list_warn_filters(update, context): chat = update.effective_chat user = update.effective_user conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat_id = conn else: if chat.type == "private": return else: chat_id = update.effective_chat.id all_handlers = sql.get_chat_warn_triggers(chat_id) if not all_handlers: update.effective_message.reply_text( "No warning filters are active here!") return filter_list = CURRENT_WARNING_FILTER_STRING for keyword in all_handlers: entry = " - {}\n".format(html.escape(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML) filter_list = entry else: filter_list += entry if not filter_list == CURRENT_WARNING_FILTER_STRING: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML)
def clear(update, context): args = context.args chat = update.effective_chat user = update.effective_user msg = update.effective_message conn = connected(context.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) >= 1: notename = args[0].lower() if sql.rm_note(chat_id, notename): update.effective_message.reply_text( "Successfully deleted '`{note_name}`' from {chat_name}!". format(note_name=notename, chat_name=chat_name), parse_mode=ParseMode.MARKDOWN, ) else: update.effective_message.reply_text( "There is no such notes saved in {chat_name}!".format( chat_name=chat_name)) else: msg.reply_text("Yeah let me clear nothing...") return
def disable(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": exit(1) else: chatD = update.effective_chat if len(args) >= 1: disable_cmd = args[0] if disable_cmd.startswith(CMD_STARTERS): disable_cmd = disable_cmd[1:] if disable_cmd in set(DISABLE_CMDS + DISABLE_OTHER): sql.disable_command(chatD.id, disable_cmd) update.effective_message.reply_text(tld(chat.id, "Disabled the use of `{}` in *{}*").format(disable_cmd, chatD.title), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text(tld(chat.id, "That command can't be disabled")) else: update.effective_message.reply_text(tld(chat.id, "What should I disable?"))
def enable(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": exit(1) else: chatD = update.effective_chat if len(args) >= 1: enable_cmd = args[0] if enable_cmd.startswith(CMD_STARTERS): enable_cmd = enable_cmd[1:] if sql.enable_command(chatD.id, enable_cmd): update.effective_message.reply_text(tld(chat.id, "Enabled the use of `{}` in *{}*").format(enable_cmd, chatD.title), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text(tld(chat.id, "Is that even disabled?")) else: update.effective_message.reply_text(tld(chat.id, "What should I enable?"))
def promote(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": exit(1) if not chatD.get_member(bot.id).can_promote_members: update.effective_message.reply_text( "I can't promote/demote people here! " "Make sure I'm admin and can appoint new admins.") exit(1) user_id = extract_user(message, args) if not user_id: message.reply_text( tld(chat.id, "You don't seem to be referring to a user.")) return "" user_member = chatD.get_member(user_id) if user_member.status == 'administrator' or user_member.status == 'creator': message.reply_text( tld(chat.id, "How am I meant to promote someone that's already an admin?")) return "" if user_id == bot.id: message.reply_text( tld(chat.id, "I can't promote myself! Get an admin to do it for me.")) return "" # set same perms as bot - bot can't assign higher perms than itself! bot_member = chatD.get_member(bot.id) bot.promoteChatMember( chatD.id, user_id, can_change_info=bot_member.can_change_info, can_post_messages=bot_member.can_post_messages, can_edit_messages=bot_member.can_edit_messages, can_delete_messages=bot_member.can_delete_messages, #can_invite_users=bot_member.can_invite_users, can_restrict_members=bot_member.can_restrict_members, can_pin_messages=bot_member.can_pin_messages, can_promote_members=bot_member.can_promote_members) message.reply_text(tld(chat.id, f"Successfully promoted in *{chatD.title}*!"), parse_mode=ParseMode.MARKDOWN) return f"<b>{html.escape(chatD.title)}:</b>" \ "\n#PROMOTED" \ f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}" \ f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
def locale_button(bot, update): chat = update.effective_chat user = update.effective_user # type: Optional[User] query = update.callback_query lang_match = re.findall(r"en|ru|ua|es|tr|id|it", query.data) if lang_match: if lang_match[0]: switch_to_locale(chat.id, lang_match[0]) query.answer(text="Language changed!") else: query.answer(text="Error!", show_alert=True) try: LANGUAGE = prev_locale(chat.id) locale = LANGUAGE.locale_name curr_lang = list_locales[locale] except: curr_lang = "English" text = "*Select language* \n" text += "User language : `{}`".format(curr_lang) conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: try: chatlng = prev_locale(conn).locale_name chatlng = list_locales[chatlng] text += "\nConnected chat language : `{}`".format(chatlng) except: chatlng = "English" text += "*\n\nSelect new user language:*" query.message.reply_text( text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton("English šŗšø", callback_data="set_lang_en") ]] + [[ InlineKeyboardButton("Russian š·šŗ", callback_data="set_lang_ru"), InlineKeyboardButton("Ukrainian šŗš¦", callback_data="set_lang_ua") ]] + [[ InlineKeyboardButton("Spanish šŖšø", callback_data="set_lang_es"), InlineKeyboardButton("Turkish š¹š·", callback_data="set_lang_tr") ]] + [[ InlineKeyboardButton("Indonesian š®š©", callback_data="set_lang_id"), InlineKeyboardButton("Italian š®š¹", callback_data="set_lang_it") ]] + [[InlineKeyboardButton("ā¬ ļø Back", callback_data="bot_start")]])) print(lang_match) query.message.delete() bot.answer_callback_query(query.id)
def set_warn_strength(update, context): chat = update.effective_chat user = update.effective_user msg = update.effective_message args = context.args conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if chat.type == "private": return else: chat_id = update.effective_chat.id chat_name = chat.title if args: if args[0].lower() in ("on", "yes"): sql.set_warn_strength(chat_id, False) msg.reply_text("Too many warns will now result in a ban!") return ("<b>{}:</b>\n" "<b>Admin:</b> {}\n" "Has enabled strong warns. Users will be banned.".format( chat_name, mention_html(user.id, user.first_name))) elif args[0].lower() in ("off", "no"): sql.set_warn_strength(chat_id, True) msg.reply_text( "Too many warns will now result in a kick! Users will be able to join again after." ) return ( "<b>{}:</b>\n" "<b>Admin:</b> {}\n" "Has disabled strong warns. Users will only be kicked.".format( chat_name, mention_html(user.id, user.first_name))) else: msg.reply_text("I only understand on/yes/no/off!") else: _, soft_warn = sql.get_warn_setting(chat_id) if soft_warn: msg.reply_text( "Warns are currently set to *kick* users when they exceed the limits.", parse_mode=ParseMode.MARKDOWN, ) else: msg.reply_text( "Warns are currently set to *ban* users when they exceed the limits.", parse_mode=ParseMode.MARKDOWN, ) return ""
def warns(update, context): message = update.effective_message chat = update.effective_chat args = context.args user = update.effective_user user_id = extract_user(message, args) or update.effective_user.id conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if chat.type == "private": return else: chat_id = update.effective_chat.id chat_name = chat.title result = sql.get_warns(user_id, chat_id) num = 1 if result and result[0] != 0: num_warns, reasons = result limit, _ = sql.get_warn_setting(chat_id) if reasons: if conn: text = "This user has {}/{} warnings, in *{}* for the following reasons:".format( num_warns, limit, chat_name) else: text = "This user has {}/{} warnings, for the following reasons:".format( num_warns, limit, ) for reason in reasons: text += "\n {}. {}".format(num, reason) num += 1 msgs = split_message(text) for msg in msgs: update.effective_message.reply_text(msg, parse_mode="markdown") else: update.effective_message.reply_text( "User has {}/{} warnings, but no reasons for any of them.". format(num_warns, limit), parse_mode="markdown", ) else: update.effective_message.reply_text( "This user hasn't got any warnings!")
def add_blacklist(update, context): msg = update.effective_message chat = update.effective_chat user = update.effective_user words = msg.text.split(None, 1) conn = connected(context.bot, update, chat, user.id) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": return 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: blacklist_db.add_to_blacklist(chat_id, trigger.lower()) if len(to_blacklist) == 1: send_message( update.effective_message, "Added blacklist <code>{}</code> in chat: <b>{}</b>!".format( html.escape(to_blacklist[0]), chat_name), parse_mode=ParseMode.HTML, ) else: send_message( update.effective_message, "Added blacklist trigger: <code>{}</code> in <b>{}</b>!". format(len(to_blacklist), chat_name), parse_mode=ParseMode.HTML, ) else: send_message( update.effective_message, "Tell me which words you would like to add in blacklist.", )
def add_warn_filter(update, context): chat = update.effective_chat user = update.effective_user msg = update.effective_message args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if chat.type == "private": return else: chat_id = update.effective_chat.id chat_name = chat.title if len(args) < 2: return extracted = split_quotes(args[1]) if len(extracted) >= 2: # set trigger -> lower, so as to avoid adding duplicate filters with # different cases keyword = extracted[0].lower() content = extracted[1] else: return # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(WARN_HANDLER_GROUP, []): if handler.filters == (keyword, chat_id): dispatcher.remove_handler(handler, WARN_HANDLER_GROUP) sql.add_warn_filter(chat_id, keyword, content) update.effective_message.reply_text( "Warn filter added for `{}` in *{}*!".format(keyword, chat_name), parse_mode="markdown", ) raise DispatcherHandlerStop
def save(update, context): chat = update.effective_chat user = update.effective_user conn = connected(context.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 msg = update.effective_message try: note_name, text, data_type, content, buttons = get_note_type(msg) except IndexError: msg.reply_text( "This isn't right things T_T\nUsage: /save <notename> <msg/reply to msg>" ) return note_name = note_name.lower() if data_type is None: msg.reply_text("Bruh! there's no note") return if len(text.strip()) == 0: text = note_name sql.add_note_to_db(chat_id, note_name, text, data_type, buttons=buttons, file=content) msg.reply_text( "Saved '`{note_name}`' in *{chat_name}*.\nGet it with `/get {note_name}`, or `#{note_name}`!" .format(note_name=note_name, chat_name=chat_name), parse_mode=ParseMode.MARKDOWN, )
def set_warn_limit(update, context) -> str: chat = update.effective_chat user = update.effective_user msg = update.effective_message args = context.args conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if chat.type == "private": return else: chat_id = update.effective_chat.id chat_name = chat.title if args: if args[0].isdigit(): if int(args[0]) < 3: msg.reply_text("The minimum warn limit is 3!") else: sql.set_warn_limit(chat_id, int(args[0])) msg.reply_text( "Updated the warn limit to `{}` in *{}*".format( escape_markdown(args[0]), chat_name), parse_mode="markdown", ) return ("<b>{}:</b>" "\n#SET_WARN_LIMIT" "\n<b>Admin:</b> {}" "\nSet the warn limit to <code>{}</code>".format( html.escape(chat_name), mention_html(user.id, user.first_name), args[0], )) else: msg.reply_text("Give me a number as an arg!") else: limit, _ = sql.get_warn_setting(chat_id) msg.reply_text("The current warn in {} limit is {}".format( chat_name, limit)) return ""
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 list_handlers(update, context): chat = update.effective_chat user = update.effective_user conn = connected(context.bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title filter_list = "*Filter in {}:*\n" else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "Local filters" filter_list = "*local filters:*\n" else: chat_name = chat.title filter_list = "*Filters in {}*:\n" all_handlers = sql.get_chat_triggers(chat_id) if not all_handlers: send_message( update.effective_message, "No filters saved 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: send_message( update.effective_message, filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN, ) filter_list = entry else: filter_list += entry send_message( update.effective_message, filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN, )
def disable(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user args = context.args conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "This command meant to be used in group not in PM", ) return "" chat = update.effective_chat chat_name = update.effective_message.chat.title if len(args) >= 1: disable_cmd = args[0] if disable_cmd.startswith(CMD_STARTERS): disable_cmd = disable_cmd[1:] if disable_cmd in set(DISABLE_CMDS + DISABLE_OTHER): disable_db.disable_command(chat.id, disable_cmd) if conn: text = "Disabled the use of `{}` command in *{}*!".format( disable_cmd, chat_name) else: text = "Disabled the use of `{}` command!".format( disable_cmd) send_message( update.effective_message, text, parse_mode=ParseMode.MARKDOWN, ) else: send_message(update.effective_message, "This command can't be disabled") else: send_message(update.effective_message, "What should I disable?")
def remove_warn_filter(update, context): chat = update.effective_chat user = update.effective_user msg = update.effective_message conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat_id = conn else: if chat.type == "private": return else: chat_id = update.effective_chat.id args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text if len(args) < 2: return extracted = split_quotes(args[1]) if len(extracted) < 1: return to_remove = extracted[0] chat_filters = sql.get_chat_warn_triggers(chat_id) if not chat_filters: msg.reply_text("No warning filters are active here!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat_id, to_remove) msg.reply_text("Yep, I'll stop warning people for that.") raise DispatcherHandlerStop msg.reply_text( "That's not a current warning filter - click: /warnlist for all active warning filters." )
def commands(update, context): chat = update.effective_chat user = update.effective_user conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "This command is meant to use in group not in PM", ) return "" chat = update.effective_chat text = build_curr_disabled(chat.id) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN)
def commands(bot: Bot, update: Update): chat = update.effective_chat user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": exit(1) else: chatD = update.effective_chat disabled = sql.get_all_disabled(chatD.id) if not disabled: update.effective_message.reply_text(tld(chat.id, "No commands are disabled! in *{}*!").format(chatD.title)) text = build_curr_disabled(chatD.id, chat.id) update.effective_message.reply_text(tld(chat.id, "The following commands are currently restricted in *{}*:\n{}").format(chatD.title, text), parse_mode=ParseMode.MARKDOWN)
def stop_filter(update, context): chat = update.effective_chat user = update.effective_user args = update.effective_message.text.split(None, 1) conn = connected(context.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 filters" else: chat_name = chat.title if len(args) < 2: send_message(update.effective_message, "What should i stop?") return chat_filters = sql.get_chat_triggers(chat_id) if not chat_filters: send_message(update.effective_message, "No filters active here!") return for keyword in chat_filters: if keyword == args[1]: sql.remove_filter(chat_id, args[1]) send_message( update.effective_message, "Okay, I'll stop replying to that filter in *{}*.".format( chat_name), parse_mode=telegram.ParseMode.MARKDOWN, ) raise DispatcherHandlerStop send_message( update.effective_message, "That's not a filter - Click: /filters to get currently active filters.", )
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 blacklist(update, context): chat = update.effective_chat user = update.effective_user args = context.args conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if chat.type == "private": return else: chat_id = update.effective_chat.id chat_name = chat.title filter_list = "Current blacklisted words in <b>{}</b>:\n".format(chat_name) all_blacklisted = blacklist_db.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)) # 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 == "Current blacklisted words in <b>{}</b>:\n".format( chat_name): send_message( update.effective_message, "No blacklisted words in <b>{}</b>!".format(chat_name), parse_mode=ParseMode.HTML, ) return send_message(update.effective_message, text, parse_mode=ParseMode.HTML)
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 list_notes(update, context): chat_id = update.effective_chat.id chat = update.effective_chat user = update.effective_user conn = connected(context.bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title msg = "*Notes in {}:*\n" else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "" msg = "*Local Notes:*\n" else: chat_name = chat.title msg = "*Notes saved in {}:*\n" note_list = sql.get_all_chat_notes(chat_id) des = "You can get notes by using `/get notename`, or `#notename`.\n" for note in note_list: note_name = " Ć `{}`\n".format(note.name.lower()) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if not note_list: update.effective_message.reply_text("No notes saved here!") elif len(msg) != 0: try: update.effective_message.reply_text(msg.format(chat_name) + des, parse_mode=ParseMode.MARKDOWN) except ValueError: update.effective_message.reply_text( "There was a problem in showing notes list, maybe due to some invalid character in note names. Ask in @userbotindo if you're unable to figure it out!" )
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 save(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) 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 msg = update.effective_message # type: Optional[Message] note_name, text, data_type, content, buttons = get_note_type(msg) if data_type is None: msg.reply_text("Dude, there's no note") return if len(text.strip()) == 0: text = note_name sql.add_note_to_db(chat_id, note_name, text, data_type, buttons=buttons, file=content) msg.reply_text( "Ok, added `{note_name}` note in *{chat_name}*.\nGet it with `/get {note_name}`, or `#{note_name}`" .format(note_name=note_name, chat_name=chat_name), parse_mode=ParseMode.MARKDOWN)
def clear(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] 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) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text( "Note succesfully removed from *{}*.".format(chat_name), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( "That's not a note in my database!")
def list_locks(update, context): chat = update.effective_chat user = update.effective_user # Connection check conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_name = chat.title else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "This command is meant to use in group not in PM", ) return "" chat = update.effective_chat chat_name = update.effective_message.chat.title res = build_lock_message(chat.id) if conn: res = res.replace("Locks in", "*{}*".format(chat_name)) send_message(update.effective_message, res, parse_mode=ParseMode.MARKDOWN)
def list_notes(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 msg = "*Notes in {}:*\n" else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "" msg = "*Local Notes:*\n" else: chat_name = chat.title msg = "*Notes in {}:*\n" note_list = sql.get_all_chat_notes(chat_id) for note in note_list: note_name = " ā¢ `#{}`\n".format(note.name) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if not note_list: update.effective_message.reply_text( "No notes in *{}*!".format(chat_name), parse_mode=ParseMode.MARKDOWN) elif len(msg) != 0: msg += "\nYou can retrieve these notes by using `/get notename`, or `#notename`" update.effective_message.reply_text(msg.format(chat_name), parse_mode=ParseMode.MARKDOWN)