Skip to content

Commit 92f1159

Browse files
committed
tag which facet is speaking in DMs
1 parent 4a6a829 commit 92f1159

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

crates/pattern_discord/src/endpoints/discord.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ impl DiscordEndpoint {
3535
}
3636
}
3737

38+
/// For DMs, prefix the content with an agent/facet tag when available
39+
fn dm_tagged_content(content: &str, origin: Option<&MessageOrigin>) -> String {
40+
if let Some(MessageOrigin::Agent { name, .. }) = origin {
41+
// Subtle Markdown tag so recipients know which facet is speaking
42+
format!("*[{}]* {}", name, content)
43+
} else {
44+
content.to_string()
45+
}
46+
}
47+
3848
/// Create a new Discord endpoint with token and optional config
3949
pub fn with_config(token: String, config: Option<&DiscordAppConfig>) -> Self {
4050
let mut endpoint = Self::new(token);
@@ -793,7 +803,8 @@ impl MessageEndpoint for DiscordEndpoint {
793803

794804
// If channel resolution failed, try user resolution for DMs
795805
if let Some(user_id) = self.resolve_user_id(target_id).await {
796-
self.send_dm(user_id, content).await?;
806+
let tagged = Self::dm_tagged_content(&content, origin);
807+
self.send_dm(user_id, tagged).await?;
797808
return Ok(Some(format!("dm:{}", user_id)));
798809
}
799810
}
@@ -826,7 +837,8 @@ impl MessageEndpoint for DiscordEndpoint {
826837

827838
// Finally check for user_id to send DM (lowest priority)
828839
if let Some(user_id) = meta.get("discord_user_id").and_then(|v| v.as_u64()) {
829-
self.send_dm(DiscordUserId::new(user_id), content).await?;
840+
let tagged = Self::dm_tagged_content(&content, origin);
841+
self.send_dm(DiscordUserId::new(user_id), tagged).await?;
830842
return Ok(Some(format!("dm:{}", user_id)));
831843
}
832844

@@ -852,14 +864,16 @@ impl MessageEndpoint for DiscordEndpoint {
852864
.await?;
853865
return Ok(Some(format!("channel:{}", chan_id)));
854866
} else if let Ok(usr_id) = user_id.parse::<u64>() {
855-
self.send_dm(DiscordUserId::new(usr_id), content).await?;
867+
let tagged = Self::dm_tagged_content(&content, origin);
868+
self.send_dm(DiscordUserId::new(usr_id), tagged).await?;
856869
return Ok(Some(format!("dm:{}", usr_id)));
857870
}
858871
}
859872

860873
// Fall back to default DM user if configured
861874
if let Some(user) = self.default_dm_user {
862-
self.send_dm(user, content).await?;
875+
let tagged = Self::dm_tagged_content(&content, origin);
876+
self.send_dm(user, tagged).await?;
863877
return Ok(Some(format!("default_dm:{}", user)));
864878
}
865879

0 commit comments

Comments
 (0)