Messages
Changing outgoing messages
Section titled “Changing outgoing messages”pre-send runs before a message is sent and pre-edit before an edit is saved. Both return a send-decision:
| Decision | Effect |
|---|---|
keep |
Send unchanged |
replace(content) |
Send with new content. Plugins after this one see the new content |
cancel |
Do not send. No later plugin runs |
fn pre_send(&mut self, message: OutgoingMessage) -> SendDecision { if message.content.starts_with("@silent ") { SendDecision::Keep } else { SendDecision::Replace(format!("@silent {}", message.content)) }}List Hook::MessagePreSend and Hook::MessagePreEdit in hooks to receive them. ClearURLs and Unindent are complete examples.
Extending rendered messages
Section titled “Extending rendered messages”| Hook | Where | Returns |
|---|---|---|
message-accessories |
Below the message content | elements |
message-decorations |
Next to the author’s name | elements |
message-popover-buttons |
The hover toolbar | popover-buttons |
Each receives the full message. These run on every render of every visible message, so return quickly.
fn message_decorations(&mut self, message: Message) -> Vec<Element> { if !message.author.bot { return Vec::new(); } vec![View::icon(Icon::Named("robot".into())).tooltip("Bot").into_element()]}Clicks on popover buttons arrive as an action event carrying the button’s action string. Encode whatever the handler needs in that string, for example the message ID.
Reading messages
Section titled “Reading messages”client::get_message and client::list_messages read the messages PhoenixCord has cached. Subscribe to message-created, message-updated and message-deleted to follow them as they change. Update and delete events include the previous version of the message when it was cached.