rHomelab / LabBot-Cogs

Cogs for the Red-based Homelab Discord server bot.
GNU General Public License v3.0
35 stars 14 forks source link

[FEAT] Mods are watching #110

Open tigattack opened 3 years ago

tigattack commented 3 years ago

Overview

Mods are watching functionality, à la Araquiel's :eye: trigger.
Example: image

Cog should build these images on the fly to avoid issues with hardcoding. Suggest using imgflip API or similar. If using imgflip, use template ID 224894675.

I'm not sure if this is best as an extension of the autoreply cog or a cog of its own. Due to this, I've not filled out the suggested commands below.

Commands

[p]modmeme <enable|disable> <watching|frog|horse>
[p]modmeme trigger <watching|frog|horse> :emote: # Trigger conflicts should not be allowed.
[p]modmeme setname <@modUser> <name> # Default to current user if user param not specified.
[p]modmeme setnamelimit <int> # Default to 32 chars if not specified.

DoD

Stretch

reichbc commented 3 years ago

I suggest adding Horse of Disapproval for extra emphasis on the disapproval... horse-of-disapproval

tigattack commented 3 years ago

If you can produce the same end result with the imgur API, then that's fine :+1: I've created a mirror of the template here if that's any help.

The only thing I notice is that while it is official, the imgurpython project has been deprecated since late 2017, so it may be better to find an alternative if possible.

I'd welcome input from @issy or any other member of the team who has any suggestions regarding this.

jeevanshah07 commented 3 years ago

Ok thanks. I realized that it's probably easier to use the imgflip api to create custom memes (ie. (Mod name) is watching) so that's what I'll prob use.

tigattack commented 3 years ago

OK. You can use imgflip template ID 224894675.

issy commented 3 years ago

The purpose of the imgflip API in this cog is for image editing, not image storing - therefore the imgur API does not provide the same featureset that we need. One note I will pass on is that I had a lot of trouble adding a second custom text field to an image with the API. It is not entirely clear from the API docs how they want you to format the array. I am sure you will see what I mean when you look into it. Recently I've been thinking about the possibility of using a library such as PIL to do this, meaning we don't rely on a third party API

tigattack commented 3 years ago

Since the template's upper text box is in the correct position there's no need to specify anything more than the text, so this is very easy:

>>> import requests
>>> body = {'username':'redacted','password':'redacted','template_id':'224894675','font':'arial','boxes[0][text]':'your mum'}
>>> req = requests.post('https://api.imgflip.com/caption_image',data = body)
>>> print(req.text)
{"success":true,"data":{"url":"https:\/\/i.imgflip.com\/5b5vyr.jpg","page_url":"https:\/\/imgflip.com\/i\/5b5vyr"}}

Resulting image.

I'm sure there's a better way to do it, but this works fine as a PoC.

issy commented 3 years ago

Thanks for the snippet, Tig. That's definitely different from what I was doing :D IIRC my method wasn't retaining font styling, but that seems to be retaining them perfectly.

issy commented 3 years ago

Suggested command usage RFC

[p]modmeme <enable|disable> <watching|frog|horse>
jeevanshah07 commented 3 years ago

This all looks really good! The frog and horse won't need any captioning right?

issy commented 3 years ago

Nope, they won't need any captioning. I've created imgflip templates for both of them, if that makes life easier. Frog: 321087939 Horse: 321088192

jeevanshah07 commented 3 years ago

Also do you guys want a hardcoded username and password or is there some sorta config file that I can edit? And should the triggers be hardcoded?

issy commented 3 years ago

Pull the username/password from the API key store built into Red. Documentation here It works similarly to the config class

tigattack commented 3 years ago

I'd like to suggest another command:

[p]modmeme trigger <watching|frog|horse> :emote: # Trigger conflicts should not be allowed.

Also, a note regarding the enable|disable command: I think it should default to be global enable/disable if the second param is not specified.

jeevanshah07 commented 3 years ago

I'd like to suggest another command:

[p]modmeme trigger <watching|frog|horse> :emote: # Trigger conflicts should not be allowed.

Also, a note regarding the enable|disable command: I think it should default to be global enable/disable if the second param is not specified.

Noted. By trigger conflicts I assume you mean the auto reply triggers?

issy commented 3 years ago

~Yep, so to check that you'll have to get the config object from the autoreply cog. Bear in mind, you have to check that the cog is loaded as well. Something like this would probably be ok~ triggers should be allowed between autoreply and modmeme; just not between the different modmemes

tigattack commented 3 years ago

Another idea I've just had:

Nicknames would be best to use for the template text since they can differ from the username and members may know a mod by their nickname rather than username.
However, Discord has a limit of 32 characters for nicknames which could make the template unreadable or look poorly formatted.

I suggest that by default it uses the nickname, but has the following options available:

[p]modmeme setname <@modUser> <name> # Default to current user if user param not specified.
[p]modmeme setnamelimit <int> # Default to 32 chars if not specified.

I'm aware I'm causing a lot of scope creep here, sorry about that. Clearly I didn't think this through very thoroughly!
Please consider these suggestions to be stretches rather than DoD's.

jeevanshah07 commented 3 years ago

It's all fine. It will probably be a bit before I can get a working cog as I've never worked with RED before😅

issy commented 3 years ago

No worries 👍 having this discussion helped us clear up a lot of the implementation details anyway