def main(): """Start the bot.""" updater = Updater(TOKEN) dp = updater.dispatcher dp.add_handler(CommandHandler('delete', delete_handler)) dp.add_handler(MessageHandler(Filters.photo, photo_handler)) dp.add_handler(MessageHandler(Filters.entity("url"), url_handler)) dp.add_handler( MessageHandler(Filters.entity("text_link"), text_link_handler)) dp.add_handler(MessageHandler(Filters.caption_entity("url"), url_handler)) dp.add_handler( MessageHandler(Filters.caption_entity("text_link"), text_link_handler)) dp.add_handler(MessageHandler(Filters.forwarded, forwarded_handler)) dp.add_error_handler(error) # Start if WEBHOOK_URL: logger.info("Running in webhook mode") updater.start_webhook(listen="0.0.0.0", port=443, url_path=TOKEN) updater.bot.set_webhook(WEBHOOK_URL + TOKEN) else: logger.info("Running in long-polling mode") updater.start_polling() updater.idle()
def main(): global sites, storage defaults = Defaults(quote=True) urlFilter = Filters.entity('url') | Filters.entity( 'text_link') | Filters.caption_entity('url') | Filters.caption_entity( 'text_link') sites.load() # Set up the Updater updater = Updater(config.TOKEN, workers=32, use_context=True, defaults=defaults) # Get the dispatcher to register handlers dp = updater.dispatcher dp.add_handler( CommandHandler('start', start, config.adminFilter, run_async=True)) dp.add_handler( CommandHandler('ping', ping, config.adminFilter, run_async=True)) dp.add_handler( CommandHandler('help', get_help, config.adminFilter, run_async=True)) sites.register_commands(dp) dp.add_handler( CommandHandler('clear_downloads', clear_downloads, config.adminFilter, pass_args=True)) dp.add_handler( MessageHandler(config.adminFilter & urlFilter & (~Filters.update.channel_posts), collection_update, pass_chat_data=True, run_async=True)) # log all errors dp.add_error_handler(handle_error) if config.ENV == 'production': # Webhook mode print('Port number: ' + str(config.PORT) + '\n') updater.start_webhook(listen="0.0.0.0", port=config.PORT, url_path=config.TOKEN, webhook_url=config.WEBHOOK_URL + config.TOKEN) time.sleep(5) updater.bot.setWebhook(url=config.WEBHOOK_URL + config.TOKEN, allowed_updates=["message"]) time.sleep(5) #updater.bot.setWebhook(allowed_updates=["message"]) logger.info('Set webhook completed') else: # Polling mode updater.start_polling() logger.info('Started polling') storage.load() updater.idle()
def test_caption_entities_filter(self, update, message_entity): update.message.caption_entities = [message_entity] assert Filters.caption_entity(message_entity.type)(update) update.message.caption_entities = [] assert not Filters.caption_entity(MessageEntity.MENTION)(update) second = message_entity.to_dict() second['type'] = 'bold' second = MessageEntity.de_json(second, None) update.message.caption_entities = [message_entity, second] assert Filters.caption_entity(message_entity.type)(update) assert not Filters.entity(message_entity.type)(update)
def test_caption_entities_filter(self, message, message_entity): message.caption_entities = [message_entity] assert Filters.caption_entity(message_entity.type)(message) message.caption_entities = [] assert not Filters.caption_entity(MessageEntity.MENTION)(message) second = message_entity.to_dict() second['type'] = 'bold' second = MessageEntity.de_json(second, None) message.caption_entities = [message_entity, second] assert Filters.caption_entity(message_entity.type)(message) assert not Filters.entity(message_entity.type)(message)
LOCK_TYPES = { "audio": Filters.audio, "voice": Filters.voice, "document": Filters.document, "video": Filters.video, "contact": Filters.contact, "photo": Filters.photo, "url": Filters.entity(MessageEntity.URL) | Filters.caption_entity(MessageEntity.URL), "bots": Filters.status_update.new_chat_members, "forward": Filters.forwarded, "game": Filters.game, "location": Filters.location, "egame": Filters.dice, "rtl": "rtl", "button": "button", "inline":
from hitsuki.modules.helper_funcs.chat_status import can_delete, is_user_admin, user_not_admin, user_admin, \ bot_can_delete, is_bot_admin from hitsuki.modules.log_channel import loggable from hitsuki.modules.sql import users_sql from hitsuki.modules.translations.strings import tld LOCK_TYPES = {'sticker': Filters.sticker, 'audio': Filters.audio, 'voice': Filters.voice, 'document': Filters.document & ~Filters.animation, 'video': Filters.video, 'videonote': Filters.video_note, 'contact': Filters.contact, 'photo': Filters.photo, 'gif': Filters.animation, 'url': Filters.entity(MessageEntity.URL) | Filters.caption_entity(MessageEntity.URL), 'bots': Filters.status_update.new_chat_members, 'forward': Filters.forwarded, 'game': Filters.game, 'location': Filters.location, } GIF = Filters.animation OTHER = Filters.game | Filters.sticker | GIF MEDIA = Filters.audio | Filters.document | Filters.video | Filters.voice | Filters.photo MESSAGES = Filters.text | Filters.contact | Filters.location | Filters.venue | Filters.command | MEDIA | OTHER PREVIEWS = Filters.entity("url") RESTRICTION_TYPES = {'messages': MESSAGES, 'media': MEDIA, 'other': OTHER,
dispatcher.add_handler(CallbackQueryHandler(button_click), group=1) dispatcher.add_handler(CommandHandler("clear", clear_db, Filters.user(username=admins)), group=1) dispatcher.add_handler(CommandHandler("rem_admin", rem_admin, Filters.user(username=admins)), group=1) dispatcher.add_handler(CommandHandler("add_admin", add_admin, Filters.user(username=admins)), group=1) dispatcher.add_handler(CommandHandler("broadcast", broadcast, Filters.user(username=admins)), group=1) dispatcher.add_handler(CommandHandler("stats", stats, Filters.user(username=admins)), group=1) dispatcher.add_handler(CommandHandler("user_stats", user_stats, Filters.user(username=admins)), group=1) dispatcher.add_handler( CommandHandler(["stats", "upload", "admin", "broadcast"], non_admin, ~Filters.user(username=admins)), group=1) dispatcher.add_handler(MessageHandler( Filters.all & (~Filters.caption_entity("bot_command")), message), group=1) """updater.start_webhook(listen="0.0.0.0", port=PORT, url_path=TOKEN) updater.bot.set_webhook("https://dynamic-account-generator.herokuapp.com/")""" updater.start_polling() updater.idle()
Filters.voice, 'document': Filters.document & ~Filters.animation, 'video': Filters.video, 'videonote': Filters.video_note, 'contact': Filters.contact, 'photo': Filters.photo, 'gif': Filters.animation, 'url': Filters.entity(MessageEntity.URL) | Filters.caption_entity(MessageEntity.URL) | Filters.entity(MessageEntity.TEXT_LINK) | Filters.caption_entity(MessageEntity.TEXT_LINK), 'bots': Filters.status_update.new_chat_members, 'forward': Filters.forwarded, 'game': Filters.game, 'location': Filters.location, } GIF = Filters.animation OTHER = Filters.game | Filters.sticker | GIF MEDIA = Filters.audio | Filters.document | Filters.video | Filters.video_note | Filters.voice | Filters.photo
def main(): """Start the bot""" updater = Updater(telegram_key, request_kwargs=get_headers()) # Get the dispatcher to register handlers dp = updater.dispatcher jobs = updater.job_queue # Typing dp.add_handler(MessageHandler(Filters.private, typing), group=-1) # Welcome dp.add_handler( MessageHandler(Filters.status_update.new_chat_members, welcome, pass_job_queue=True)) dp.add_handler( RegexHandler(r'(/start[a-z-]*|{})'.format(MENU_ROADS), send_instructions)) dp.add_handler(RegexHandler(MENU_LINKS, bookmarks)) dp.add_handler( MessageHandler( (Filters.entity('hashtag') | Filters.caption_entity('hashtag')), hashtag)) dp.add_handler(RegexHandler(MENU_ADMIN, admin_menu)) dp.add_handler(RegexHandler(MENU_CHATS, chats_management)) dp.add_handler( RegexHandler(r'({}|{})'.format(MENU_SUBSCRIBE, MENU_UNSUBSCRIBE), update_subscription)) dp.add_handler(RegexHandler(MENU_RETURN, cancel, pass_user_data=True)) # Conversations dp.add_handler( ConversationHandler( entry_points=[RegexHandler(MENU_FEEDBACK, request_feedback)], states={ FEEDBACK_REQUESTED: [RegexHandler(r'^(?!⬅ Вернуться)', receive_feedback)] }, fallbacks=[RegexHandler(MENU_RETURN, cancel, pass_user_data=True)])) dp.add_handler( ConversationHandler( entry_points=[ RegexHandler(MENU_SEARCH_CLUB, search, pass_user_data=True), RegexHandler(MENU_SEARCH_RULES, search, pass_user_data=True) ], states={ SEARCH_QUERY_REQUESTED: [ RegexHandler(r'^(?!⬅ Вернуться)', run_search, pass_user_data=True) ] }, fallbacks=[RegexHandler(MENU_RETURN, cancel, pass_user_data=True)])) dp.add_handler( ConversationHandler( entry_points=[RegexHandler(MENU_TRANSLIT, transliterate)], states={ TRANSLITERATE_REQUESTED: [RegexHandler(r'^(?!⬅ Вернуться)', retrieve_transliteration)] }, fallbacks=[RegexHandler(MENU_RETURN, cancel, pass_user_data=True)])) # Callbacks dp.add_handler( CallbackQueryHandler(roadblock_callback, pattern=r'^road\w+')) dp.add_handler( CallbackQueryHandler(verify_user, pattern=r'not_bot', pass_job_queue=True)) dp.add_handler( CallbackQueryHandler(change_chats_page, pattern=r'chats_\d+')) dp.add_handler( CallbackQueryHandler(update_chat_subscription, pattern=r'chats_\D+')) dp.add_handler(CallbackQueryHandler(admin_menu, pattern=r'admin_return')) # This one will handle any random message dp.add_handler(MessageHandler(Filters.private, send_instructions)) # Checkin dp.add_handler(MessageHandler(Filters.private, add_user), group=1) dp.add_handler(MessageHandler(Filters.group, add_chat), group=1) # Logging errors dp.add_error_handler(error) # Adds repeating jobs if not enable_dev(): jobs.run_repeating(rss, 300) # Inline handler dp.add_handler(InlineQueryHandler(inline_search)) # Actually start the bot updater.start_polling() updater.idle()
from functions.classes import * # Initialised token from botfather updater = Updater('1033297905:AAF4KZfofsQNsdkDrHxoP15jgU5VSWAD4Tw', use_context=True) dispatcher = updater.dispatcher # Set up logging to report errors logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s -%(message)s', level=logging.INFO) # Added /start to work on demand dispatcher.add_handler(CommandHandler('start', start)) dispatcher.add_handler(MessageHandler(Filters.caption_entity("hashtag"))) # Added the /caps functionalities to the caps dispatcher.add_handler(CommandHandler('caps', caps)) # Added inline caps funcionalities dispatcher.add_handler(InlineQueryHandler(inline_caps)) # Added picture and video handler dispatcher.add_handler(MessageHandler(Filters.photo | Filters.video, picvid)) # Added some random dispatcher.add_handler(CommandHandler('owner', owner)) # Added filter to sticker dispatcher.add_handler(MessageHandler(Filters.sticker, sticker))