UB
Universal Blueโ€ข10mo ago
akdev

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