35 lines
900 B
Rust
Raw Normal View History

use plugins::Plugin;
use toml::Table;
use event::Event;
pub struct EchoPlugin {
prefix: String
}
impl EchoPlugin {
pub fn new (configuration: &Table) -> Box<Plugin> {
let prefix = configuration.get("prefix")
.and_then(|value| value.as_str())
.unwrap_or("!echo ");
Box::new(EchoPlugin {
prefix: String::from(prefix)
})
}
}
impl Plugin for EchoPlugin {
fn on_event (&self, event: Event) {
match event {
Event::Message { content: message, channel: channel, sender: sender } => {
if message.starts_with(self.prefix.as_str()) {
let substring = String::from(&message[self.prefix.chars().count()..]);
println!("Echo: {:?}", substring);
}
}
_ => ()
}
}
}