Add context types to other commands

This commit is contained in:
toast 2024-12-07 13:29:26 +11:00
parent 5417dcaa1d
commit a7f67c1ec8
4 changed files with 26 additions and 18 deletions

View File

@ -1,3 +1,8 @@
mod ilo;
mod midi;
mod status;
mod uptime;
use kon_libs::{
KonData,
KonError,
@ -5,13 +10,6 @@ use kon_libs::{
PoiseCtx
};
use poise::Command;
mod ilo;
mod midi;
mod status;
mod uptime;
use {
ilo::ilo,
midi::midi_to_wav,
@ -25,7 +23,7 @@ macro_rules! commands {
}
}
pub fn register_cmds() -> Vec<Command<KonData, KonError>> { commands!(deploy, ping, midi_to_wav, status, ilo, uptime) }
pub fn register_cmds() -> Vec<poise::Command<KonData, KonError>> { commands!(deploy, ping, ilo, midi_to_wav, status, uptime) }
/// Deploy the commands globally or in a guild
#[poise::command(prefix_command, owners_only, guild_only)]
@ -35,7 +33,7 @@ pub async fn deploy(ctx: PoiseCtx<'_>) -> KonResult<()> {
}
/// Check if the bot is alive
#[poise::command(slash_command)]
#[poise::command(slash_command, install_context = "Guild|User", interaction_context = "Guild|BotDm|PrivateChannel")]
pub async fn ping(ctx: PoiseCtx<'_>) -> KonResult<()> {
ctx.reply(format!("Powong! `{:.2?}`", ctx.ping().await)).await?;
Ok(())

View File

@ -7,7 +7,10 @@ use {
},
poise::{
CreateReply,
serenity_prelude::CreateAttachment
serenity_prelude::{
CreateAttachment,
Message
}
},
regex::Regex,
std::{
@ -23,12 +26,12 @@ use {
/// Convert MIDI file to WAV
#[poise::command(
context_menu_command = "MIDI -> WAV",
install_context = "User",
install_context = "Guild|User",
interaction_context = "Guild|BotDm|PrivateChannel"
)]
pub async fn midi_to_wav(
ctx: super::PoiseCtx<'_>,
#[description = "MIDI file to be converted"] message: poise::serenity_prelude::Message
#[description = "MIDI file to be converted"] message: Message
) -> KonResult<()> {
let re = Regex::new(r"(?i)\.mid$").unwrap();
@ -87,9 +90,12 @@ pub async fn midi_to_wav(
&*wav_path,
format_bytes(metadata(&*wav_path).unwrap().size())
)))
.await
.unwrap();
.await?;
} else if reply.is_ok() {
println!(
"Discord[{}]: Processed file uploaded back to Discord channel",
ctx.command().qualified_name
);
remove_file(midi_path)?;
remove_file(&*wav_path)?;
}
@ -97,8 +103,7 @@ pub async fn midi_to_wav(
Err(y) => {
ctx
.send(CreateReply::default().content("Command didn't execute successfully, check console for more information!"))
.await
.unwrap();
.await?;
return Err(KonError::from(format!("Midi conversion failed: {y}")))
}

View File

@ -73,7 +73,12 @@ fn process_pms_statuses(servers: Vec<(String, Vec<Value>)>) -> Vec<(String, Stri
}
/// Query the server statuses
#[poise::command(slash_command, subcommands("wg"))]
#[poise::command(
slash_command,
install_context = "Guild|User",
interaction_context = "Guild|BotDm|PrivateChannel",
subcommands("wg")
)]
pub async fn status(_: super::PoiseCtx<'_>) -> KonResult<()> { Ok(()) }
/// Retrieve the server statuses from Wargaming

View File

@ -46,7 +46,7 @@ fn get_os_info() -> String {
}
/// Retrieve host and bot uptimes
#[poise::command(slash_command)]
#[poise::command(slash_command, install_context = "Guild|User", interaction_context = "Guild|BotDm|PrivateChannel")]
pub async fn uptime(ctx: super::PoiseCtx<'_>) -> KonResult<()> {
let bot = ctx.http().get_current_user().await.unwrap();
let mut sys = System::new_all();