support sending gifs via rpc
This commit is contained in:
@@ -3,6 +3,7 @@ import logging
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from telegram import Bot
|
||||
from telegram.error import RetryAfter
|
||||
|
||||
from config.celery import app
|
||||
@@ -39,3 +40,35 @@ def upload_image_rpc(self, queued_image_pk, fpath, caption):
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
raise self.retry(exc=e, countdown=5)
|
||||
|
||||
|
||||
@app.task(bind=True)
|
||||
def upload_animation_rpc(self, queued_image_pk, fpath, caption):
|
||||
from .modules.channel_helper import QueuedItem
|
||||
try:
|
||||
logging.warning(f'Processing upload task for queued animation item #{queued_image_pk}')
|
||||
qi = QueuedItem.objects.get(pk=queued_image_pk)
|
||||
bot = qi.config.bot.get_bot()
|
||||
if qi.config.queued:
|
||||
m = bot.send_animation(
|
||||
config.tmp_uploads_chat_id,
|
||||
open(fpath, 'rb'),
|
||||
caption=caption,
|
||||
)
|
||||
qi.message_id = m.message_id
|
||||
qi.args = json.dumps([m.animation.file_id])
|
||||
qi.save()
|
||||
else:
|
||||
bot.send_animation(
|
||||
qi.config.chat_id,
|
||||
open(fpath, 'rb'),
|
||||
caption=caption,
|
||||
)
|
||||
qi.processed = True
|
||||
qi.save()
|
||||
os.unlink(fpath)
|
||||
except RetryAfter as e:
|
||||
raise self.retry(exc=e, countdown=int(e.retry_after))
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
raise self.retry(exc=e, countdown=5)
|
||||
|
Reference in New Issue
Block a user