Exemplo n.º 1
0
 def __init__(self, bot=None, config=None):
     TelegramHandler.__init__(self, bot, config)
     self.announceListFile = "announce.dat"
     self.announceList = {}
     self._loadAnnounce()
     try:
         self.sources = self.config['admins'] + self.config['sources']
     except KeyError:
         self.sources = ()
Exemplo n.º 2
0
 def __init__(self, bot=None, config=None):
     TelegramHandler.__init__(self, bot, config)
     
     try:
         self.sources = config['sources']
     except KeyError:
         self.sources = ()
     self.filelistfile = "files.txt"
     self.filelist = {}
     self._loadFileList()
Exemplo n.º 3
0
 def update(self, update):
     TelegramHandler.update(self, update)
     bot = self.bot
     try:
         from_id = update['message']['from']['id']
         chat_id = update['message']['chat']['id']
         text = update['message']['text']
     except KeyError:
         pass
     else:
         if text.startswith("/get "):
             cmd = text.split(" ", 1)
             fid, fname = self._findFileRe(cmd[1])
             if fid:
                 try:
                     bot.sendMessage(chat_id, fname)
                     bot.sendDocument(chat_id, fid)
                 except telegram.Error:
                     logger.exception("document failed to send")
         elif text.startswith("/search "):
             cmd = text.split(" ", 1)
             if from_id == chat_id:
                 maxresults = 30
             else:
                 maxresults = 10
             try:
                 results = self._findFilesRe(cmd[1], maxresults=maxresults)
             except RegexError as e:
                 bot.sendMessage(chat_id, e.message)
                 return
             if results:
                 results = [r[1] for r in results]
                 results = sorted(results)
                 response = "\n".join(results)
                 bot.sendMessage(chat_id, response)
                 
     try:
         from_id = update['message']['from']['id']
         chat_id = update['message']['chat']['id']
         document = update['message']['document']
         fid = document['file_id']
         fname = document['file_name']
     except KeyError:
         pass
     else:
         logger.debug("Document: [{0}]{1}".format(fid, fname))
         if from_id in self.sources:
             logger.info("Recieved: {0}".format(fname))
             self._addFile(fid, fname)
             bot.sendMessage(chat_id, fname)
             
     try:
         query = update['inline_query']
         query_id = query['id']
         query_offset = query['offset']
         query_text = query['query']
     except KeyError:
         pass
     else:
         try:
             self._inlineQuery(query_id, query_text, query_offset)
         except Error:
             logger.exception("error while handling inline query {0}".format(query))