use crate::cap::{Auth, Cap};
use crate::error::{BotError, unbound_domain};
use crate::verb;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Message {
text: String,
}
impl Message {
#[must_use]
pub fn new(text: impl Into<String>) -> Self {
Self { text: text.into() }
}
#[must_use]
pub fn text(&self) -> &str {
&self.text
}
}
#[derive(Debug)]
pub struct Slack {
channel: String,
caps: Vec<Cap>,
}
impl Slack {
pub fn new(channel: impl Into<String>) -> Self {
Self {
channel: channel.into(),
caps: vec![Cap::notify(), Cap::net()],
}
}
}
impl verb::Execute for Slack {
type Input = Message;
type Output = ();
fn required_caps(&self) -> &[Cap] {
&self.caps
}
async fn execute_action(&self, call: (Auth, &Message)) -> Result<(), BotError> {
unbound_domain(
&call.0,
self.required_caps(),
self.domain_id(),
"notifying",
&self.channel,
)
}
fn domain_id(&self) -> &str {
"notify::slack"
}
}
pub fn slack(channel: impl Into<String>) -> Slack {
Slack::new(channel)
}