Images saved in Discord automatically expire #4

Open
opened 2 years ago by brejela · 0 comments
Owner

Images, when saved in discord, naturally expire after sometime, and deleting the "hosting" message makes the image itself disappear, this issue gets compounded with quotes over time, meaning that the older a message is, the more likely it is that a quoted image no longer exists.

It is CRUCIAL that a solution to that problem DOES NOT need any new supporting infrastructure.

One possible solution (For images hosted in discord):

  1. User uploads a link to some sort of media hosted in Discord (Ending in .png,.jpg and other extensions specified in f43520e51d/settings/config.py (L62) )
  2. The bot downloads the image in an specified directory by using requests and writing directly to a file:
import requests
url = 'https://media.discordapp.net/attachments/1007369896822317178/1189268533285236808/image.png'
file = requests.get(url)
filedir = str(os.environ.get('DOWNLOADED_QUOTES', '/mnt/downloadedquotes/') + '<quote id>.png'
open(filedir, 'wb').write(myfile.content)
  1. When the quote is called, the bot uploads the file:
#The quote will be saved in the database as "#FILE=/mnt/downloadedquotes/<id>.png", for example
if content[:6] == "#FILE=": 
	filedir = content[6:] 
	with open(filedir, 'rb') as f:
    	picture = discord.File(f)
    	return await bot.send(file=picture)

Naturally, we expect all quotes to be saved in the same table.

This solution will, naturally need to be replicated in all "quote-responding" references:

f43520e51d/utils/commands.py (L185)

f43520e51d/utils/commands.py (L215)

f43520e51d/utils/commands.py (L249)

Maybe it is also time to make this a single function :þ

Images, when saved in discord, naturally expire after sometime, and deleting the "hosting" message makes the image itself disappear, this issue gets compounded with quotes over time, meaning that the older a message is, the more likely it is that a quoted image no longer exists. It is **CRUCIAL** that a solution to that problem **DOES NOT** need any new supporting infrastructure. One possible solution (For images hosted in discord): 1. User uploads a link to some sort of media hosted in Discord (Ending in `.png`,`.jpg` and other extensions specified in https://brejela.club/gitea/neeble-club/neeble/src/commit/f43520e51db9db145813e4d6f294ac21a67b9d65/settings/config.py#L62 ) 2. The bot downloads the image in an specified directory by using `requests` and writing directly to a file: ```py import requests url = 'https://media.discordapp.net/attachments/1007369896822317178/1189268533285236808/image.png' file = requests.get(url) filedir = str(os.environ.get('DOWNLOADED_QUOTES', '/mnt/downloadedquotes/') + '<quote id>.png' open(filedir, 'wb').write(myfile.content) ``` 3. When the quote is called, the bot uploads the file: ```py #The quote will be saved in the database as "#FILE=/mnt/downloadedquotes/<id>.png", for example if content[:6] == "#FILE=": filedir = content[6:] with open(filedir, 'rb') as f: picture = discord.File(f) return await bot.send(file=picture) ``` Naturally, we expect all quotes to be saved in the same table. This solution will, naturally need to be replicated in all "quote-responding" references: https://brejela.club/gitea/neeble-club/neeble/src/commit/f43520e51db9db145813e4d6f294ac21a67b9d65/utils/commands.py#L185 https://brejela.club/gitea/neeble-club/neeble/src/commit/f43520e51db9db145813e4d6f294ac21a67b9d65/utils/commands.py#L215 https://brejela.club/gitea/neeble-club/neeble/src/commit/f43520e51db9db145813e4d6f294ac21a67b9d65/utils/commands.py#L249 Maybe it is also time to make this a single function :þ
brejela added this to the General media-quoting improvements project 2 years ago
brejela added the
enhancement
help wanted
labels 2 years ago
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: neeble-club/neeble#4
Loading…
There is no content yet.