AndBobsYourUncle / stable-diffusion-discord-bot

A Discord bot, written in Go, that interfaces with the Automatic 1111's API interface.
MIT License
131 stars 35 forks source link

Feature request: allow changing of command #5

Open Papahyooie opened 1 year ago

Papahyooie commented 1 year ago

Want to be able to use this on the same server as the midjourney bot, and they both use the same discord command (/imagine). Not a big deal as you can choose which one you want to use with a click, but annoying to users. I can do a PR for it myself if that's what you want, just wanted to make sure you didn't have plans. Maybe make it a command line option?

If there's another way to make this happen directly in discord, I'm just not aware of it.

AndBobsYourUncle commented 1 year ago

Ah yeah, this is a good idea, and I don’t believe you can do that in Discord’s UI. Simple enough to add another command line flag.

AndBobsYourUncle commented 1 year ago

Just pushed up something to master that adds the -imagine flag that you can give whatever string you'd like. Hopefully this works for you. 👍

Papahyooie commented 1 year ago

Works fantastic! For future reference, it gives a null pointer if you:

  1. have a preexisting bot on your server
  2. update to new code
  3. use the -imagine flag to change the command

Easily worked around by removing the bot from your server and re-adding with the new command. Also verified it doesn't break existing users if they don't add the flag.

Not a big deal at all, just wanted to let you know. I'm a QA by trade, so I can't help it, haha. I consider this closed, but I won't close it in case you want to fix the above.

Papahyooie commented 1 year ago

Actually, just realized it will also break the second time you launch with the flag. So you have to re-add the bot every time you launch, if you use the flag.

EDIT: aaaand it didn't do it the third time. I have no idea what's happening here. I'll keep looking at it.

AndBobsYourUncle commented 1 year ago

Hmmm, interesting.

I tried launching my dev version of the bot with -imagine test_imagine and it seemed to work. Definitely the old command sticks around, but trying to use it won't work (since no bot is listening for it anymore).

Like you mentioned, removing the bot and adding it back to the server again cleared out the old commands that were not working after the flag change.

I then proceeded to test again after relaunching, and it all seems to work. I think the thing with the flag is that you need to run the bot with the flag every single time, or it won't be listening to the overridden version of the command name?

AndBobsYourUncle commented 1 year ago

I'm curious about the null pointer you mentioned though. Was that a panic that you saw? Curious if there is a way to replicate it.

Papahyooie commented 1 year ago

So after some more testing, it seems you can reproduce the error by putting capital letters in your custom command. The idea that it was being caused by existing commands was a false positive on my part.

AndBobsYourUncle commented 1 year ago

Oh nice, thanks for spotting this. Just pushed a fix.

AndBobsYourUncle commented 1 year ago

It was an error coming back from Discord about the command name being invalid. Now, trying to use capital letters correctly logs the error coming back from their API:

Error creating 'dev_Test' command: HTTP 400 Bad Request, {"code": 50035, "errors": {"name": {"_errors": [{"code": "APPLICATION_COMMAND_INVALID_NAME", "message": "Command name is invalid"}]}}, "message": "Invalid Form Body"}

AndBobsYourUncle commented 1 year ago

Also added a --remove flag that, if you run the bot with this flag, upon killing the bot it will cleanup and delete all commands that it has added.

You can use this flag to run the bot with the normal imagine command, exit the bot (it will then delete the normal imagine commands), and then rerun with the -imagine flag to give the command a new name. That way, the old /imagine command won't stick around.

Papahyooie commented 1 year ago

That's fantastic. I'll give the remove flag a try, everything else is working great.