diff options
author | gennyble <gen@nyble.dev> | 2025-08-02 19:47:29 -0500 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2025-08-02 19:47:29 -0500 |
commit | 0150fce1af73affcbe0d58a439fc7277be027059 (patch) | |
tree | e78c1734145ab52b62f99a8a579f0007eae503a4 | |
parent | 0e3f1550d960dc47751ca4196e894d1aeea5afd2 (diff) | |
download | leaberblord-0150fce1af73affcbe0d58a439fc7277be027059.tar.gz leaberblord-0150fce1af73affcbe0d58a439fc7277be027059.zip |
about command
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | TODO | 6 | ||||
-rw-r--r-- | src/main.rs | 31 |
3 files changed, 35 insertions, 5 deletions
diff --git a/README.md b/README.md index e515a22..d33bf21 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -EMBOARD is end-of-life and I have a need for a leaderboard bot. +EMBOARD is end-of-life and I have a need for a leaderboard bot. How hard could it be? Uh oh, the code is kinda bad. @@ -6,6 +6,7 @@ Uh oh, the code is kinda bad. [Invite Link](https://discord.com/oauth2/authorize?client_id=1363055126264283136&permissions=2048&integration_type=0&scope=bot+applications.commands) Requirements- We want to do what emboard can at least. here is what we do so far. +- `about`: Get information about the bot. - `leaderboard`: Displays the leaderboard. - `points [points] [user]`: Change the points of the mentioned users - `permission none`: No permissions are required to change the score; anyone may set the score. This command requires the Manage Server permission. diff --git a/TODO b/TODO index 0057cf8..585c4e9 100644 --- a/TODO +++ b/TODO @@ -2,4 +2,8 @@ Use the cache! We do not- I mean, we set the cache /up/ but we do not make use of it kind of really at all. I think the only place we kind of need this is in `add_points` where - we get the members of the guild. \ No newline at end of file + we get the members of the guild. + +Better logging + There's like, an user now, so we should log better so we can find errors + more readily. \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 37d9a75..0b34f30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ use twilight_model::{ use twilight_util::builder::{ InteractionResponseDataBuilder, command::{CommandBuilder, IntegerBuilder, RoleBuilder, StringBuilder, SubCommandBuilder}, - embed::EmbedBuilder, + embed::{EmbedBuilder, EmbedFieldBuilder}, }; mod brain; @@ -32,8 +32,9 @@ mod database; mod import; const PROD_APP_ID: u64 = 1363055126264283136; +#[allow(dead_code)] const DEV_APP_ID: u64 = 1363494986699771984; -const APP_ID: u64 = PROD_APP_ID; +const APP_ID: u64 = DEV_APP_ID; macro_rules! bail { ($msg:expr) => { @@ -163,6 +164,7 @@ async fn handle_event(event: Event, brain: Arc<Brain>) -> Result<(), Box<dyn Err let guild = create.guild.as_ref().unwrap().id.unwrap(); let command = match cmd.name.as_str() { + "about" => Commands::About, "leaderboard" => Commands::Leaderboard, "points" => Commands::Points, "permission" => Commands::Permission, @@ -183,6 +185,13 @@ async fn handle_event(event: Event, brain: Arc<Brain>) -> Result<(), Box<dyn Err } async fn commands() -> Vec<Command> { + let about = CommandBuilder::new( + "about", + "Get information about the bot", + CommandType::ChatInput, + ) + .build(); + let leaderboard = CommandBuilder::new( "leaderboard", "View the server leaderboard", @@ -221,7 +230,7 @@ async fn commands() -> Vec<Command> { ) .build(); - vec![leaderboard, points, permission, import] + vec![about, leaderboard, points, permission, import] } async fn command_handler( @@ -233,6 +242,7 @@ async fn command_handler( ) { // Handle the command and create our interaction response data let data = match command { + Commands::About => about(brain.clone(), guild), Commands::Leaderboard => get_leaderboard(brain.clone(), guild), Commands::Points => add_points(brain.clone(), guild, create, command_data).await, Commands::Permission => permission(brain.clone(), guild, create, command_data).await, @@ -246,6 +256,20 @@ async fn command_handler( brain.interaction_respond(create, data).await; } +fn about(_brain: Arc<Brain>, _guild: Id<GuildMarker>) -> InteractionResponseData { + let embed = EmbedBuilder::new() + .title("About Leaberblord") + .description( + "A single-purpose bot for keeping score. Written in Rust using the twilight set of crates.", + ).field(EmbedFieldBuilder::new("Source", "The source is available on the author's [cgit instance](https://git.dreamy.place/whimsy/leaberblord/about)")) + .field(EmbedFieldBuilder::new("Author", "Written by @gennyble. Her homepage is [dreamy.place](https://dreamy.place)")) + .color(0x33aa88).build(); + + InteractionResponseDataBuilder::new() + .embeds([embed]) + .build() +} + fn get_leaderboard(brain: Arc<Brain>, guild: Id<GuildMarker>) -> InteractionResponseData { let board = brain.db.get_leaderboard(guild.get()); @@ -449,6 +473,7 @@ async fn import_cmd( } enum Commands { + About, Leaderboard, Points, Permission, |