This commit is contained in:
bakatrouble 2022-08-08 04:42:13 +03:00
parent 54016c2f0c
commit bae521dd10

View File

@ -45,7 +45,8 @@ class ChannelHelperBotModuleConfig(TelegramBotModuleConfig):
raise RuntimeError('Could not load image')
im = Image.open(f) # type: Image.Image
if self.queued_items.filter(image_hash=imagehash.phash(im), type='photo').count() > 0:
image_hash = imagehash.phash(im)
if self.queued_items.filter(image_hash=image_hash, type='photo').count() > 0:
return False
width, height = im.size
@ -57,10 +58,10 @@ class ChannelHelperBotModuleConfig(TelegramBotModuleConfig):
im.save(fpath)
if self.queued:
m = bot.send_photo(config.tmp_uploads_chat_id, open(fpath, 'rb'))
i = QueuedItem(config=self, type='photo', args=json.dumps([m.photo[-1].file_id]), message_id=m.message_id)
i.save()
QueuedItem.objects.create(config=self, type='photo', args=json.dumps([m.photo[-1].file_id]), message_id=m.message_id, image_hash=image_hash)
else:
bot.send_photo(self.chat_id, open(fpath, 'rb'))
QueuedItem.objects.create(config=self, type='photo', args=json.dumps([]), image_hash=image_hash, processed=True)
return True
def periodic_task(self, bot: Bot):
@ -168,3 +169,5 @@ class QueuedItem(models.Model):
def send(self, bot: Bot):
getattr(bot, 'send_' + self.type)(self.config.chat_id, *json.loads(self.args))
self.processed = True
self.save()