Add 'enable' field
This commit is contained in:
parent
bd6481f1a1
commit
0b3098726e
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix",
|
||||
"nixEnvSelector.useFlakes": false
|
||||
}
|
||||
1046
Cargo.lock
generated
1046
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
20
Cargo.toml
20
Cargo.toml
@ -1,17 +1,17 @@
|
||||
[package]
|
||||
name = "playerbot"
|
||||
version = "1.2.0"
|
||||
version = "1.3.0"
|
||||
edition = "2021"
|
||||
repository = "https://git.shibedrill.site/shibedrill/playerbot"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.102"
|
||||
env_logger = "0.11.10"
|
||||
futures = "0.3.32"
|
||||
log = "0.4.29"
|
||||
anyhow = "1.0.104"
|
||||
env_logger = "0.11.11"
|
||||
futures = "0.3.33"
|
||||
log = "0.4.33"
|
||||
poise = "0.6.2"
|
||||
reqwest = {version = "0.13.3", features = ["json"]}
|
||||
serde = {version = "1.0.215", features = ["derive", "serde_derive"]}
|
||||
serde_json = "1.0.149"
|
||||
tokio = {version = "1.41.1", features = ["full"]}
|
||||
url = "2.5.3"
|
||||
reqwest = {version = "0.13.4", features = ["json"]}
|
||||
serde = {version = "1.0.229", features = ["derive", "serde_derive"]}
|
||||
serde_json = "1.0.151"
|
||||
tokio = {version = "1.53.1", features = ["full"]}
|
||||
url = "2.5.8"
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -18,10 +18,11 @@ The program requires a file named config.json to be present in its current worki
|
||||
|
||||
```json
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"version": "0.3.0",
|
||||
"entries": [
|
||||
{
|
||||
"Minecraft": {
|
||||
"enabled": true, // If false, this handler won't be loaded
|
||||
"host": {
|
||||
"Ipv4": "10.0.0.2:233" // Can be "Domain", "Ipv4", or "Ipv6", required
|
||||
},
|
||||
|
||||
21
shell.nix
Normal file
21
shell.nix
Normal 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;
|
||||
'';
|
||||
|
||||
}
|
||||
@ -3,7 +3,7 @@ use anyhow::anyhow;
|
||||
use serde::Deserialize;
|
||||
use std::{fs::File, path::Path};
|
||||
|
||||
const SCHEMA_VERSION: &str = "0.2.0";
|
||||
const SCHEMA_VERSION: &str = "0.3.0";
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub enum ConfigEntry {
|
||||
|
||||
@ -49,14 +49,16 @@ pub struct OnlineResponse {
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct Minecraft {
|
||||
#[allow(dead_code)]
|
||||
enabled: bool,
|
||||
token: String,
|
||||
host: Host,
|
||||
contact: Option<u64>,
|
||||
}
|
||||
|
||||
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 {
|
||||
enabled,
|
||||
token,
|
||||
host,
|
||||
contact,
|
||||
@ -117,4 +119,8 @@ impl ServerInfo for Minecraft {
|
||||
fn supports_playerlist(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn enabled(&self) -> bool {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ mod handlers;
|
||||
mod request;
|
||||
mod types;
|
||||
|
||||
use crate::bot_runner::BotRunner;
|
||||
use crate::{bot_runner::BotRunner, types::ServerInfo};
|
||||
use futures::{self, future::try_join_all};
|
||||
use log::*;
|
||||
use std::path::Path;
|
||||
@ -18,7 +18,7 @@ async fn main() {
|
||||
info!("Got config file");
|
||||
info!("Parsed {} handlers", config.entries.len());
|
||||
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);
|
||||
}
|
||||
let futures: Vec<_> = bots.iter_mut().map(|b| b.run()).collect();
|
||||
|
||||
@ -21,7 +21,7 @@ pub struct ServerOnlineResponse {
|
||||
|
||||
#[allow(dead_code)]
|
||||
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
|
||||
Self: Sized;
|
||||
|
||||
@ -39,4 +39,6 @@ pub trait ServerInfo: Send + Sync {
|
||||
fn supports_playerlist(&self) -> bool;
|
||||
|
||||
fn contact(&self) -> Option<u64>;
|
||||
|
||||
fn enabled(&self) -> bool;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user