예제 #1
0
        def decorator(func: Callable) -> Callable:
            if isinstance(self, pyrogram.Client):
                self.add_handler(pyrogram.RawUpdateHandler(func), group)
            else:
                func.handler = (pyrogram.RawUpdateHandler(func),
                                group if self is None else group)

            return func
예제 #2
0
    def __init__(self,
                 client: pyrogram.Client,
                 use_proxy_if_available: bool = True):
        if not client.is_started:
            raise RuntimeError('Client must be started first')
        self.client = client
        self.ctrl = VoIPController()
        self.ctrl_started = False
        self.call = None
        self.call_access_hash = None
        self.peer = None
        self.state = None
        self.dhc = self.get_dhc()
        self.a = None
        self.g_a = None
        self.g_a_hash = None
        self.b = None
        self.g_b = None
        self.g_b_hash = None
        self.auth_key = None
        self.key_fingerprint = None
        self.call_started_handlers = []
        self.call_discarded_handlers = []
        self.call_ended_handlers = []

        if use_proxy_if_available and client.proxy:
            proxy = self.client.proxy
            self.ctrl.set_proxy(proxy['hostname'], proxy['port'],
                                proxy['username'], proxy['password'])

        self._update_handler = pyrogram.RawUpdateHandler(self.process_update)
        self.client.add_handler(self._update_handler, -1)
예제 #3
0
        def decorator(func):
            handler = pyrogram.RawUpdateHandler(func)

            if isinstance(self, int):
                return handler, group if self is None else group

            if self is not None:
                self.add_handler(handler, group)

            return handler, group
예제 #4
0
        def decorator(func):
            if isinstance(func, tuple):
                func = func[0].callback

            handler = pyrogram.RawUpdateHandler(func)

            if isinstance(self, int):
                return handler, group if self is None else group

            if self is not None:
                self.add_handler(handler, group)

            return handler, group
예제 #5
0
파일: tgminer.py 프로젝트: Teriks/TGMiner
    def __init__(self, config: tgminer.config.TGMinerConfig):

        session_path_dir = os.path.dirname(config.session_path)

        self._config = config

        if session_path_dir:
            os.makedirs(session_path_dir, exist_ok=True)

        pyrogram.Client.UPDATES_WORKERS = config.updates_workers
        pyrogram.Client.DOWNLOAD_WORKERS = config.download_workers

        self._client = pyrogram.Client(config.session_path,
                                       api_id=config.api_key.id,
                                       api_hash=config.api_key.hash)

        self._client.add_handler(
            pyrogram.RawUpdateHandler(self._update_handler))

        os.makedirs(config.data_dir, exist_ok=True)

        self._indexdir = os.path.join(config.data_dir,
                                      TGMinerClient.INDEX_DIR_NAME)

        # interprocess lock only
        self._index_lock_path = os.path.join(config.data_dir,
                                             TGMinerClient.INTERPROCESS_MUTEX)

        self._index_lock = threading.Lock()

        try:
            os.makedirs(self._indexdir)
            self._index = whoosh.index.create_in(self._indexdir,
                                                 tgminer.fulltext.LogSchema)
        except OSError as e:
            if e.errno == errno.EEXIST:
                self._index = whoosh.index.open_dir(self._indexdir)
예제 #6
0
 def decorator(func):
     self.add_handler(pyrogram.RawUpdateHandler(func), group)
     return func