diff --git a/src/commands/edit.rs b/src/commands/edit.rs index 4fa187b..02f0bfd 100644 --- a/src/commands/edit.rs +++ b/src/commands/edit.rs @@ -36,6 +36,9 @@ pub async fn mate( #[description = "the new avatar to use when proxying"] avatar: Option, #[description = "the mate's bio"] bio: Option, #[description = "the mate's pronouns"] pronouns: Option, + #[description = "a signature to add to any proxied messages (ie `💙- text`)"] signature: Option< + String, + >, ) -> Result<()> { let database = &ctx.data().database; @@ -67,6 +70,7 @@ pub async fn mate( selector, publicity, avatar_url, + signature, ) .await?; diff --git a/src/commands/mate.rs b/src/commands/mate.rs index 9bc0d32..25ae843 100644 --- a/src/commands/mate.rs +++ b/src/commands/mate.rs @@ -4,7 +4,7 @@ use poise::serenity_prelude::{self as serenity}; use super::{autocomplete::mate as mate_autocomplete, CommandContext}; use crate::{ - models::{DBCollective, DBMate, DBMate__new}, + models::{DBCollective, DBMate, DBMate__new, Signature}, utils::{ collectives::{get_or_create_collective, update_switch_logs}, messages::parse_selector, @@ -28,6 +28,9 @@ pub async fn create( >, #[description = "the mate's bio"] bio: Option, #[description = "the mate's pronouns"] pronouns: Option, + #[description = "a signature to add to any proxied messages (ie `💙- text`)"] signature: Option< + String, + >, ) -> Result<()> { let database = &ctx.data().database; let mates_collection = database.collection::("mates"); @@ -58,6 +61,11 @@ pub async fn create( } else { avatar_url = envvar("DEFAULT_AVATAR_URL"); } + let signature = if let Some(signature) = signature { + Some(Signature::parse(signature)) + } else { + None + }; let mate = DBMate__new! { user_id = ctx.author().id.get() as i64, @@ -69,6 +77,7 @@ pub async fn create( bio, pronouns, display_name, + signature, autoproxy = false, }; diff --git a/src/models.rs b/src/models.rs index bb86559..4ac9ba1 100644 --- a/src/models.rs +++ b/src/models.rs @@ -22,14 +22,41 @@ pub struct DBMate { pub prefix: Option, pub postfix: Option, pub pronouns: Option, + pub signature: Option, pub display_name: Option, } +#[derive(Clone, Debug, Default, Serialize, Deserialize)] +pub struct Signature { + pub prefix: String, + pub postfix: String, +} + +impl Signature { + pub fn parse(signature: String) -> Self { + let mut split_sig = signature.split("text"); + + let split_sig = (split_sig.next(), split_sig.next()); + + let split_sig = match split_sig { + (None, None) => (String::new(), String::new()), + (None, Some(r)) => (String::new(), r.to_string()), + (Some(l), None) => (l.to_string(), String::new()), + (Some(l), Some(r)) => (l.to_string(), r.to_string()), + }; + + Signature { + prefix: split_sig.0, + postfix: split_sig.1, + } + } +} + #[impl_orderless] impl DBMate { #[make_orderless( public = true, - defs(bio = None, prefix = None, postfix = None, pronouns = None, display_name = None, id = None), + defs(bio = None, prefix = None, postfix = None, pronouns = None, display_name = None, signature = None, id = None), )] pub fn new( user_id: i64, @@ -42,6 +69,7 @@ impl DBMate { postfix: Option, pronouns: Option, display_name: Option, + signature: Option, id: Option, ) -> DBMate { DBMate { @@ -55,6 +83,7 @@ impl DBMate { postfix, pronouns, display_name, + signature, id, } } @@ -69,6 +98,7 @@ impl DBMate { selector: Option, publicity: Option, avatar: Option, + signature: Option, ) -> Result<()> { let current_name = self.name.clone(); @@ -104,6 +134,10 @@ impl DBMate { self.avatar = avatar; } + if let Some(signature) = signature { + self.signature = Some(Signature::parse(signature)) + } + collection .find_one_and_replace( doc! { "user_id": self.user_id, "name": current_name }, diff --git a/src/utils/messages.rs b/src/utils/messages.rs index f050bda..39de829 100644 --- a/src/utils/messages.rs +++ b/src/utils/messages.rs @@ -40,7 +40,7 @@ pub async fn send_proxied_message( get_webhook_or_create(http, &channels_collection, message.channel_id).await?; let new_content = message.content.clone(); - let new_content = message + let mut new_content = message .content .clone() .strip_prefix(&mate.prefix.clone().unwrap_or_default()) @@ -49,6 +49,10 @@ pub async fn send_proxied_message( .unwrap_or(&new_content) .to_string(); + if let Some(sig) = &mate.signature { + new_content = format!("{}{}{}", sig.prefix, new_content, sig.postfix) + } + let mut builder = ExecuteWebhook::new(); builder = builder