Add p.rh command

This commit is contained in:
2026-04-06 17:11:08 -03:00
parent 5fdea76f37
commit 78fcfe386d
5 changed files with 180 additions and 7 deletions
+61 -1
View File
@@ -3,7 +3,7 @@ use std::time::Duration;
use scylla::client::session::Session;
use crate::database::models::{Message, User};
use crate::database::models::{Channel, Message, User};
use crate::extras::Extras;
use crate::framework::commands::arguments::{ArgumentParsingError, FromArguments, NeedyString};
use crate::framework::commands::context::CommandContext;
@@ -206,3 +206,63 @@ impl DerefMut for DurationArgument {
&mut self.0
}
}
#[derive(Debug, Clone)]
pub struct ChannelArgument(pub Channel);
impl FromArguments<State, Extras> for ChannelArgument {
async fn from_args<'a>(
args: &'a str,
ctx: &'a CommandContext<'_, State, Extras>,
) -> Result<(Self, &'a str), ArgumentParsingError> {
let (identifier, args) = NeedyString::from_args(args, ctx).await?;
let identifier = identifier.0.trim();
if identifier == "." || identifier == "this" || identifier == "here" {
let channel = Channel::get_by_id(ctx.event.channel_id.get(), &ctx.rt.state.db).await?;
if let Some(channel) = channel {
return Ok((Self(channel), args));
}
} else if identifier.starts_with("<#") && identifier.ends_with(">") {
// The argument is a Discord mention.
let channel_id: u64 = identifier[2..identifier.len() - 1]
.to_string()
.parse()
.map_err(|_| ArgumentParsingError::InvalidArgument)?;
let channel = Channel::get_by_id(channel_id, &ctx.rt.state.db).await?;
if let Some(channel) = channel {
return Ok((Self(channel), args));
}
} else {
let channel_id: u64 = identifier
.parse()
.map_err(|_| ArgumentParsingError::InvalidArgument)?;
let channel = Channel::get_by_id(channel_id, &ctx.rt.state.db).await?;
if let Some(channel) = channel {
return Ok((Self(channel), args));
}
}
Err(ArgumentParsingError::MissingArgument)
}
}
impl Deref for ChannelArgument {
type Target = Channel;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for ChannelArgument {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}