def forwardMessage(self, forward_dict):
     try:
         url = self.bot_request_url + "forwardMessage"
         message_dict = self.Execute(url, params=forward_dict)
         return Message(message_dict)
     except:
         raise MyError("Unable to forward the message")
 def sendLocation(self, location_dict):
     try:
         url = self.bot_request_url + "sendLocation"
         tmp_dict = self.Execute(url, location_dict)
         return Message(tmp_dict)
     except:
         raise MyError("Unable to send the location")
 def sendMessage(self, send_dict):
     try:
         url = self.bot_request_url + "sendMessage"
         message_dict = self.Execute(url, params=send_dict)
         return Message(message_dict)
     except:
         raise MyError("Unable to send the message")
Exemplo n.º 4
0
 def _handle_rutracker_download(self, incoming_message):
     if not self.rutracker.logged_in:
         self.rutracker.login()
     filename = self.rutracker.download(incoming_message.text[3:])
     self.log.info('Starting {}'.format(filename))
     self._reply_to(incoming_message,
                    Message('Начал качать. Статус загрузок: /status'))
Exemplo n.º 5
0
 def handle_incoming_message(self, incoming_message):
     if incoming_message.text.startswith('/'):
         if incoming_message.text == '/start':
             ans = Message(
                 'Я ищу фильмы на rutracker.org и качаю их на NAS. Отправь название фильма.'
             )
             self._reply_to(incoming_message, ans)
         elif incoming_message.text == '/help':
             ans = Message('Отправь мне название фильма.')
             self._reply_to(incoming_message, ans)
         elif incoming_message.text == '/status':
             self._handle_download_status(incoming_message)
         elif incoming_message.text.startswith('/dl'):
             self._handle_rutracker_download(incoming_message)
     else:
         self._handle_rutracker_search(incoming_message)
Exemplo n.º 6
0
 def _callback_query_from_json(callback_query_j):
     message = Message(
         None,
         chat_id=callback_query_j['message']['chat']['id'],
         from_user_id=callback_query_j['message']['from']['id'],
         message_id=callback_query_j['message']['message_id'])
     return CallbackQuery(callback_query_j['data'], message=message)
Exemplo n.º 7
0
 def syno_tasks_to_message(self, tasks, as_existing_message=None):
     message_body = self._format_syno_tasks(tasks)
     refresh = InlineKeyboardButton(emoji['Refresh'],
                                    self.CallbackCommand.refresh)
     reply_markup = ReplyMarkup(inline_keyboard=[[refresh]])
     if as_existing_message:
         as_existing_message.text = message_body
         as_existing_message.reply_markup = reply_markup
         as_existing_message.parse_mode = 'Markdown'
         return as_existing_message
     return Message(message_body,
                    reply_markup=reply_markup,
                    parse_mode='Markdown')
 def sendVideo(self, param_dict, video_path):
     try:
         header = "video/mp4"
         filename = GetFormat(video_path, "/")
         m = MultipartEncoder(
             fields={"video": (filename, open(video_path, "rb"), header)})
         tmp_message = self.Execute(
             self.bot_request_url + "sendVideo",
             params=param_dict,
             data=m,
             headers={"Content-Type": m.content_type})
         return Message(tmp_message)
     except:
         raise MyError("Unable to send video")
 def sendSticker(self, param_dict, sticker_path):
     try:
         header = "image/webp"
         filename = GetFormat(sticker_path, "/")
         m = MultipartEncoder(fields={
             "sticker": (filename, open(sticker_path, "rb"), header)
         })
         tmp_message = self.Execute(
             self.bot_request_url + "sendSticker",
             params=param_dict,
             data=m,
             headers={"Content-Type": m.content_type})
         return Message(tmp_message)
     except:
         raise MyError("Unable to send sticker")
Exemplo n.º 10
0
 def sendDocument(self, param_dict, document_path):
     try:
         header = "text/plain"
         filename = GetFormat(document_path, "/")
         m = MultipartEncoder(fields={
             "document": (filename, open(document_path, "rb"), header)
         })
         tmp_message = self.Execute(
             self.bot_request_url + "sendDocument",
             params=param_dict,
             data=m,
             headers={"Content-Type": m.content_type})
         return Message(tmp_message)
     except:
         raise MyError("Unable to send document")
Exemplo n.º 11
0
 def search_result_page_to_message(self,
                                   search_result_page,
                                   as_existing_message=None):
     message_body = self._format_torrents(search_result_page.torrents)
     footer = '```\n\n--------- {} / {} ---------```'.format(
         search_result_page.number(), search_result_page.of())
     first = InlineKeyboardButton(emoji['Fast Reverse Button'],
                                  self.CallbackCommand.first)
     previous = InlineKeyboardButton(emoji['Reverse Button'],
                                     self.CallbackCommand.previous)
     next = InlineKeyboardButton(emoji['Play Button'],
                                 self.CallbackCommand.next)
     last = InlineKeyboardButton(emoji['Fast-Forward Button'],
                                 self.CallbackCommand.last)
     reply_markup = ReplyMarkup(
         inline_keyboard=[[first, previous, next, last]])
     if as_existing_message:
         as_existing_message.text = message_body + footer
         as_existing_message.reply_markup = reply_markup
         as_existing_message.parse_mode = 'Markdown'
         return as_existing_message
     return Message(message_body + footer,
                    reply_markup=reply_markup,
                    parse_mode='Markdown')
Exemplo n.º 12
0
 def _message_from_json(message_j):
     return Message(message_j['text'],
                    chat_id=message_j['chat']['id'],
                    from_user_id=message_j['from']['id'])