get-got / discord-downloader-go

A Discord bot program to download and otherwise handle files sent in Discord channels with extensive configuration. Can be used as a genuine Discord Bot or user account / self-bot
MIT License
271 stars 30 forks source link

Request: Add "saveMessages" option to capture Midjourney prompts #122

Closed kauffy closed 5 months ago

kauffy commented 6 months ago

I only use ddg for Midjourney. I only have it connected to channels that are used exclusively for Midjourney's bot.

Midjourney's file names begin with username, then part of the prompt, and then end with a job ID, but the prompt will be abbreviated to make room for the job ID-- it will also be completely stripped of URLs for image prompts.

However, the image attachment is attached to a message (I think always) that contains the full Midjourney prompt-- having an option to save the content of this message into a text file (.prompt?) that has the exact same name/location as the image file attached to it would be a really big help. This might make sense, also, for non-Midjourney users.

As a technical note, Midjourney updates the in-progress image using .webp, so I filtered the extension out so that I only get the finished .png-- it would make sense (perhaps as an option) to only save the message when really saving the attachment.

As it is now, often when I'm working, Midge will give me ephemeral messages for my images, so if I do almost anything, they disappear from Discord-- I also find it comes up a LOT that when I'm going through my images, that I want to quickly know what the whole prompt was. I may have hundreds of nearly-identical images with just slightly different prompts, but the differences in the prompts are truncated in the image name. I can dig them out of the archive, but that adds steps if we're not dealing with the most-recent images.

Where this is coming up a lot now is with the release of v6, I find I am going back to re-run prompts I ran under 5.2. I find these by flipping through the images in the file system, but I have 11,000+ images-- if I want to find the prompt now (particularly if I want to see image prompts), I have to use the job ID off the image file, then show the job from Midjourney in Discord. That might sound simple, but if I want to see a bunch of related prompts at once (to see how they/if they differ), I can't do it in any easy way.

Very advanced: Save image prompts when the URL isn't recognized in the current directory. For example, if I have https://s.mj.run/oV1fLNrILibD as part of my prompt, look for https://s.mj.run/oV1fLNrILibD in the directory where the image would go. If it's not there, save that image, using a standard filesystem-friendly name (silly example): https£¤¤s.mj.run¤oV1fLNrILibD.

get-got commented 6 months ago

I think I've added an okay solution for what you're needing. https://github.com/get-got/discord-downloader-go/commit/f9727c2267a348a57a8b50dbd3a5f0b59edc1cdf & https://github.com/get-got/discord-downloader-go/commit/57675470e2a31d559ede438de4f3af139d34bf49

Rather than implement a new utility, it seemed much better to adapt logLinks to be able to accomplish this.

I added a "content" setting to logLinks and logMessages. This currently provides no actual utility for logMessages, but in the case of logLinks, it defaults to "{{link}}" but accepts {{msgContent}} or {{embedDesc}} (since I recall Midjourney images/prompts are embedded), you should be able to use the settings below to accomplish what you're wanting.

logLinks is called after the download request finishes, because part of the original intention was to log download failures and whatnot. It also takes the same data keys as downloads, so we can use this to mirror your actual download.

"logLinks": {
    "destination": "*match downloads*",
    "subfolders": [ "*match downloads*" ],
    "filenameFormat": "{{downloadFilename}}.prompt",
    "prefix": "",
    "suffix": "",
    "content": "{{embedDesc}}",
    "logFailures": false
}

should result in

file_A.jpg file_A.prompt - "Aaaaaaa aaaaaaaaa aaaaaaaa" file_B.jpg file_B.prompt - "Bbbbbbb bbbbbbbb bbbbbbbb"

kauffy commented 5 months ago

Well, that sounds like a pretty decent solution. Are you going to push an update?

kauffy commented 5 months ago

Given that tens of thousands of images have already been downloaded, how would this handle the history part for prompts? I don't want to redownload the images, of course, but I would like allllllllll the prompts.

get-got commented 5 months ago

Close your active instance of the bot, copy your active settings file to a temporary backup file, change the settings.json to use "save": false, and run the history query you're needing. It'll reprocess everything, logging and whatnot, but won't save files.

kauffy commented 5 months ago

I didn't fully get the instructions for capturing the log stuff. The sample XML you gave-- where should that go? Is that inside the channel? Secondly, does it save the prompts as you described-- alongside the images? (I'm being extra cautious, given how many files there are).

get-got commented 5 months ago

logLinks and logMessages exist globally and per-source. For your uses here, it should be used per-source (inside the channel) as formatted above.

Something like this will achieve the result you're wanting. Matching the destination and subfolders will cause them to be downloaded alongside the images.

image