def __init__(self, instance_id: InstanceID = None): super().__init__(instance_id) session_path = efb_utils.get_data_path( self.channel_id) / "session.pickle" try: data = pickle.load(session_path.open('rb')) self.client = EFMSClient(self, None, None, session_cookies=data) except FileNotFoundError: raise EFBException( self._("Session not found, please authorize your account.\n" "To do so, run: efms-auth")) except FBchatUserError as e: message = str(e) + "\n" + \ self._("You may need to re-authorize your account.\n" + "To do so, run: efms-auth") raise EFBException(message) self.load_config() self.chat_manager: EFMSChatManager = EFMSChatManager(self) self.flag: ExperimentalFlagsManager = ExperimentalFlagsManager(self) self.master_message: MasterMessageManager = MasterMessageManager(self) self.extra_functions: ExtraFunctionsManager = ExtraFunctionsManager( self) # Initialize list of chat from server self.get_chats() # Monkey patching Thread.__eq__ = lambda a, b: a.uid == b.uid
def __init__(self, instance_id: str = None): super().__init__(instance_id) storage_path = utils.get_data_path(self.middleware_id) config_path = utils.get_config_path(self.middleware_id) if not os.path.exists(storage_path): os.makedirs(storage_path) if not os.path.exists(config_path): raise EFBException("Filter middleware is not configured.") else: config = yaml.safe_load(open(config_path, encoding="UTF-8")) self.config_version = 0 self.match_mode = config.get("match_mode") # fuzz and exact if self.match_mode is None: self.match_mode = "fuzz" self.logger = logging.getLogger("xzsk2.filter") hdlr = logging.FileHandler('./xzsk2.filter.log', encoding="UTF-8") formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) self.logger.addHandler(hdlr) self.logger.setLevel(logging.ERROR)
def __init__(self, instance_id: str = None): """ Initialization. """ super().__init__(instance_id) # Check PIL support for WebP Image.init() if 'WEBP' not in Image.ID: raise EFBException( self._( "WebP support of Pillow is required.\n" "Please refer to Pillow Documentation for instructions.\n" "https://pillow.readthedocs.io/")) # Suppress debug logs from dependencies logging.getLogger('requests').setLevel(logging.CRITICAL) logging.getLogger('urllib3').setLevel(logging.CRITICAL) logging.getLogger('telegram.bot').setLevel(logging.CRITICAL) logging.getLogger( 'telegram.vendor.ptb_urllib3.urllib3.connectionpool').setLevel( logging.CRITICAL) # Set up logger self.logger: logging.Logger = logging.getLogger(__name__) # Load configs self.load_config() # Load predefined MIME types mimetypes.init(files=["mimetypes"]) # Initialize managers self.flag: ExperimentalFlagsManager = ExperimentalFlagsManager(self) self.db: DatabaseManager = DatabaseManager(self) self.bot_manager: TelegramBotManager = TelegramBotManager(self) # self.voice_recognition: VoiceRecognitionManager = VoiceRecognitionManager(self) self.chat_binding: ChatBindingManager = ChatBindingManager(self) self.commands: CommandsManager = CommandsManager(self) self.master_messages: MasterMessageProcessor = MasterMessageProcessor( self) self.slave_messages: SlaveMessageProcessor = SlaveMessageProcessor( self) if not self.flag('auto_locale'): self.translator = translation("efb_telegram_master", resource_filename( 'efb_telegram_master', 'locale'), fallback=True) # Basic message handlers self.bot_manager.dispatcher.add_handler( GlobalCommandHandler("start", self.start, pass_args=True)) self.bot_manager.dispatcher.add_handler( telegram.ext.CommandHandler("help", self.help)) self.bot_manager.dispatcher.add_handler( GlobalCommandHandler("info", self.info)) self.bot_manager.dispatcher.add_handler( telegram.ext.CallbackQueryHandler( self.bot_manager.session_expired)) self.bot_manager.dispatcher.add_error_handler(self.error) self.rpc_utilities = RPCUtilities(self)
def __init__(self, instance_id: InstanceID = None): """ Initialization. """ super().__init__(instance_id) # Check PIL support for WebP Image.init() if 'WEBP' not in Image.ID or not WebPImagePlugin.SUPPORTED: raise EFBException( self._( "WebP support of Pillow is required.\n" "Please refer to Pillow Documentation for instructions.\n" "https://pillow.readthedocs.io/")) # Suppress debug logs from dependencies logging.getLogger('requests').setLevel(logging.CRITICAL) logging.getLogger('urllib3').setLevel(logging.CRITICAL) logging.getLogger('telegram.bot').setLevel(logging.CRITICAL) logging.getLogger( 'telegram.vendor.ptb_urllib3.urllib3.connectionpool').setLevel( logging.CRITICAL) # Set up logger self.logger: logging.Logger = logging.getLogger(__name__) # Load configs self.load_config() # Load predefined MIME types mimetypes.init(files=["mimetypes"]) # Initialize managers self.flag: ExperimentalFlagsManager = ExperimentalFlagsManager(self) self.db: DatabaseManager = DatabaseManager(self) self.chat_manager: ChatObjectCacheManager = ChatObjectCacheManager( self) self.chat_dest_cache: ChatDestinationCache = ChatDestinationCache( self.flag("send_to_last_chat")) self.bot_manager: TelegramBotManager = TelegramBotManager(self) self.commands: CommandsManager = CommandsManager(self) self.chat_binding: ChatBindingManager = ChatBindingManager(self) self.slave_messages: SlaveMessageProcessor = SlaveMessageProcessor( self) if not self.flag('auto_locale'): self.translator = translation("efb_telegram_master", resource_filename( 'efb_telegram_master', 'locale'), fallback=True) # Basic message handlers non_edit_filter = Filters.update.message | Filters.update.channel_post self.bot_manager.dispatcher.add_handler( CommandHandler("start", self.start, filters=non_edit_filter)) self.bot_manager.dispatcher.add_handler( CommandHandler("help", self.help, filters=non_edit_filter)) self.bot_manager.dispatcher.add_handler( CommandHandler("info", self.info, filters=non_edit_filter)) self.bot_manager.dispatcher.add_handler( CallbackQueryHandler(self.void_callback_handler, pattern="void")) self.bot_manager.dispatcher.add_handler( CallbackQueryHandler(self.bot_manager.session_expired)) self.bot_manager.dispatcher.add_handler( CommandHandler("react", self.react, filters=non_edit_filter)) # Register master message handlers after commands to prevent commands # commands to be delivered as messages self.master_messages: MasterMessageProcessor = MasterMessageProcessor( self) self.bot_manager.dispatcher.add_error_handler(self.error) self.rpc_utilities = RPCUtilities(self)