New command, fields

This commit is contained in:
August 2026-05-21 21:40:02 -04:00
parent 8c61eac586
commit e5ac08f990
Signed by: shibedrill
SSH Key Fingerprint: SHA256:M0m3JW1s38BgO2t0fG146Yxd9OJ2IOqkvCAsuRHQ6Pw
6 changed files with 55 additions and 10 deletions

2
Cargo.lock generated
View File

@ -1317,7 +1317,7 @@ checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
[[package]] [[package]]
name = "playerbot" name = "playerbot"
version = "1.1.0" version = "1.2.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"env_logger", "env_logger",

View File

@ -1,7 +1,8 @@
[package] [package]
name = "playerbot" name = "playerbot"
version = "1.1.0" version = "1.2.0"
edition = "2021" edition = "2021"
repository = "https://git.shibedrill.site/shibedrill/playerbot"
[dependencies] [dependencies]
anyhow = "1.0.102" anyhow = "1.0.102"

View File

@ -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. 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: - 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. - `/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. - `/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 ## Configuration
@ -21,9 +23,10 @@ The program requires a file named config.json to be present in its current worki
{ {
"Minecraft": { "Minecraft": {
"host": { "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
} }
} }
] ]

View File

@ -1,7 +1,7 @@
use crate::request::request; use crate::request::request;
use crate::types::*; use crate::types::*;
use log::*; use log::*;
use poise::serenity_prelude as serenity; use poise::serenity_prelude::{self as serenity, Mentionable};
use poise::serenity_prelude::{ActivityData, ClientBuilder, GatewayIntents}; use poise::serenity_prelude::{ActivityData, ClientBuilder, GatewayIntents};
use tokio::sync::Mutex; use tokio::sync::Mutex;
@ -17,9 +17,13 @@ pub struct Data {
impl BotRunner { impl BotRunner {
pub async fn new(server: Box<dyn ServerInfo>) -> Self { pub async fn new(server: Box<dyn ServerInfo>) -> Self {
let token = server.app_token(); 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() let framework = poise::Framework::builder()
.options(poise::FrameworkOptions { .options(poise::FrameworkOptions {
commands: vec![players(), join()], commands,
event_handler: |ctx, event, framework, data| { event_handler: |ctx, event, framework, data| {
Box::pin(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(()) 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(())
}

View File

@ -51,11 +51,20 @@ pub struct Minecraft {
#[allow(dead_code)] #[allow(dead_code)]
token: String, token: String,
host: Host, host: Host,
contact: Option<u64>,
} }
impl ServerInfo for Minecraft { impl ServerInfo for Minecraft {
fn new(token: String, host: Host) -> Self { fn new(token: String, host: Host, contact: Option<u64>) -> Self {
Minecraft { token, host } Minecraft {
token,
host,
contact,
}
}
fn contact(&self) -> Option<u64> {
self.contact
} }
fn addressable_name(&self) -> String { fn addressable_name(&self) -> String {

View File

@ -21,7 +21,7 @@ pub struct ServerOnlineResponse {
#[allow(dead_code)] #[allow(dead_code)]
pub trait ServerInfo: Send + Sync { pub trait ServerInfo: Send + Sync {
fn new(token: String, addr: Host) -> Self fn new(token: String, addr: Host, contact: Option<u64>) -> Self
where where
Self: Sized; Self: Sized;
@ -37,4 +37,6 @@ pub trait ServerInfo: Send + Sync {
fn app_token(&self) -> String; fn app_token(&self) -> String;
fn supports_playerlist(&self) -> bool; fn supports_playerlist(&self) -> bool;
fn contact(&self) -> Option<u64>;
} }