From e5ac08f990270a743e0ec35db2b251ab666ea466 Mon Sep 17 00:00:00 2001 From: August Date: Thu, 21 May 2026 21:40:02 -0400 Subject: [PATCH] New command, fields --- Cargo.lock | 2 +- Cargo.toml | 3 ++- README.md | 9 ++++++--- src/bot_runner.rs | 34 ++++++++++++++++++++++++++++++++-- src/handlers/minecraft.rs | 13 +++++++++++-- src/types.rs | 4 +++- 6 files changed, 55 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 632f5ee..ff5b60b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1317,7 +1317,7 @@ checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "playerbot" -version = "1.1.0" +version = "1.2.0" dependencies = [ "anyhow", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index 7e8f4eb..48300dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "playerbot" -version = "1.1.0" +version = "1.2.0" edition = "2021" +repository = "https://git.shibedrill.site/shibedrill/playerbot" [dependencies] anyhow = "1.0.102" diff --git a/README.md b/README.md index 0036bec..dfc57c9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Playerbot 1.1.0 +# Playerbot 1.2.0 Playerbot is a utility to monitor the status of game servers through Discord bots. These bots provide a rich integration into your Discord server, including things like player counts, server status, game versions, and game server addresses. It's easy to configure, and runs as one process from one binary. @@ -9,6 +9,8 @@ Playerbot is a utility to monitor the status of game servers through Discord bot - The bot will automatically register slash commands: - `/players` displays the number of players online and, if the server supports it, will list the usernames of all players on the server. - `/join` displays the address, or some kind of name that players can search to join the server, as well as the server's version. + - `/contact` allows users to file support tickets which ping the configured maintainer. This is only registered for servers with supplied maintainer UIDs. + - `/about` displays information about the bot itself. ## Configuration @@ -21,9 +23,10 @@ The program requires a file named config.json to be present in its current worki { "Minecraft": { "host": { - "Domain": "10.0.0.2:233" + "Ipv4": "10.0.0.2:233" // Can be "Domain", "Ipv4", or "Ipv6", required }, - "token": "FAKETOKENPLACEHOLDERWHICHISVERYLONG" + "token": "FAKETOKENPLACEHOLDERWHICHISVERYLONG", // Bot tokem, required + "contact": 999999999999999999 // Maintainence contact Discord UID, optional } } ] diff --git a/src/bot_runner.rs b/src/bot_runner.rs index 3232825..1788c61 100644 --- a/src/bot_runner.rs +++ b/src/bot_runner.rs @@ -1,7 +1,7 @@ use crate::request::request; use crate::types::*; use log::*; -use poise::serenity_prelude as serenity; +use poise::serenity_prelude::{self as serenity, Mentionable}; use poise::serenity_prelude::{ActivityData, ClientBuilder, GatewayIntents}; use tokio::sync::Mutex; @@ -17,9 +17,13 @@ pub struct Data { impl BotRunner { pub async fn new(server: Box) -> Self { let token = server.app_token(); + let mut commands = vec![players(), join()]; + if let Some(_contact_id) = server.contact() { + commands.push(contact()); + } let framework = poise::Framework::builder() .options(poise::FrameworkOptions { - commands: vec![players(), join()], + commands, event_handler: |ctx, event, framework, data| { Box::pin(event_handler(ctx, event, framework, data)) }, @@ -157,3 +161,29 @@ pub async fn join(ctx: poise::Context<'_, Data, serenity::Error>) -> Result<(), }; Ok(()) } + +/// File a help request with the maintainer +#[poise::command(slash_command, global_cooldown = 120)] +pub async fn contact( + ctx: poise::Context<'_, Data, serenity::Error>, + #[description = "What you would like the maintainer's help with"] request_deets: String, +) -> Result<(), serenity::Error> { + ctx.say(format!( + "<@{}>\nNew ticket from {}!\nDetails: `{}`", + ctx.data().server.contact().unwrap(), + ctx.author().mention(), + request_deets + )) + .await?; + Ok(()) +} + +#[poise::command(slash_command)] +pub async fn about(ctx: poise::Context<'_, Data, serenity::Error>) -> Result<(), serenity::Error> { + ctx.say(format!( + "Playerbot v{} was developed by shibedrill!\nSource code: {}", + env!("CARGO_PKG_VERSION"), + env!("CARGO_PKG_REPOSITORY") + )).await?; + Ok(()) +} \ No newline at end of file diff --git a/src/handlers/minecraft.rs b/src/handlers/minecraft.rs index 3f502fb..23952c4 100644 --- a/src/handlers/minecraft.rs +++ b/src/handlers/minecraft.rs @@ -51,11 +51,20 @@ pub struct Minecraft { #[allow(dead_code)] token: String, host: Host, + contact: Option, } impl ServerInfo for Minecraft { - fn new(token: String, host: Host) -> Self { - Minecraft { token, host } + fn new(token: String, host: Host, contact: Option) -> Self { + Minecraft { + token, + host, + contact, + } + } + + fn contact(&self) -> Option { + self.contact } fn addressable_name(&self) -> String { diff --git a/src/types.rs b/src/types.rs index 8484758..c39ae07 100644 --- a/src/types.rs +++ b/src/types.rs @@ -21,7 +21,7 @@ pub struct ServerOnlineResponse { #[allow(dead_code)] pub trait ServerInfo: Send + Sync { - fn new(token: String, addr: Host) -> Self + fn new(token: String, addr: Host, contact: Option) -> Self where Self: Sized; @@ -37,4 +37,6 @@ pub trait ServerInfo: Send + Sync { fn app_token(&self) -> String; fn supports_playerlist(&self) -> bool; + + fn contact(&self) -> Option; }