refactor: move commands to separate module
This commit is contained in:
parent
2999ca2301
commit
38994a29a0
6 changed files with 47 additions and 24 deletions
|
|
@ -1,30 +1,11 @@
|
|||
use crate::{Context, Error};
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use uuid::{uuid, Uuid};
|
||||
|
||||
const STERRE_BIB_ID: Uuid = uuid!("4737e57a-ee05-4f7b-901a-7bb541eeb297");
|
||||
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
|
||||
#[poise::command(prefix_command, slash_command)]
|
||||
pub async fn available(ctx: Context<'_>, date: NaiveDate) -> Result<(), Error> {
|
||||
27
src/commands/mod.rs
Normal file
27
src/commands/mod.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
mod affluence;
|
||||
|
||||
use crate::{Context, Data, Error};
|
||||
|
||||
pub fn commands() -> Vec<poise::structs::Command<Data, Error>> {
|
||||
vec![help(), affluence::available()]
|
||||
}
|
||||
|
||||
/// 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 poise::serenity_prelude as serenity;
|
||||
use std::{collections::HashMap, env::var, sync::Mutex, time::Duration};
|
||||
use std::{env::var, time::Duration};
|
||||
|
||||
// Types used by all command functions
|
||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
|
|
@ -10,7 +10,6 @@ type Context<'a> = poise::Context<'a, Data, Error>;
|
|||
|
||||
// Custom user data passed to all command functions
|
||||
pub struct Data {
|
||||
votes: Mutex<HashMap<String, u32>>,
|
||||
client: AffluencesClient,
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +35,7 @@ async fn main() {
|
|||
// FrameworkOptions contains all of poise's configuration option in one struct
|
||||
// Every option can be omitted to use its default value
|
||||
let options = poise::FrameworkOptions {
|
||||
commands: vec![commands::help(), commands::available()],
|
||||
commands: commands::commands(),
|
||||
prefix_options: poise::PrefixFrameworkOptions {
|
||||
prefix: Some("~".into()),
|
||||
edit_tracker: Some(poise::EditTracker::for_timespan(Duration::from_secs(3600))),
|
||||
|
|
@ -91,7 +90,6 @@ async fn main() {
|
|||
println!("Logged in as {}", _ready.user.name);
|
||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||
Ok(Data {
|
||||
votes: Mutex::new(HashMap::new()),
|
||||
client: AffluencesClient::new(),
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue