Ejemplo n.º 1
0
 async def _search_remote(self, query, max_results=5):
     if len(query) < 5:
         return []
     server_results = await self.client(SearchRequest(q=query, limit=max_results))
     results = []
     for user in server_results.users:
         puppet = pu.Puppet.get(user.id)
         await puppet.update_info(self, user)
         results.append((puppet, puppet.similarity(query)))
     results.sort(key=lambda tup: tup[1], reverse=True)
     return results[0:max_results]
def search_accounts(request, client):
    """
    Search accounts in Telegram
    :param request: text request to search
    :param client: telegram client obj
    :return: result obj
    """
    try:
        result = client(SearchRequest(request, 10))
        return result
    except Exception as e:
        logging.warning(e)
        return []
Ejemplo n.º 3
0
 def __init__(self, tg_client: TelegramClient, character: Character):
     super().__init__()
     self._tgClient = tg_client
     self._character = character
     self._send_queue = []
     self._lock = RLock()
     self._dialogs = self._tgClient.get_dialogs(100)
     self._cwBot = self._find_contact_by_username(config.CWBot)
     if not self._cwBot:
         self._cwBot = self._tgClient.invoke(SearchRequest(config.CWBot,
                                                           1)).users[0]
         self._tgClient.send_message(self._cwBot, '/start')
         self._tgClient.send_message(self._cwBot, '🇬🇵Черный замок🇬🇵')
     self._captchaBot = self._find_contact_by_username(config.CaptchaBot)
     if not self._captchaBot:
         self._captchaBot = self._tgClient.invoke(
             SearchRequest(config.CaptchaBot, 1)).users[0]
         self._tgClient.send_message(self._captchaBot, '/start')
     self._tradeBot = self._find_contact_by_username(config.TradeBot)
     if not self._tradeBot:
         self._tradeBot = self._tgClient.invoke(
             SearchRequest(config.TradeBot, 1)).users[0]
         self._tgClient.send_message(self._tradeBot, '/start')
     self._orderBot = self._find_contact_by_username(
         self._character.config.orderBot)
     if not self._orderBot:
         self._orderBot = self._tgClient.invoke(
             SearchRequest(self._character.config.orderBot, 1)).users[0]
         self._tgClient.send_message(self._orderBot, '/start')
     self._dataBot = self._find_contact_by_username(
         self._character.config.dataBot)
     if not self._dataBot:
         self._dataBot = self._tgClient.invoke(
             SearchRequest(self._character.config.dataBot, 1)).users[0]
         self._tgClient.send_message(self._dataBot, '/start')
     self._admin = self._find_contact_by_username(
         self._character.config.admin)
     if not self._admin:
         self._admin = self._tgClient.invoke(SearchRequest(self._character.config.admin, 1)).users[0] if \
             len(self._tgClient.invoke(SearchRequest(self._character.config.admin, 1)).users) else None
     self._orderGroup = self._find_contact_by_name(
         self._character.config.orderChat)
     if not self._admin:
         # Если юзера-админа не нашли, то админим сами
         self._admin = self._tgClient.session.user
     self._tgClient.add_update_handler(self._locked_receive)