2025-11-22 12:20:56 +00:00
|
|
|
//! Plugin command definitions.
|
|
|
|
|
|
|
|
|
|
// Dear future me: If you forget the JSON translations in the future you'll
|
|
|
|
|
// thank me for the comment overkill.
|
|
|
|
|
|
2025-11-13 10:35:38 +00:00
|
|
|
use std::fmt::Display;
|
|
|
|
|
|
2025-11-14 11:06:57 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2025-11-13 10:35:38 +00:00
|
|
|
|
2025-11-22 12:20:56 +00:00
|
|
|
/// Message types accepted from plugins.
|
2025-11-14 11:06:57 +00:00
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
2025-11-22 12:20:56 +00:00
|
|
|
pub enum PluginMsg {
|
|
|
|
|
/// Plugin message indicating the bot should send a [`message`] to [`channel`].
|
|
|
|
|
/// {
|
|
|
|
|
/// "SendMessage": {
|
|
|
|
|
/// "channel": "channel_name",
|
|
|
|
|
/// "message": "your message here"
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// }
|
|
|
|
|
SendMessage {
|
|
|
|
|
/// The IRC channel to send the [`message`] to.
|
|
|
|
|
channel: String,
|
|
|
|
|
/// The [`message`] to send.
|
|
|
|
|
message: String,
|
|
|
|
|
},
|
2025-11-13 10:35:38 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-22 12:20:56 +00:00
|
|
|
impl Display for PluginMsg {
|
2025-11-13 10:35:38 +00:00
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
match self {
|
|
|
|
|
Self::SendMessage { channel, message } => {
|
|
|
|
|
write!(f, "[{channel}]: {message}")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|