Compare commits
No commits in common. "c966529a2b6fb0b451922a317089b8c747f05372" and "2999ca23014d6150252d26aebb01a2d89b575aa8" have entirely different histories.
c966529a2b
...
2999ca2301
|
|
@ -33,7 +33,6 @@ name = "affy"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"affluences-api",
|
"affluences-api",
|
||||||
"async-minecraft-ping",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
"poise",
|
"poise",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|
@ -98,19 +97,6 @@ dependencies = [
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "async-minecraft-ping"
|
|
||||||
version = "0.8.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "668b459c14dd8d9ef21e296af3f2a3651ff7dc3536e092fb0b09e528daaa6d89"
|
|
||||||
dependencies = [
|
|
||||||
"async-trait",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"thiserror",
|
|
||||||
"tokio",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-trait"
|
name = "async-trait"
|
||||||
version = "0.1.68"
|
version = "0.1.68"
|
||||||
|
|
|
||||||
|
|
@ -21,4 +21,3 @@ tokio = { version = "1.28.1", features = ["full"] }
|
||||||
chrono = "*"
|
chrono = "*"
|
||||||
uuid = "*"
|
uuid = "*"
|
||||||
poise = "0.5.5"
|
poise = "0.5.5"
|
||||||
async-minecraft-ping = "0.8.0"
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,6 @@ COPY --from=builder /build/dumb-init /build/affy/target/release/affy /bin/
|
||||||
|
|
||||||
WORKDIR /data
|
WORKDIR /data
|
||||||
|
|
||||||
ENV TZ=Europe/Brussels
|
|
||||||
|
|
||||||
USER www-data:www-data
|
USER www-data:www-data
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/dumb-init", "--"]
|
ENTRYPOINT ["/bin/dumb-init", "--"]
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,30 @@
|
||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use uuid::{uuid, Uuid};
|
use uuid::{uuid, Uuid};
|
||||||
|
|
||||||
const STERRE_BIB_ID: Uuid = uuid!("4737e57a-ee05-4f7b-901a-7bb541eeb297");
|
const STERRE_BIB_ID: Uuid = uuid!("4737e57a-ee05-4f7b-901a-7bb541eeb297");
|
||||||
const TIME_FORMAT: &str = "%H:%M";
|
const TIME_FORMAT: &str = "%H:%M";
|
||||||
|
|
||||||
|
/// Show this help menu
|
||||||
|
#[poise::command(prefix_command, track_edits, slash_command)]
|
||||||
|
pub async fn help(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Specific command to show help about"]
|
||||||
|
#[autocomplete = "poise::builtins::autocomplete_command"]
|
||||||
|
command: Option<String>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
poise::builtins::help(
|
||||||
|
ctx,
|
||||||
|
command.as_deref(),
|
||||||
|
poise::builtins::HelpConfiguration {
|
||||||
|
extra_text_at_bottom: "This is an example bot made to showcase features of my custom Discord bot framework",
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// List available timeslots for day
|
/// List available timeslots for day
|
||||||
#[poise::command(prefix_command, slash_command)]
|
#[poise::command(prefix_command, slash_command)]
|
||||||
pub async fn available(ctx: Context<'_>, date: NaiveDate) -> Result<(), Error> {
|
pub async fn available(ctx: Context<'_>, date: NaiveDate) -> Result<(), Error> {
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
use crate::{Context, Error};
|
|
||||||
use async_minecraft_ping::ServerDescription;
|
|
||||||
|
|
||||||
const DEFAULT_SERVER: &str = "rustybever.be";
|
|
||||||
|
|
||||||
/// Ping a minecraft server
|
|
||||||
#[poise::command(prefix_command, slash_command)]
|
|
||||||
pub async fn ping_mc(
|
|
||||||
ctx: Context<'_>,
|
|
||||||
#[description = "Address of the server"] address: Option<String>,
|
|
||||||
#[description = "Port the server runs on"] port: Option<u16>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let mut full_name = address.unwrap_or(DEFAULT_SERVER.to_string());
|
|
||||||
let mut builder = async_minecraft_ping::ConnectionConfig::build(&full_name);
|
|
||||||
|
|
||||||
if let Some(port) = port {
|
|
||||||
builder = builder.with_port(port);
|
|
||||||
full_name += &format!(":{}", port);
|
|
||||||
}
|
|
||||||
|
|
||||||
let conn = builder.connect().await?;
|
|
||||||
let status = conn.status().await?.status;
|
|
||||||
|
|
||||||
let description = match status.description {
|
|
||||||
ServerDescription::Plain(s) => s,
|
|
||||||
ServerDescription::Object { text } => text,
|
|
||||||
};
|
|
||||||
|
|
||||||
ctx.send(|f| {
|
|
||||||
f.embed(|e| {
|
|
||||||
e.description(format!("Server information for {}", full_name))
|
|
||||||
.field("version", status.version.name, false)
|
|
||||||
.field("description", description, false)
|
|
||||||
.field(
|
|
||||||
"players",
|
|
||||||
format!(
|
|
||||||
"{} of {} player(s) online",
|
|
||||||
status.players.online, status.players.max
|
|
||||||
),
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
mod affluence;
|
|
||||||
mod minecraft;
|
|
||||||
|
|
||||||
use crate::{Context, Data, Error};
|
|
||||||
|
|
||||||
pub fn commands() -> Vec<poise::structs::Command<Data, Error>> {
|
|
||||||
vec![help(), affluence::available(), minecraft::ping_mc()]
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Show this help menu
|
|
||||||
#[poise::command(prefix_command, track_edits, slash_command)]
|
|
||||||
pub async fn help(
|
|
||||||
ctx: Context<'_>,
|
|
||||||
#[description = "Specific command to show help about"]
|
|
||||||
#[autocomplete = "poise::builtins::autocomplete_command"]
|
|
||||||
command: Option<String>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
poise::builtins::help(
|
|
||||||
ctx,
|
|
||||||
command.as_deref(),
|
|
||||||
poise::builtins::HelpConfiguration {
|
|
||||||
extra_text_at_bottom: "This is an example bot made to showcase features of my custom Discord bot framework",
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,7 @@ mod commands;
|
||||||
|
|
||||||
use affluences_api::AffluencesClient;
|
use affluences_api::AffluencesClient;
|
||||||
use poise::serenity_prelude as serenity;
|
use poise::serenity_prelude as serenity;
|
||||||
use std::{env::var, time::Duration};
|
use std::{collections::HashMap, env::var, sync::Mutex, time::Duration};
|
||||||
|
|
||||||
// Types used by all command functions
|
// Types used by all command functions
|
||||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||||
|
|
@ -10,6 +10,7 @@ type Context<'a> = poise::Context<'a, Data, Error>;
|
||||||
|
|
||||||
// Custom user data passed to all command functions
|
// Custom user data passed to all command functions
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
|
votes: Mutex<HashMap<String, u32>>,
|
||||||
client: AffluencesClient,
|
client: AffluencesClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,7 +36,7 @@ async fn main() {
|
||||||
// FrameworkOptions contains all of poise's configuration option in one struct
|
// FrameworkOptions contains all of poise's configuration option in one struct
|
||||||
// Every option can be omitted to use its default value
|
// Every option can be omitted to use its default value
|
||||||
let options = poise::FrameworkOptions {
|
let options = poise::FrameworkOptions {
|
||||||
commands: commands::commands(),
|
commands: vec![commands::help(), commands::available()],
|
||||||
prefix_options: poise::PrefixFrameworkOptions {
|
prefix_options: poise::PrefixFrameworkOptions {
|
||||||
prefix: Some("~".into()),
|
prefix: Some("~".into()),
|
||||||
edit_tracker: Some(poise::EditTracker::for_timespan(Duration::from_secs(3600))),
|
edit_tracker: Some(poise::EditTracker::for_timespan(Duration::from_secs(3600))),
|
||||||
|
|
@ -90,6 +91,7 @@ async fn main() {
|
||||||
println!("Logged in as {}", _ready.user.name);
|
println!("Logged in as {}", _ready.user.name);
|
||||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||||
Ok(Data {
|
Ok(Data {
|
||||||
|
votes: Mutex::new(HashMap::new()),
|
||||||
client: AffluencesClient::new(),
|
client: AffluencesClient::new(),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue