Universal Blue ChatOps

okay so I keep thinking about this bot thing. What if we had like:
# show count of PRs, issues, etc in a neofetch like fashion
ubluectl status

# approve pr 56 for main
ubluectl pr —approve main/56

# trigger GitHub workflows
ubluectl trigger-workflow main/build.yml
# show count of PRs, issues, etc in a neofetch like fashion
ubluectl status

# approve pr 56 for main
ubluectl pr —approve main/56

# trigger GitHub workflows
ubluectl trigger-workflow main/build.yml
Let’s make this a bot thread 🧵
50 Replies
akdev
akdevOP15mo ago
What feature do we want/need in a bot?
xyny
xyny15mo ago
ubluectl makes it seem like a cli-thing discord has the /slash commands now couldn't it be like
akdev
akdevOP15mo ago
It can’t be slash because it will conflict with discord stuff
xyny
xyny15mo ago
/status, /trigger-workflow, /pr slash commands are the new "correct" way to make discord bots, though could have a prefix to prevent collisions
akdev
akdevOP15mo ago
Oh then I can do that but it would be /ubluectl status
xyny
xyny15mo ago
i guess hold on, i'm googling how other bots do it
akdev
akdevOP15mo ago
The one on fedora server uses .command
xyny
xyny15mo ago
yeah, a lot of bots use .cmd !cmd etc too but with slash commands we get that fancy autocomplete no need for .help https://discord.com/blog/slash-commands-are-here
akdev
akdevOP15mo ago
the problem with that is that it seems very easy to create conflicts
xyny
xyny15mo ago
other bots just have /command
akdev
akdevOP15mo ago
Eg: /status
xyny
xyny15mo ago
/status there's no /status in discord by default if we don't add other bots we can use /status
akdev
akdevOP15mo ago
Yeah but if two bots implement /status I guess you get two responses
xyny
xyny15mo ago
i'd guess discord would handle that better because slash commands are a discord feature, not just parsing messages that people send maybe in the dialog that opens when you type / you need to select the correct one?
akdev
akdevOP15mo ago
mm not sure what this discord commands feature actually does I would prefer parsing messages because it is more flexible but need to see what the discord commands do
xyny
xyny15mo ago
it's just like parsing messages, but you get autocomplete and descriptions of the different fields
Lina
Lina15mo ago
multiple bots can have the same command name with slash commands, youre able to choose between what command you actually intend to use
akdev
akdevOP15mo ago
There's limitations like this
No description
akdev
akdevOP15mo ago
mm need to see what it means
xyny
xyny15mo ago
at least https://discordjs.guide/creating-your-bot/slash-commands.html in discord.js creating slash commands seems pretty easy i don't think we'd cross 100, but this depends on if what we'd want is CHAT_INPUT or MESSAGE
akdev
akdevOP15mo ago
Whats the difference?
xyny
xyny15mo ago
no idea
Lina
Lina15mo ago
slash commands have the advantages of 1. showing a little tooltip describing the command and 2. suggesting command completions
akdev
akdevOP15mo ago
I’ll probably just use message parsing at least at the beginning because it’s very easy
Lina
Lina15mo ago
heres what it looks like on mobile
No description
xyny
xyny15mo ago
i wouldn't go for worse UX because it's a bit easier to develop
akdev
akdevOP15mo ago
Going from message parsing to slash commands is a lot easier than the reverse
xyny
xyny15mo ago
CHAT_INPUT is the one (https://discord.com/developers/docs/interactions/application-commands), the others are for context menus
akdev
akdevOP15mo ago
plus I need a working CLI anyway to test locally
Lina
Lina15mo ago
usually people make personal discord servers for testing
xyny
xyny15mo ago
you can test with a test discord server do you have experience making discord bots?
akdev
akdevOP15mo ago
I do have a testing server It’s still not really ideal if I have to open my web browser to test stuff
xyny
xyny15mo ago
i always just keep the web browser on the side, for googling stuff and such. you can just have the discord server open there and type in the commands you wanna test. i don't see the issue
akdev
akdevOP15mo ago
To make a code change I would have to: 1. Make a code change, rebuild/reinstall application 2. Go to web browser and type on discord vs: npm build && npm run ubluectl I prefer tight feedback loops I guess I could automate something with the discord API itself to send the message but this is more work
xyny
xyny15mo ago
if you do npm build && npm run ubluectl i presume that would connect to discord and host the bot temporarily on your local machine. with that, it's just the difference between writing the commands in the same textbox or writing them in a discord window on the side plus if you want to have a cli for testing don't you need to build a cli
akdev
akdevOP15mo ago
yeah and it is very easy to do and very easy to reuse the work to implement other interfaces
xyny
xyny15mo ago
and of course you can just use console.log() for debugging and the logs would just be in your console window i don't see how using slash commands would be any more work for you (and other developers working on the project in the future) (unless you are already very familiar with the other ways of doing things), while not using slash commands makes the UX worse
akdev
akdevOP15mo ago
unless you are very familiar with the other ways of doing things
Yes.
xyny
xyny15mo ago
so you have experience writing discord bots. i asked that earlier and thought you brushed it off.
akdev
akdevOP15mo ago
I have experience writing software incrementally. Not discord bots specifically. I build software to work on cloud different compute platforms (ECS/EC2/EKS/Lambda) transparently - I just build a CLI first for fast feedback loops and create interfaces for each compute platform so I can build core functionality first and focus on the interface later For example it’s not really that important if the application is triggered by ubluectl status or
{
“command”: [“status”]
}
{
“command”: [“status”]
}
90% of the work will be the same so I’d rather start with the former so I don’t have to figure out how to test and interact with discord commands and I can just focus on interacting with GitHub, etc Ultimately the code will run AWS lambda and needs to take in a post request so probably discord commands is totally the way
xyny
xyny15mo ago
i don't have anything against you building a cli first, i was just arguing that you should use slash commands. but cool to hear that you weren't as against that as i read you as being.
akdev
akdevOP15mo ago
You brought up good points! But at this stage I would like to focus more on the things we want to do vs implementation details
j0rge
j0rge15mo ago
Just off the top of my head real quick: kick off a build in any repo, with the ability to just rebuild everything in one go in order. show any PRs older than X days notify the dev channel if the build is broken for over X days
xyny
xyny15mo ago
oh and a (useless) bonus feature, pretty complicated, if you've linked your github account to your discord account it could give CONTRIB if you have a commit in any ublue-os repository
akdev
akdevOP15mo ago
What’s CONTRIB?
Gerblesh
Gerblesh15mo ago
It's the discord role
akdev
akdevOP15mo ago
Oh I see that’d be cool
$ poetry run ubluebot --help
usage: ubluebot [-h] {status,pr-approve,trigger-workflow} ...

options:
-h, --help show this help message and exit

commands:
valid commands for ubluebot

{status,pr-approve,trigger-workflow}
pass one of these commands to get the ubluebot output
status check out the status of the project
pr-approve approve a pending PR
trigger-workflow trigger a github workflow

$ poetry run ubluebot status --help
usage: ubluebot status [-h] [-i] [-spr] [-rw] [-f {json,human,discord}]

options:
-h, --help show this help message and exit
-i, --issues list issue metrics
-spr, --stale-pr show stale pull requests
-rw, --running-workflows
show running and pending workflows across the organization
-f {json,human,discord}, --format {json,human,discord}
output format
$ poetry run ubluebot --help
usage: ubluebot [-h] {status,pr-approve,trigger-workflow} ...

options:
-h, --help show this help message and exit

commands:
valid commands for ubluebot

{status,pr-approve,trigger-workflow}
pass one of these commands to get the ubluebot output
status check out the status of the project
pr-approve approve a pending PR
trigger-workflow trigger a github workflow

$ poetry run ubluebot status --help
usage: ubluebot status [-h] [-i] [-spr] [-rw] [-f {json,human,discord}]

options:
-h, --help show this help message and exit
-i, --issues list issue metrics
-spr, --stale-pr show stale pull requests
-rw, --running-workflows
show running and pending workflows across the organization
-f {json,human,discord}, --format {json,human,discord}
output format
I started work on this yesterday night, the end usage would be like /status --issues --stale-pr --running-workflows or maybe separate commands idk how discord commands are supposed to work yet
xyny
xyny15mo ago
i don't think you're supposed to do --param, i think all the params are positioned and given names and autocomplete values, so it'd probably be more like /status [type:][issues/pr/workflows] with [] being hints discord gives to the user and the code just getting the value as {type: "issues"} or {type: ["issues", "prs"]}. actually i'm not sure there's an autocomplete at all
akdev
akdevOP15mo ago
How to pass parameters to a GitHub command? Positional parameters are hard to remember for me
xyny
xyny15mo ago
discord tells you the name of the positional parameter you are currently writing, for some things it might be more suited for named params and that might need to be a custom implementation which is not ideal
Want results from more Discord servers?
Add your server