Python telegram.ext.Filters.all() Examples
The following are 16
code examples of telegram.ext.Filters.all().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
telegram.ext.Filters
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: locks.py From SkittBot with GNU General Public License v3.0 | 6 votes |
def lock(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 can_delete(chat, bot.id): if len(args) >= 1: if args[0] in LOCK_TYPES: sql.update_lock(chat.id, args[0], locked=True) message.reply_text("Locked {} messages for all non-admins!".format(args[0])) return "<b>{}:</b>" \ "\n#LOCK" \ "\n<b>Admin:</b> {}" \ "\nLocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) elif args[0] in RESTRICTION_TYPES: sql.update_restriction(chat.id, args[0], locked=True) if args[0] == "previews": members = users_sql.get_chat_members(str(chat.id)) restr_members(bot, chat.id, members, messages=True, media=True, other=True) message.reply_text("Locked {} for all non-admins!".format(args[0])) return "<b>{}:</b>" \ "\n#LOCK" \ "\n<b>Admin:</b> {}" \ "\nLocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) else: message.reply_text("What are you trying to lock...? Try /locktypes for the list of lockables") else: message.reply_text("I'm not an administrator, or haven't got delete rights.") return ""
Example #2
Source File: daysandbox_bot.py From daysandbox_bot with MIT License | 6 votes |
def register_handlers(dispatcher, mode): assert mode in ('production', 'test') dispatcher.add_handler(MessageHandler( Filters.status_update.new_chat_members, handle_new_chat_members )) dispatcher.add_handler(CommandHandler( ['start', 'help'], handle_start_help )) dispatcher.add_handler(CommandHandler('stat', handle_stat)) dispatcher.add_handler(CommandHandler( ['daysandbox_set', 'daysandbox_get'], handle_set_get )) dispatcher.add_handler(RegexHandler( r'^/setlogformat ', handle_setlogformat, channel_post_updates=True )) dispatcher.add_handler(CommandHandler('setlog', handle_setlog)) dispatcher.add_handler(CommandHandler('unsetlog', handle_unsetlog)) dispatcher.add_handler(MessageHandler( Filters.all, partial(handle_any_message, mode), edited_updates=True ))
Example #3
Source File: bot.py From gdrivemirror_bot with GNU General Public License v3.0 | 6 votes |
def main(): updater = Updater(token=TOKEN, workers = 8) dispatcher = updater.dispatcher start_cmd = CommandHandler("start" , start) help_cmd = CommandHandler("help" , help) donate_cmd = CommandHandler("donate" , donate) dispatcher.add_handler(start_cmd) dispatcher.add_handler(help_cmd) dispatcher.add_handler(donate_cmd) if ADMIN_MODULE: extras.add_extra_commands(dispatcher) else: print("ADMIN_MODULE not found. (Won't effect the bot though.)") start_handler = MessageHandler((Filters.all) , start_bot) dispatcher.add_handler(start_handler) updater.start_polling()
Example #4
Source File: users.py From SkittBot with GNU General Public License v3.0 | 5 votes |
def __user_info__(user_id): if user_id == dispatcher.bot.id: return """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 """I've seen them in <code>{}</code> chats in total.""".format(num_chats)
Example #5
Source File: locks.py From SkittBot with GNU General Public License v3.0 | 5 votes |
def build_lock_message(chat_id): locks = sql.get_locks(chat_id) restr = sql.get_restr(chat_id) if not (locks or restr): res = "There are no current locks in this chat." else: res = "These are the locks in this chat:" if locks: res += "\n - sticker = `{}`" \ "\n - audio = `{}`" \ "\n - voice = `{}`" \ "\n - document = `{}`" \ "\n - video = `{}`" \ "\n - videonote = `{}`" \ "\n - contact = `{}`" \ "\n - photo = `{}`" \ "\n - gif = `{}`" \ "\n - url = `{}`" \ "\n - bots = `{}`" \ "\n - forward = `{}`" \ "\n - game = `{}`" \ "\n - location = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document, locks.video, locks.videonote, locks.contact, locks.photo, locks.gif, locks.url, locks.bots, locks.forward, locks.game, locks.location) if restr: res += "\n - messages = `{}`" \ "\n - media = `{}`" \ "\n - other = `{}`" \ "\n - previews = `{}`" \ "\n - all = `{}`".format(restr.messages, restr.media, restr.other, restr.preview, all([restr.messages, restr.media, restr.other, restr.preview])) return res
Example #6
Source File: users.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def __user_info__(user_id): if user_id == dispatcher.bot.id: return """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 """I've seen them in <code>{}</code> chats in total.""".format(num_chats)
Example #7
Source File: locks.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def lock(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 can_delete(chat, bot.id): if len(args) >= 1: if args[0] in LOCK_TYPES: sql.update_lock(chat.id, args[0], locked=True) message.reply_text("Locked {} messages for all non-admins!".format(args[0])) return "<b>{}:</b>" \ "\n#LOCK" \ "\n<b>Admin:</b> {}" \ "\nLocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) elif args[0] in RESTRICTION_TYPES: sql.update_restriction(chat.id, args[0], locked=True) if args[0] == "previews": members = users_sql.get_chat_members(str(chat.id)) restr_members(bot, chat.id, members, messages=True, media=True, other=True) message.reply_text("Locked {} for all non-admins!".format(args[0])) return "<b>{}:</b>" \ "\n#LOCK" \ "\n<b>Admin:</b> {}" \ "\nLocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) else: message.reply_text("What are you trying to lock...? Try /locktypes for the list of lockables") else: message.reply_text("I'm not an administrator, or haven't got delete rights.") return ""
Example #8
Source File: locks.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
def build_lock_message(chat_id): locks = sql.get_locks(chat_id) restr = sql.get_restr(chat_id) if not (locks or restr): res = "There are no current locks in this chat." else: res = "These are the locks in this chat:" if locks: res += "\n - sticker = `{}`" \ "\n - audio = `{}`" \ "\n - voice = `{}`" \ "\n - document = `{}`" \ "\n - video = `{}`" \ "\n - contact = `{}`" \ "\n - photo = `{}`" \ "\n - gif = `{}`" \ "\n - url = `{}`" \ "\n - bots = `{}`" \ "\n - forward = `{}`" \ "\n - game = `{}`" \ "\n - location = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document, locks.video, locks.contact, locks.photo, locks.gif, locks.url, locks.bots, locks.forward, locks.game, locks.location) if restr: res += "\n - messages = `{}`" \ "\n - media = `{}`" \ "\n - other = `{}`" \ "\n - previews = `{}`" \ "\n - all = `{}`".format(restr.messages, restr.media, restr.other, restr.preview, all([restr.messages, restr.media, restr.other, restr.preview])) return res
Example #9
Source File: main.py From simple-forwarder-bot with MIT License | 5 votes |
def main(): global dispatcher, updater, Token, Blacklist, admin load_config() updater = Updater(Token) dispatcher = updater.dispatcher fwd_text_handler = MessageHandler(Filters.all & (~Filters.command), read_text_message) ban_user_handler = CommandHandler('ban', ban_user) unban_user_handler = CommandHandler('unban', unban_user) callback_query_handler = CallbackQueryHandler(answer_session) dispatcher.add_handler(callback_query_handler) dispatcher.add_handler(fwd_text_handler) dispatcher.add_handler(ban_user_handler) dispatcher.add_handler(unban_user_handler) updater.start_polling()
Example #10
Source File: users.py From tgbot with GNU General Public License v3.0 | 5 votes |
def __user_info__(user_id): if user_id == dispatcher.bot.id: return """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 """I've seen them in <code>{}</code> chats in total.""".format(num_chats)
Example #11
Source File: locks.py From tgbot with GNU General Public License v3.0 | 5 votes |
def lock(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 can_delete(chat, bot.id): if len(args) >= 1: if args[0] in LOCK_TYPES: sql.update_lock(chat.id, args[0], locked=True) message.reply_text("Locked {} messages for all non-admins!".format(args[0])) return "<b>{}:</b>" \ "\n#LOCK" \ "\n<b>Admin:</b> {}" \ "\nLocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) elif args[0] in RESTRICTION_TYPES: sql.update_restriction(chat.id, args[0], locked=True) if args[0] == "previews": members = users_sql.get_chat_members(str(chat.id)) restr_members(bot, chat.id, members, messages=True, media=True, other=True) message.reply_text("Locked {} for all non-admins!".format(args[0])) return "<b>{}:</b>" \ "\n#LOCK" \ "\n<b>Admin:</b> {}" \ "\nLocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) else: message.reply_text("What are you trying to lock...? Try /locktypes for the list of lockables") else: message.reply_text("I'm not an administrator, or haven't got delete rights.") return ""
Example #12
Source File: locks.py From tgbot with GNU General Public License v3.0 | 5 votes |
def build_lock_message(chat_id): locks = sql.get_locks(chat_id) restr = sql.get_restr(chat_id) if not (locks or restr): res = "There are no current locks in this chat." else: res = "These are the locks in this chat:" if locks: res += "\n - sticker = `{}`" \ "\n - audio = `{}`" \ "\n - voice = `{}`" \ "\n - document = `{}`" \ "\n - video = `{}`" \ "\n - videonote = `{}`" \ "\n - contact = `{}`" \ "\n - photo = `{}`" \ "\n - gif = `{}`" \ "\n - url = `{}`" \ "\n - bots = `{}`" \ "\n - forward = `{}`" \ "\n - game = `{}`" \ "\n - location = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document, locks.video, locks.videonote, locks.contact, locks.photo, locks.gif, locks.url, locks.bots, locks.forward, locks.game, locks.location) if restr: res += "\n - messages = `{}`" \ "\n - media = `{}`" \ "\n - other = `{}`" \ "\n - previews = `{}`" \ "\n - all = `{}`".format(restr.messages, restr.media, restr.other, restr.preview, all([restr.messages, restr.media, restr.other, restr.preview])) return res
Example #13
Source File: locks.py From SkittBot with GNU General Public License v3.0 | 4 votes |
def unlock(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 is_user_admin(chat, message.from_user.id): if len(args) >= 1: if args[0] in LOCK_TYPES: sql.update_lock(chat.id, args[0], locked=False) message.reply_text("Unlocked {} for everyone!".format(args[0])) return "<b>{}:</b>" \ "\n#UNLOCK" \ "\n<b>Admin:</b> {}" \ "\nUnlocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) elif args[0] in RESTRICTION_TYPES: sql.update_restriction(chat.id, args[0], locked=False) """ members = users_sql.get_chat_members(chat.id) if args[0] == "messages": unrestr_members(bot, chat.id, members, media=False, other=False, previews=False) elif args[0] == "media": unrestr_members(bot, chat.id, members, other=False, previews=False) elif args[0] == "other": unrestr_members(bot, chat.id, members, previews=False) elif args[0] == "previews": unrestr_members(bot, chat.id, members) elif args[0] == "all": unrestr_members(bot, chat.id, members, True, True, True, True) """ message.reply_text("Unlocked {} for everyone!".format(args[0])) return "<b>{}:</b>" \ "\n#UNLOCK" \ "\n<b>Admin:</b> {}" \ "\nUnlocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) else: message.reply_text("What are you trying to unlock...? Try /locktypes for the list of lockables") else: bot.sendMessage(chat.id, "What are you trying to unlock...?") return ""
Example #14
Source File: bot.py From telegram-moderator with MIT License | 4 votes |
def start(self): """ Start the bot. """ # Create the EventHandler and pass it your bot's token. updater = Updater(os.environ["TELEGRAM_BOT_TOKEN"]) # Get the dispatcher to register handlers dp = updater.dispatcher # on different commands - answer in Telegram # on commands dp.add_handler( CommandHandler( command=self.available_commands, callback=self.handle_command, filters=Filters.all, ) ) # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler( Filters.all, lambda bot, update : self.logger(bot, update) )) # dp.add_handler(MessageHandler(Filters.status_update, status)) # log all errors dp.add_error_handler( lambda bot, update, error : self.error(bot, update, error) ) # Start the Bot updater.start_polling() print("Bot started. Montitoring chats: {}".format(self.chat_ids)) # Run the bot until you press Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT. This should be used most of the time, since # start_polling() is non-blocking and will stop the bot gracefully. updater.idle()
Example #15
Source File: locks.py From Marie-2.0-English with GNU General Public License v3.0 | 4 votes |
def unlock(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 is_user_admin(chat, message.from_user.id): if len(args) >= 1: if args[0] in LOCK_TYPES: sql.update_lock(chat.id, args[0], locked=False) message.reply_text("Unlocked {} for everyone!".format(args[0])) return "<b>{}:</b>" \ "\n#UNLOCK" \ "\n<b>Admin:</b> {}" \ "\nUnlocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) elif args[0] in RESTRICTION_TYPES: sql.update_restriction(chat.id, args[0], locked=False) """ members = users_sql.get_chat_members(chat.id) if args[0] == "messages": unrestr_members(bot, chat.id, members, media=False, other=False, previews=False) elif args[0] == "media": unrestr_members(bot, chat.id, members, other=False, previews=False) elif args[0] == "other": unrestr_members(bot, chat.id, members, previews=False) elif args[0] == "previews": unrestr_members(bot, chat.id, members) elif args[0] == "all": unrestr_members(bot, chat.id, members, True, True, True, True) """ message.reply_text("Unlocked {} for everyone!".format(args[0])) return "<b>{}:</b>" \ "\n#UNLOCK" \ "\n<b>Admin:</b> {}" \ "\nUnlocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) else: message.reply_text("What are you trying to unlock...? Try /locktypes for the list of lockables") else: bot.sendMessage(chat.id, "What are you trying to unlock...?") return ""
Example #16
Source File: locks.py From tgbot with GNU General Public License v3.0 | 4 votes |
def unlock(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 is_user_admin(chat, message.from_user.id): if len(args) >= 1: if args[0] in LOCK_TYPES: sql.update_lock(chat.id, args[0], locked=False) message.reply_text("Unlocked {} for everyone!".format(args[0])) return "<b>{}:</b>" \ "\n#UNLOCK" \ "\n<b>Admin:</b> {}" \ "\nUnlocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) elif args[0] in RESTRICTION_TYPES: sql.update_restriction(chat.id, args[0], locked=False) """ members = users_sql.get_chat_members(chat.id) if args[0] == "messages": unrestr_members(bot, chat.id, members, media=False, other=False, previews=False) elif args[0] == "media": unrestr_members(bot, chat.id, members, other=False, previews=False) elif args[0] == "other": unrestr_members(bot, chat.id, members, previews=False) elif args[0] == "previews": unrestr_members(bot, chat.id, members) elif args[0] == "all": unrestr_members(bot, chat.id, members, True, True, True, True) """ message.reply_text("Unlocked {} for everyone!".format(args[0])) return "<b>{}:</b>" \ "\n#UNLOCK" \ "\n<b>Admin:</b> {}" \ "\nUnlocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) else: message.reply_text("What are you trying to unlock...? Try /locktypes for the list of lockables") else: bot.sendMessage(chat.id, "What are you trying to unlock...?") return ""