From bae521dd1033585c2671301142664e727e53e59e Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Mon, 8 Aug 2022 04:42:13 +0300 Subject: [PATCH] fix --- bots/modules/channel_helper.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bots/modules/channel_helper.py b/bots/modules/channel_helper.py index 92cbe96..8f2d9ff 100644 --- a/bots/modules/channel_helper.py +++ b/bots/modules/channel_helper.py @@ -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()