Add the skip command and remove the unused commands folder

This commit is contained in:
2025-08-14 13:42:36 -03:00
parent 09ed3b870e
commit 55431d580e
4 changed files with 97 additions and 1 deletions
View File
View File
+95
View File
@@ -109,6 +109,101 @@ impl Command<State> for CallCommand {
}
}
#[derive(Debug)]
pub struct SkipCommand;
#[async_trait]
impl Command<State> for SkipCommand {
fn name(&self) -> &'static str {
"skip"
}
fn aliases(&self) -> &'static [&'static str] {
&["s", "next"]
}
async fn execute(
&self,
ctx: CommandContext<'_, State>,
_args: &str,
) -> Result<(), CommandError> {
let channel = Channel::get_or_create_by_id(
ctx.event.channel_id.get(),
&ctx.rt.state.db,
&ctx.rt.http,
)
.await
.inspect_err(|e| {
log::error!("Failed to get or create channel: {e:?}");
})
.map_err(|_| CommandError::DatabaseQueryFailed)?;
if channel.call_id.is_none() {
ctx.send()
.content(format!(
"❌ You're not on a call! Use `{}call` to start one.",
ctx.prefix
))
.await
.map_err(|_| CommandError::MessageSendingFailed)?;
return Ok(());
}
if channel.is_searching {
ctx.send()
.content(format!(
"☎️ You're already searching for a call! Use `{}hangup` to cancel the search.",
ctx.prefix
))
.await
.map_err(|_| CommandError::MessageSendingFailed)?;
return Ok(());
}
let call = Call::get_by_id(channel.call_id.unwrap(), &ctx.rt.state.db)
.await
.map_err(|_| CommandError::DatabaseQueryFailed)?
.ok_or(CommandError::DatabaseInconsistentState)?;
call.hangup(&ctx.rt.state.db)
.await
.inspect_err(|e| log::error!("Failed to hang up call: {e:?}"))
.map_err(|_| CommandError::DatabaseQueryFailed)?;
let other_channel_id = call.other_party_channel_id(ctx.event.channel_id.get());
ctx.rt
.http
.create_message(Id::new(other_channel_id))
.content("☎️ The other party hung up the phone.")
.await
.map_err(|_| CommandError::MessageSendingFailed)?;
let call = Call::start(&channel, &ctx.rt.state.db)
.await
.map_err(|_| CommandError::DatabaseQueryFailed)?;
if let Some(call) = call {
ctx.send().content("☎️ Call connected. Say hi!").await.bye();
ctx.rt
.http
.create_message(Id::new(call.other_party_channel_id(channel.id)))
.content("☎️ Call connected. Say hi!")
.await
.bye();
} else {
ctx.send()
.content("☎️ Skipped! Searching for a call...")
.await
.map_err(|_| CommandError::MessageSendingFailed)?;
}
Ok(())
}
}
#[derive(Debug)]
pub struct HangupCommand;
+2 -1
View File
@@ -120,7 +120,7 @@ use crate::{
groups::{
about::{commands::HelpCommand, components::HelpGoBackButton},
calls::{
commands::{CallCommand, HangupCommand},
commands::{CallCommand, HangupCommand, SkipCommand},
events::MessageRedirector,
},
gateway::events::{ReadyHandler, ReconnectHandler},
@@ -190,6 +190,7 @@ async fn start(token: String, database_addr: String) {
.intent(Intents::MESSAGE_CONTENT)
.command(HelpCommand)
.command(CallCommand::new())
.command(SkipCommand)
.command(HangupCommand)
.component(HelpGoBackButton)
.on_ready(ReadyHandler)