Performance upgrades, fixes for 2 issues
This commit is contained in:
@@ -44,13 +44,32 @@ pub async fn respond_message(
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn defer_message(
|
||||
ctx: &Context,
|
||||
command: &ApplicationCommandInteraction,
|
||||
ephemeral: bool,
|
||||
) {
|
||||
if let Err(why) = command
|
||||
.create_interaction_response(&ctx.http, |response| {
|
||||
response
|
||||
.kind(InteractionResponseType::DeferredChannelMessageWithSource)
|
||||
.interaction_response_data(|message| message.ephemeral(ephemeral))
|
||||
})
|
||||
.await
|
||||
{
|
||||
error!("Error deferring message: {:?}", why);
|
||||
}
|
||||
}
|
||||
|
||||
pub type CommandOutput = Pin<Box<dyn Future<Output = ()> + Send>>;
|
||||
pub type CommandExecutor = fn(Context, ApplicationCommandInteraction) -> CommandOutput;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CommandManager {
|
||||
commands: HashMap<String, CommandInfo>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CommandInfo {
|
||||
pub name: String,
|
||||
pub executor: CommandExecutor,
|
||||
|
||||
@@ -5,7 +5,7 @@ use serenity::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
bot::commands::{respond_message, CommandOutput},
|
||||
bot::commands::{defer_message, respond_message, CommandOutput},
|
||||
session::manager::{SessionCreateError, SessionManager},
|
||||
utils::embed::{EmbedBuilder, Status},
|
||||
};
|
||||
@@ -46,6 +46,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
|
||||
// Check if another session is already active in this server
|
||||
let session_opt = session_manager.get_session(guild.id).await;
|
||||
|
||||
if let Some(session) = &session_opt {
|
||||
if let Some(owner) = session.get_owner().await {
|
||||
let msg = if owner == command.user.id {
|
||||
@@ -91,6 +92,8 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
return;
|
||||
}
|
||||
|
||||
defer_message(&ctx, &command, true).await;
|
||||
|
||||
if let Some(session) = &session_opt {
|
||||
if let Err(why) = session.update_owner(&ctx, command.user.id).await {
|
||||
// Need to link first
|
||||
|
||||
Reference in New Issue
Block a user