99 lines
3.2 KiB
Rust
99 lines
3.2 KiB
Rust
|
|
use poise::serenity_prelude::*;
|
||
|
|
|
||
|
|
use crate::{ManifoldContext, ManifoldData};
|
||
|
|
use crate::built_info;
|
||
|
|
use crate::error::{ManifoldError, ManifoldResult};
|
||
|
|
|
||
|
|
#[poise::command(prefix_command, track_edits, slash_command)]
|
||
|
|
async fn help(
|
||
|
|
ctx: ManifoldContext<'_>,
|
||
|
|
#[description = "Help about a specific command"] command: Option<String>
|
||
|
|
) -> ManifoldResult<()> {
|
||
|
|
|
||
|
|
let responses = &ctx.data().responses;
|
||
|
|
|
||
|
|
let config = poise::builtins::HelpConfiguration {
|
||
|
|
extra_text_at_bottom: &*format!("{}", responses.get_response(&"help footer".to_string()).unwrap_or(&"".to_string())),
|
||
|
|
..Default::default()
|
||
|
|
};
|
||
|
|
|
||
|
|
poise::builtins::help(ctx, command.as_deref(), config).await?;
|
||
|
|
|
||
|
|
Ok(())
|
||
|
|
}
|
||
|
|
|
||
|
|
#[poise::command(slash_command, prefix_command)]
|
||
|
|
async fn ping(ctx: ManifoldContext<'_>,) -> ManifoldResult<()> {
|
||
|
|
let requestor = {
|
||
|
|
let calling_user = ctx.author();
|
||
|
|
calling_user.mention().to_string()
|
||
|
|
};
|
||
|
|
|
||
|
|
ctx.say(format!("{}: Ping? Pong!", requestor)).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(())
|
||
|
|
}
|
||
|
|
|
||
|
|
#[poise::command(slash_command, prefix_command)]
|
||
|
|
async fn version(ctx: ManifoldContext<'_>) -> ManifoldResult<()> {
|
||
|
|
let git_info: String = built_info::GIT_VERSION.unwrap_or("unknown").to_string();
|
||
|
|
let version_string: String = format!("Version {} built at {} revision {}", built_info::PKG_VERSION, built_info::BUILT_TIME_UTC, git_info);
|
||
|
|
|
||
|
|
ctx.send(|f| f
|
||
|
|
.reply(true)
|
||
|
|
.content(version_string)).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 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(())
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn commands() -> [poise::Command<ManifoldData, ManifoldError>; 8] {
|
||
|
|
[help(), ping(), register_commands(), set_activity(), version(), get_config(), dump_config(), get_environment()]
|
||
|
|
}
|