Skip to content

Commit

Permalink
modularize poise commands into separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
ivinjabraham committed Oct 14, 2024
1 parent f3765a8 commit afc3fc9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
33 changes: 33 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
amFOSS Daemon: A discord bot for the amFOSS Discord server.
Copyright (C) 2024 amFOSS
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use crate::Data;

type Context<'a> = poise::Context<'a, Data, Error>;
type Error = Box<dyn std::error::Error + Send + Sync>;

#[poise::command(prefix_command)]
async fn amdctl(ctx: Context<'_>) -> Result<(), Error> {
ctx.say("amD is up and running.").await?;
Ok(())
}

pub fn get_commands() -> Vec<poise::Command<Data, Error>> {
vec![
amdctl(),
]
}
12 changes: 3 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
mod commands;

use anyhow::Context as _;

struct Data {}
type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>;

#[poise::command(prefix_command)]
async fn amdctl(ctx: Context<'_>) -> Result<(), Error> {
ctx.say("amD is up and running.").await?;
Ok(())
}

#[shuttle_runtime::main]
async fn main(
Expand All @@ -37,7 +31,7 @@ async fn main(

let framework = poise::Framework::builder()
.options(poise::FrameworkOptions {
commands: vec![amdctl()],
commands: commands::get_commands(),
prefix_options: poise::PrefixFrameworkOptions {
prefix: Option::Some(String::from("$")),
..Default::default()
Expand Down

0 comments on commit afc3fc9

Please sign in to comment.