Add 'enable' field

This commit is contained in:
August 2026-08-01 16:16:10 +00:00
parent bd6481f1a1
commit 0b3098726e
Signed by: shibedrill
SSH Key Fingerprint: SHA256:M0m3JW1s38BgO2t0fG146Yxd9OJ2IOqkvCAsuRHQ6Pw
9 changed files with 550 additions and 564 deletions

4
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix",
"nixEnvSelector.useFlakes": false
}

1046
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,17 @@
[package] [package]
name = "playerbot" name = "playerbot"
version = "1.2.0" version = "1.3.0"
edition = "2021" edition = "2021"
repository = "https://git.shibedrill.site/shibedrill/playerbot" repository = "https://git.shibedrill.site/shibedrill/playerbot"
[dependencies] [dependencies]
anyhow = "1.0.102" anyhow = "1.0.104"
env_logger = "0.11.10" env_logger = "0.11.11"
futures = "0.3.32" futures = "0.3.33"
log = "0.4.29" log = "0.4.33"
poise = "0.6.2" poise = "0.6.2"
reqwest = {version = "0.13.3", features = ["json"]} reqwest = {version = "0.13.4", features = ["json"]}
serde = {version = "1.0.215", features = ["derive", "serde_derive"]} serde = {version = "1.0.229", features = ["derive", "serde_derive"]}
serde_json = "1.0.149" serde_json = "1.0.151"
tokio = {version = "1.41.1", features = ["full"]} tokio = {version = "1.53.1", features = ["full"]}
url = "2.5.3" url = "2.5.8"

View File

@ -1,4 +1,4 @@
# Playerbot 1.2.0 # Playerbot 1.3.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.
@ -18,10 +18,11 @@ The program requires a file named config.json to be present in its current worki
```json ```json
{ {
"version": "0.2.0", "version": "0.3.0",
"entries": [ "entries": [
{ {
"Minecraft": { "Minecraft": {
"enabled": true, // If false, this handler won't be loaded
"host": { "host": {
"Ipv4": "10.0.0.2:233" // Can be "Domain", "Ipv4", or "Ipv6", required "Ipv4": "10.0.0.2:233" // Can be "Domain", "Ipv4", or "Ipv6", required
}, },

21
shell.nix Normal file
View File

@ -0,0 +1,21 @@
let
nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz";
pkgs = import nixpkgs { config = {}; overlays = []; };
in
pkgs.mkShell {
packages = with pkgs; [
bash
gcc
rustup
openssl
];
shellHook = ''
echo $TMPDIR;
rustup default nightly;
rustup target add x86_64-unknown-none;
'';
}

View File

@ -3,7 +3,7 @@ use anyhow::anyhow;
use serde::Deserialize; use serde::Deserialize;
use std::{fs::File, path::Path}; use std::{fs::File, path::Path};
const SCHEMA_VERSION: &str = "0.2.0"; const SCHEMA_VERSION: &str = "0.3.0";
#[derive(Deserialize)] #[derive(Deserialize)]
pub enum ConfigEntry { pub enum ConfigEntry {

View File

@ -49,14 +49,16 @@ pub struct OnlineResponse {
#[derive(Deserialize, Clone)] #[derive(Deserialize, Clone)]
pub struct Minecraft { pub struct Minecraft {
#[allow(dead_code)] #[allow(dead_code)]
enabled: bool,
token: String, token: String,
host: Host, host: Host,
contact: Option<u64>, contact: Option<u64>,
} }
impl ServerInfo for Minecraft { impl ServerInfo for Minecraft {
fn new(token: String, host: Host, contact: Option<u64>) -> Self { fn new(token: String, host: Host, contact: Option<u64>, enabled: bool) -> Self {
Minecraft { Minecraft {
enabled,
token, token,
host, host,
contact, contact,
@ -117,4 +119,8 @@ impl ServerInfo for Minecraft {
fn supports_playerlist(&self) -> bool { fn supports_playerlist(&self) -> bool {
true true
} }
fn enabled(&self) -> bool {
self.enabled
}
} }

View File

@ -4,7 +4,7 @@ mod handlers;
mod request; mod request;
mod types; mod types;
use crate::bot_runner::BotRunner; use crate::{bot_runner::BotRunner, types::ServerInfo};
use futures::{self, future::try_join_all}; use futures::{self, future::try_join_all};
use log::*; use log::*;
use std::path::Path; use std::path::Path;
@ -18,7 +18,7 @@ async fn main() {
info!("Got config file"); info!("Got config file");
info!("Parsed {} handlers", config.entries.len()); info!("Parsed {} handlers", config.entries.len());
let mut bots: Vec<bot_runner::BotRunner> = vec![]; let mut bots: Vec<bot_runner::BotRunner> = vec![];
for item in config.entries { for item in config.entries.iter().filter(|item| {item.inner().enabled()}) {
bots.push(BotRunner::new(Box::new(item.inner())).await); bots.push(BotRunner::new(Box::new(item.inner())).await);
} }
let futures: Vec<_> = bots.iter_mut().map(|b| b.run()).collect(); let futures: Vec<_> = bots.iter_mut().map(|b| b.run()).collect();

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, contact: Option<u64>) -> Self fn new(token: String, addr: Host, contact: Option<u64>, enabled: bool) -> Self
where where
Self: Sized; Self: Sized;
@ -39,4 +39,6 @@ pub trait ServerInfo: Send + Sync {
fn supports_playerlist(&self) -> bool; fn supports_playerlist(&self) -> bool;
fn contact(&self) -> Option<u64>; fn contact(&self) -> Option<u64>;
fn enabled(&self) -> bool;
} }