fix
This commit is contained in:
parent
54016c2f0c
commit
bae521dd10
@ -45,7 +45,8 @@ class ChannelHelperBotModuleConfig(TelegramBotModuleConfig):
|
|||||||
raise RuntimeError('Could not load image')
|
raise RuntimeError('Could not load image')
|
||||||
im = Image.open(f) # type: Image.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
|
return False
|
||||||
|
|
||||||
width, height = im.size
|
width, height = im.size
|
||||||
@ -57,10 +58,10 @@ class ChannelHelperBotModuleConfig(TelegramBotModuleConfig):
|
|||||||
im.save(fpath)
|
im.save(fpath)
|
||||||
if self.queued:
|
if self.queued:
|
||||||
m = bot.send_photo(config.tmp_uploads_chat_id, open(fpath, 'rb'))
|
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)
|
QueuedItem.objects.create(config=self, type='photo', args=json.dumps([m.photo[-1].file_id]), message_id=m.message_id, image_hash=image_hash)
|
||||||
i.save()
|
|
||||||
else:
|
else:
|
||||||
bot.send_photo(self.chat_id, open(fpath, 'rb'))
|
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
|
return True
|
||||||
|
|
||||||
def periodic_task(self, bot: Bot):
|
def periodic_task(self, bot: Bot):
|
||||||
@ -168,3 +169,5 @@ class QueuedItem(models.Model):
|
|||||||
|
|
||||||
def send(self, bot: Bot):
|
def send(self, bot: Bot):
|
||||||
getattr(bot, 'send_' + self.type)(self.config.chat_id, *json.loads(self.args))
|
getattr(bot, 'send_' + self.type)(self.config.chat_id, *json.loads(self.args))
|
||||||
|
self.processed = True
|
||||||
|
self.save()
|
||||||
|
Loading…
Reference in New Issue
Block a user