Skip to content

Commit

Permalink
matrigram: Include sender when sending images/videos/audio
Browse files Browse the repository at this point in the history
Signed-off-by: Gal Pressman <galpressman@gmail.com>
  • Loading branch information
galpressman committed Jan 24, 2017
1 parent c26570b commit bcad446
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
27 changes: 15 additions & 12 deletions matrigram/bot.py
Expand Up @@ -518,9 +518,10 @@ def send_invite(self, client, room):
reply_markup=keyboard)

# temporary fixes are permanent, lets do it the hard way
def _workaround_sendPhoto(self, path, chat_id):
def _workaround_sendPhoto(self, sender, path, chat_id):
payload = {
'chat_id': chat_id
'chat_id': chat_id,
'caption': sender,
}

files = {
Expand All @@ -530,9 +531,10 @@ def _workaround_sendPhoto(self, path, chat_id):
base_url = BOT_BASE_URL.format(token=self._token, path='sendPhoto')
requests.post(base_url, params=payload, files=files)

def _workaround_sendAudio(self, path, chat_id):
def _workaround_sendAudio(self, sender, path, chat_id):
payload = {
'chat_id': chat_id
'chat_id': chat_id,
'caption': sender,
}

files = {
Expand All @@ -542,9 +544,10 @@ def _workaround_sendAudio(self, path, chat_id):
base_url = BOT_BASE_URL.format(token=self._token, path='sendAudio')
requests.post(base_url, params=payload, files=files)

def _workaround_sendVideo(self, path, chat_id):
def _workaround_sendVideo(self, sender, path, chat_id):
payload = {
'chat_id': chat_id
'chat_id': chat_id,
'caption': sender,
}

files = {
Expand All @@ -554,33 +557,33 @@ def _workaround_sendVideo(self, path, chat_id):
base_url = BOT_BASE_URL.format(token=self._token, path='sendVideo')
requests.post(base_url, params=payload, files=files)

def send_photo(self, path, client):
def send_photo(self, sender, path, client):
logger.info('path = %s', path)
chat_id = self._get_chat_id(client)
if not chat_id:
return

self.sendChatAction(chat_id, 'upload_photo')
self._workaround_sendPhoto(path, chat_id)
self._workaround_sendPhoto(sender, path, chat_id)
# self.sendPhoto(chat_id, open(path, 'rb'))

def send_voice(self, path, client):
def send_voice(self, sender, path, client):
logger.info('path = %s', path)
chat_id = self._get_chat_id(client)
if not chat_id:
return

self.sendChatAction(chat_id, 'upload_audio')
self._workaround_sendAudio(path, chat_id)
self._workaround_sendAudio(sender, path, chat_id)

def send_video(self, path, client):
def send_video(self, sender, path, client):
logger.info('path = %s', path)
chat_id = self._get_chat_id(client)
if not chat_id:
return

self.sendChatAction(chat_id, 'upload_video')
self._workaround_sendVideo(path, chat_id)
self._workaround_sendVideo(sender, path, chat_id)

def relay_typing(self, chat_id):
while True:
Expand Down
9 changes: 6 additions & 3 deletions matrigram/client.py
Expand Up @@ -257,16 +257,19 @@ def download_from_event(self, event):
return path

def forward_image_to_tb(self, event):
sender = event['sender'].split(':')[0].encode('utf-8')
path = self.download_from_event(event)
self.tb.send_photo(path, self)
self.tb.send_photo(sender, path, self)

def forward_voice_to_tb(self, event):
sender = event['sender'].split(':')[0].encode('utf-8')
path = self.download_from_event(event)
self.tb.send_voice(path, self)
self.tb.send_voice(sender, path, self)

def forward_video_to_tb(self, event):
sender = event['sender'].split(':')[0].encode('utf-8')
path = self.download_from_event(event)
self.tb.send_video(path, self)
self.tb.send_video(sender, path, self)

def forward_emote_to_tb(self, event):
sender = event['sender'].split(':')[0].encode('utf-8')
Expand Down

0 comments on commit bcad446

Please sign in to comment.