Skip to content

Commit

Permalink
Embed画像保存機能の改善
Browse files Browse the repository at this point in the history
- 同じ画像URLは1枚に集約(:largeも同じとみなす)
- embedのset_imageを利用し複数枚をいい感じに表示させるよう対処(ノンドキュメントなやつらしいので壊れる可能性あり)
  • Loading branch information
tetsuya-ki committed Dec 31, 2023
1 parent 3761b78 commit bfc7597
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cogs/onmessagecog.py
Expand Up @@ -58,6 +58,7 @@ async def save_message_file(self, targetMessage: discord.Message):
return

embeds = []
before_embeds_url = ''
for embed in targetMessage.embeds:
current_path = os.path.dirname(os.path.abspath(__file__))
saved_path = ''.join([current_path, os.sep, self.FILEPATH.replace('/', os.sep)])
Expand All @@ -72,18 +73,19 @@ async def save_message_file(self, targetMessage: discord.Message):
# LOG.debug(embed.image)
# LOG.debug('filepath:' + saved_path)
LOG.info(dicted_data)
if img_url:
if img_url is not None and before_embeds_url != img_url:
path = await self.savefile.download_file_to_dir(img_url, saved_path)
before_embeds_url = img_url.replace(':large','')
if path is not None:
embed_data = discord.Embed()
embed_data.set_thumbnail(url=f'attachment://{path}')
embed_data = discord.Embed(url='https://discord.com')
embed_data.set_image(url=f'attachment://{path}')
embeds.append(embed_data)
full_path = saved_path + os.sep + path
files.append(discord.File(full_path, filename=path))
LOG.debug('save file: ' + full_path)
else:
LOG.debug('url is empty.')
return
continue

# チャンネルにファイルを添付する
if (len(files) > 0):
Expand Down

0 comments on commit bfc7597

Please sign in to comment.