Exemple #1
0
def private_peer(user_id):
    """Returns peer for user by user id

    :param user_id: user id
    :return: Peer object
    """
    return peers_pb2.Peer(type=peers_pb2.PEERTYPE_PRIVATE, id=user_id)
 def preprocessing_from_database(self):
     try:
         self.cursor.execute(
             "CREATE TABLE users (uid integer, gid integer)")
         self.connect.commit()
     except:
         print("Table 'users' already exist")
         self.cursor.execute("SELECT * FROM users")
         users = self.cursor.fetchall()
         for user in users:
             if user[0] not in self.tracked_users:
                 peer = peers_pb2.Peer(type=peers_pb2.PEERTYPE_PRIVATE,
                                       id=user[0])
                 self.tracked_users[user[0]] = User(
                     self.bot.manager.get_outpeer(peer), [user[1]])
             else:
                 self.tracked_users[user[0]].groups.append(user[1])
     try:
         self.cursor.execute(
             "CREATE TABLE reminder (time text, uid integer)")
         self.connect.commit()
     except:
         print("Table 'reminder' already exist")
         self.cursor.execute("SELECT * FROM reminder")
         reminder = self.cursor.fetchall()
         for remind in reminder:
             if remind[0] in self.reminder:
                 self.reminder[remind[0]].append(remind[1])
             else:
                 self.reminder[remind[0]] = [remind[1]]
             self.tracked_users[remind[1]].remind_time = remind[0]
Exemple #3
0
def group_peer(group_id):
    """Returns peer for group by group id

    :param group_id: group id
    :return: Peer object
    """
    return peers_pb2.Peer(type=peers_pb2.PEERTYPE_GROUP, id=group_id)
Exemple #4
0
def on_event(*params):
    uid = params[0].uid
    msg = bot.messaging.get_messages_by_id([params[0].mid])[0]
    peer = peers_pb2.Peer(type=peers_pb2.PEERTYPE_PRIVATE, id=uid)
    which_button = params[0].value
    if which_button in MONTHS or which_button in ["1", "2", "3", "4"]:
        send_events(peer, which_button)
    bot.messaging.update_message(msg, msg.message.textMessage.text)
 def cron(self):
     ticker = threading.Event()
     while not ticker.wait(self.cron_time):
         t = datetime.utcnow()
         self.cron_time = CRON_TIME - int(t.strftime("%S"))
         time = t.strftime("%H:%M")
         if time in self.reminder:
             for uid in self.reminder[time]:
                 peer = peers_pb2.Peer(type=peers_pb2.PEERTYPE_PRIVATE,
                                       id=uid)
                 self.send_mentions_for_user(peer)
Exemple #6
0
def get_peer(peer: Peer or AsyncTask) -> peers_pb2.Peer or None:
    if isinstance(peer, AsyncTask):
        from_task = peer.wait()
        if not hasattr(from_task, 'peer'):
            raise AttributeError("{} has not attribute 'peer'".format(type(from_task)))
        peer = from_task.peer
    if not isinstance(peer, Peer):
        raise AttributeError("peer must be {}, got {}.".format(Peer, type(peer)))
    if peer.type in [PeerType.PEERTYPE_PRIVATE, PeerType.PEERTYPE_GROUP]:
        return peers_pb2.Peer(id=peer.id, type=peer.type)
    else:
        raise UnknownPeerError("Unknown PeerType.")
 def on_event(self, *params):
     uid = params[0].uid
     peer = peers_pb2.Peer(type=peers_pb2.PEERTYPE_PRIVATE, id=uid)
     which_button = params[0].value
     msg = self.bot.messaging.get_messages_by_id([params[0].mid])[0]
     if which_button == "Start":
         self.on_click_start(int(params[0].id), peer, msg)
     elif which_button == "Stop":
         self.on_click_stop(int(params[0].id), peer, msg)
     elif params[0].id == "hours":
         self.on_select(peer, params[0].mid, msg, which_button, "")
     elif params[0].id == "minutes":
         self.on_select(peer, params[0].mid, msg, "", which_button)
Exemple #8
0
    def get_user_outpeer_by_id(self, uid):
        req = messaging_pb2.RequestLoadDialogs(
            min_date=0,
            limit=1,
            peers_to_load=[
                peers_pb2.Peer(type=peers_pb2.PEERTYPE_PRIVATE, id=uid)
            ])
        result = self.internal.messaging.LoadDialogs(req)

        for outpeer in result.user_peers:
            if outpeer.uid == uid:
                return peers_pb2.OutPeer(type=peers_pb2.PEERTYPE_PRIVATE,
                                         id=outpeer.uid,
                                         access_hash=outpeer.access_hash)
Exemple #9
0
    def get_user_by_id(self, uid):
        req = messaging_pb2.RequestLoadDialogs(
            min_date=0,
            limit=1,
            peers_to_load=[
                peers_pb2.Peer(type=peers_pb2.PEERTYPE_PRIVATE, id=uid)
            ])
        result = self.internal.messaging.LoadDialogs(req)
        users_list = self.internal.updates.GetReferencedEntitites(
            sequence_and_updates_pb2.RequestGetReferencedEntitites(
                users=list(result.user_peers)))

        for user in users_list.users:
            if hasattr(user, "id") and user.id == uid:
                return user
        return None
 def to_api(self) -> peers_pb2.Peer:
     return peers_pb2.Peer(id=self.id, type=self.type)
Exemple #11
0
 def get_user_peer_by_id(uid):
     return peers_pb2.Peer(type=peers_pb2.PEERTYPE_PRIVATE, id=uid)