def new_fed(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message fednam = message.text[len('/newfed '):] if not fednam == '': fed_id = str(uuid.uuid4()) fed_name = fednam LOGGER.info(fed_id) #if fednam == 'Name': # fed_id = "Name" x = sql.new_fed(user.id, fed_name, fed_id) if not x: update.effective_message.reply_text( tld( chat.id, "Big F! There is an error while creating Federations, Kindly get into my support group and ask what is going on!" )) return update.effective_message.reply_text("*You have successfully created a new federation!*"\ "\nName: `{}`"\ "\nID: `{}`" "\n\nUse command below to join the federation:" "\n`/joinfed {}`".format(fed_name, fed_id, fed_id), parse_mode=ParseMode.MARKDOWN) bot.send_message( MESSAGE_DUMP, "Federation <b>{}</b> has been created with ID: <pre>{}</pre>". format(fed_name, fed_id), parse_mode=ParseMode.HTML) else: update.effective_message.reply_text( tld(chat.id, "Please write federation name!"))
def __list_all_modules(): from os.path import dirname, basename, isfile import glob # This generates a list of modules in this folder for the * in __main__ to work. mod_paths = glob.glob(dirname(__file__) + "/*.py") all_modules = [ basename(f)[:-3] for f in mod_paths if isfile(f) and f.endswith(".py") and not f.endswith('__init__.py') ] if LOAD or NO_LOAD: to_load = LOAD if to_load: if not all( any(mod == module_name for module_name in all_modules) for mod in to_load): LOGGER.error("Invalid load order names. Quitting.") quit(1) else: to_load = all_modules if NO_LOAD: LOGGER.info("Not loading: {}".format(NO_LOAD)) return [item for item in to_load if item not in NO_LOAD] return to_load return all_modules
def main(): #test_handler = CommandHandler("test", test) #Unused variable start_handler = CommandHandler("start", start, pass_args=True) help_handler = CommandHandler("help", get_help) help_callback_handler = CallbackQueryHandler(help_button, pattern=r"help_") start_callback_handler = CallbackQueryHandler(send_start, pattern=r"bot_start") dispatcher.add_handler(start_callback_handler) cntrl_panel = CommandHandler("controlpanel", control_panel) cntrl_panel_callback_handler = CallbackQueryHandler(control_panel, pattern=r"cntrl_panel") dispatcher.add_handler(cntrl_panel_callback_handler) dispatcher.add_handler(cntrl_panel) settings_handler = CommandHandler("settings", get_settings) settings_callback_handler = CallbackQueryHandler(settings_button, pattern=r"stngs_") migrate_handler = MessageHandler(Filters.status_update.migrate, migrate_chats) # dispatcher.add_handler(test_handler) dispatcher.add_handler(start_handler) dispatcher.add_handler(help_handler) dispatcher.add_handler(settings_handler) dispatcher.add_handler(help_callback_handler) dispatcher.add_handler(settings_callback_handler) dispatcher.add_handler(migrate_handler) # dispatcher.add_error_handler(error_callback) # add antiflood processor Dispatcher.process_update = process_update if WEBHOOK: LOGGER.info("Using webhooks.") updater.start_webhook(listen="0.0.0.0", port=PORT, url_path=TOKEN) if CERT_PATH: updater.bot.set_webhook(url=URL + TOKEN, certificate=open(CERT_PATH, 'rb')) else: updater.bot.set_webhook(url=URL + TOKEN) else: LOGGER.info("Using long polling.") # updater.start_polling(timeout=15, read_latency=4, clean=True) updater.start_polling(poll_interval=0.0, timeout=10, clean=True, bootstrap_retries=-1, read_latency=3.0) updater.idle()
from bl4ckdr4g0n.modules.disable import DisableAbleCommandHandler import bl4ckdr4g0n.modules.sql.feds_sql as sql from bl4ckdr4g0n.modules.translations.strings import tld from bl4ckdr4g0n.modules.connection import connected # Hello bot owner, I spended for feds many hours of my life, Please don't remove this if you still respect MrYacha and peaktogoo # Federation by MrYacha 2018-2019 # Federation rework in process by Mizukito Akito 2019 # Time spended on feds = 10h by #MrYacha # Time spended on reworking on the whole feds = 20+ hours by @peaktogoo LOGGER.info( "Original federation module by MrYacha, reworked by Mizukito Akito (@peaktogoo) on Telegram." ) FBAN_ERRORS = { "User is an administrator of the chat", "Chat not found", "Not enough rights to restrict/unrestrict chat member", "User_not_participant", "Peer_id_invalid", "Group chat was deactivated", "Need to be inviter of a user to kick it from a basic group", "Chat_admin_required", "Only the creator of a basic group can kick group administrators", "Channel_private", "Not in the chat" } UNFBAN_ERRORS = { "User is an administrator of the chat", "Chat not found",
# Stop processing with any other handler. except DispatcherHandlerStop: self.logger.debug( 'Stopping further handlers due to DispatcherHandlerStop') break # Dispatch any error. except TelegramError as te: self.logger.warning( 'A TelegramError was raised while processing the Update') try: self.dispatch_error(update, te) except DispatcherHandlerStop: self.logger.debug('Error handler stopped further handlers') break except Exception: self.logger.exception( 'An uncaught error was raised while handling the error') # Errors should not stop the thread. except Exception: self.logger.exception( 'An uncaught error was raised while processing the update') if __name__ == '__main__': LOGGER.info("Successfully loaded modules: " + str(ALL_MODULES)) LOGGER.info("Successfully loaded") main()
mod_paths = glob.glob(dirname(__file__) + "/*.py") all_modules = [ basename(f)[:-3] for f in mod_paths if isfile(f) and f.endswith(".py") and not f.endswith('__init__.py') ] if LOAD or NO_LOAD: to_load = LOAD if to_load: if not all( any(mod == module_name for module_name in all_modules) for mod in to_load): LOGGER.error("Invalid load order names. Quitting.") quit(1) else: to_load = all_modules if NO_LOAD: LOGGER.info("Not loading: {}".format(NO_LOAD)) return [item for item in to_load if item not in NO_LOAD] return to_load return all_modules ALL_MODULES = sorted(__list_all_modules()) LOGGER.info("Modules to load: %s", str(ALL_MODULES)) __all__ = ALL_MODULES + ["ALL_MODULES"]