def __init__(self, client: pyrogram.Client, shared_config_callback=None):
     self.client = client
     client.add_handler(RawUpdateHandler(self._process_raw_update))
     self.shared_config_callback = shared_config_callback
     self.voips = {}
     voip = VoIP()
     self.max_layer = voip.get_connection_max_layer()
     if shared_config_callback:
         voip.set_shared_config(json.dumps(shared_config_callback({})))
Exemple #2
0
    def __init__(self, client: Optional[Client] = None,
                 conn: Optional[MySqlDB] = None,
                 other_client: Optional[Union[Client, bool]] = None):
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(level=logging.DEBUG)

        config = ConfigParser()
        config.read('config.ini')

        self.filter_chat: List[int] = list(map(int, config['filters']['chat'].split(', ')))
        self.filter_user: List[int] = list(map(int, config['filters']['user'].split(', ')))

        self.logger.debug('Filter chat %s', repr(self.filter_chat))
        self.logger.debug('Filter user %s', repr(self.filter_user))

        self.other_client = other_client

        self.owner = int(config['account']['owner'])

        if client is None:
            self.client = Client(
                session_name='history_index',
                api_hash=config['account']['api_hash'],
                api_id=config['account']['api_id']
            )
            if isinstance(other_client, bool) and other_client:
                self.other_client=Client(
                    session_name='other_session',
                    api_hash=config['account']['api_hash'],
                    api_id=config['account']['api_id']
                )
        else:
            self.client = client

        if self.other_client is None:
            self.other_client = self.client

        self.bot_id = 0

        if conn is None:
            self.conn = MySqlDB(
                config['mysql']['host'],
                config['mysql']['username'],
                config['mysql']['passwd'],
                config['mysql']['history_db'],
            )
            self.bot_id = int(config['account']['indexbot_token'].split(':')[0])
            self._init = True
        else:
            self.conn = conn
            self._init = False

        self.media_lookup_channel = int(config['account']['media_send_target'])
        self.trackers = task.MsgTrackerThreadClass(
            self.client,
            self.conn,
            self.check_filter,
            notify = task.NotifyClass(self.other_client, self.owner),
            other_client = self.other_client,
        )

        self.client.add_handler(MessageHandler(self.pre_process), 888)
        self.client.add_handler(MessageHandler(self.handle_all_message), 888)
        self.client.add_handler(RawUpdateHandler(self.handle_raw_update), 999)

        self.index_dialog = iter_user_messages(self)

        self.logger.info('History indexer initialize success')
Exemple #3
0
 def __init__(self, client: pyrogram.Client, receive_calls=True):
     self.client = client
     self.incoming_call_handlers = []
     if receive_calls:
         client.add_handler(RawUpdateHandler(self.update_handler), -1)
     client.on_message()
            time = datetime.datetime.fromtimestamp(update.status.was_online)
            result = '[{}] {} is Offline'.format(time, name)
        writetofile(result)


def printmessage(user, msg):
    if user.last_name is None:
        name = user.first_name
    else:
        name = user.first_name + ' ' + user.last_name
    now = datetime.datetime.now()
    result = '[{:%Y-%m-%d %H:%M:%S}] {}{}'.format(now, name, msg)
    writetofile(result)


def update_handler(client, update, users, chats):
    checknewmessage(update, users)
    checkonline(client, update)
    checktyping(client, update)
    checkreadmessage(client, update)


app = Client(session_name="session",
             api_id=123291,
             api_hash="7351c78aa85f88948bdd8a32faaf939a",
             phone_number="380951476392",
             password="******")
app.start()
app.add_handler(RawUpdateHandler(update_handler))
app.idle()
Exemple #5
0
def configure_voip(cnf):
    cnf['audio_init_bitrate'] = 80000
    cnf['audio_max_bitrate'] = 100000
    cnf['audio_min_bitrate'] = 60000
    cnf['audio_bitrate_step_decr'] = 5000
    cnf['audio_bitrate_step_incr'] = 5000
    return cnf


client = pyrogram.Client('session', 'app_id', 'app_hash', ipv6=True)
calls = PyrogramWrapper(client, configure_voip)


def accept_call(cl, update, users, chats):
    if isinstance(update, UpdatePhoneCall):
        pc = update.phone_call
        voip = calls.get_voip(pc.id)
        if voip:
            if voip.get_call_state() == VoIP.CALL_STATE_INCOMING:
                print(pc.admin_id, 'is calling')

                voip.accept()
                voip.play('input.raw')
                voip.play_on_hold(['input.raw'])
                voip.set_output_file('output.raw')


client.start()
client.add_handler(RawUpdateHandler(accept_call))
client.idle()
    def __init__(self):

        self.client = Client("Listener")

        self.client.add_handler(RawUpdateHandler(self.processUpdate))