55 lines
1.9 KiB
Rust
55 lines
1.9 KiB
Rust
use poise::serenity_prelude::Activity;
|
|
use crate::{ManifoldContext, ManifoldData, ManifoldResult};
|
|
use crate::error::ManifoldError;
|
|
|
|
#[poise::command(slash_command, prefix_command, owners_only)]
|
|
async fn dump_config(ctx: ManifoldContext<'_>) -> ManifoldResult<()> {
|
|
let config = &ctx.data().bot_config;
|
|
|
|
ctx.say(format!("Config dump; {:?}", config.config)).await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[poise::command(slash_command, prefix_command, owners_only)]
|
|
async fn get_environment(ctx: ManifoldContext<'_>) -> ManifoldResult<()> {
|
|
let environment = ctx.data().bot_config.get_environment();
|
|
|
|
ctx.say(format!("Currently running under the {} environment", environment)).await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[poise::command(slash_command, prefix_command, owners_only)]
|
|
async fn get_config(ctx: ManifoldContext<'_>, #[description="Config key"] key: String) -> ManifoldResult<()> {
|
|
let config = &ctx.data().bot_config;
|
|
|
|
let value = match config.get_value(&key) {
|
|
Ok(v) => v.clone(),
|
|
Err(_) => "not found, sorry!".to_string()
|
|
};
|
|
|
|
ctx.say(format!("Value for key {} was {}", &key, &value)).await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[poise::command(slash_command, prefix_command, owners_only)]
|
|
async fn register_commands(ctx: ManifoldContext<'_>) -> ManifoldResult<()> {
|
|
poise::builtins::register_application_commands_buttons(ctx).await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[poise::command(slash_command, prefix_command, track_edits, aliases("sa"), required_permissions = "MODERATE_MEMBERS")]
|
|
async fn set_activity(ctx: ManifoldContext<'_>, #[rest] #[description="Who to watch"] target: String) -> ManifoldResult<()> {
|
|
ctx.serenity_context().set_activity(Activity::watching(&target)).await;
|
|
|
|
ctx.say(format!("Okay, I'll start watching {}", target)).await?;
|
|
Ok(())
|
|
}
|
|
|
|
pub fn commands() -> [poise::Command<ManifoldData, ManifoldError>; 5] {
|
|
[dump_config(), get_environment(), get_config(), register_commands(), set_activity()]
|
|
}
|