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
akdevOP16mo ago
What feature do we want/need in a bot?
xyny
xyny16mo ago
ubluectl makes it seem like a cli-thing discord has the /slash commands now couldn't it be like
akdev
akdevOP16mo ago
It can’t be slash because it will conflict with discord stuff
xyny
xyny16mo 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
akdevOP16mo ago
Oh then I can do that but it would be /ubluectl status
xyny
xyny16mo ago
i guess hold on, i'm googling how other bots do it
akdev
akdevOP16mo ago
The one on fedora server uses .command
xyny
xyny16mo 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
akdevOP16mo ago
the problem with that is that it seems very easy to create conflicts
xyny
xyny16mo ago
other bots just have /command
akdev
akdevOP16mo ago
Eg: /status
xyny
xyny16mo ago
/status there's no /status in discord by default if we don't add other bots we can use /status
akdev
akdevOP16mo ago
Yeah but if two bots implement /status I guess you get two responses
xyny
xyny16mo 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
akdevOP16mo 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
xyny16mo ago
it's just like parsing messages, but you get autocomplete and descriptions of the different fields
Lina
Lina16mo 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
akdevOP16mo ago
There's limitations like this
No description
akdev
akdevOP16mo ago
mm need to see what it means
xyny
xyny16mo 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
akdevOP16mo ago
Whats the difference?
xyny
xyny16mo ago
no idea
Lina
Lina16mo ago
slash commands have the advantages of 1. showing a little tooltip describing the command and 2. suggesting command completions
akdev
akdevOP16mo ago
I’ll probably just use message parsing at least at the beginning because it’s very easy
Lina
Lina16mo ago
heres what it looks like on mobile
No description
xyny
xyny16mo ago
i wouldn't go for worse UX because it's a bit easier to develop
akdev
akdevOP16mo ago
Going from message parsing to slash commands is a lot easier than the reverse
xyny
xyny16mo ago
CHAT_INPUT is the one (https://discord.com/developers/docs/interactions/application-commands), the others are for context menus
akdev
akdevOP16mo ago
plus I need a working CLI anyway to test locally
Lina
Lina16mo ago
usually people make personal discord servers for testing
xyny
xyny16mo ago
you can test with a test discord server do you have experience making discord bots?
akdev
akdevOP16mo 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
xyny16mo 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
akdevOP16mo 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
xyny16mo 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
akdevOP16mo ago
yeah and it is very easy to do and very easy to reuse the work to implement other interfaces
xyny
xyny16mo 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
akdevOP16mo ago
unless you are very familiar with the other ways of doing things
Yes.
xyny
xyny16mo ago
so you have experience writing discord bots. i asked that earlier and thought you brushed it off.
akdev
akdevOP16mo 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
xyny16mo 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
akdevOP16mo 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
j0rge16mo 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
xyny16mo 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
akdevOP16mo ago
What’s CONTRIB?
Gerblesh
Gerblesh16mo ago
It's the discord role
akdev
akdevOP16mo 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
xyny16mo 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
akdevOP16mo ago
How to pass parameters to a GitHub command? Positional parameters are hard to remember for me
xyny
xyny16mo 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