servers/plugin_test/src/lib.rs

64 lines
1.4 KiB
Rust
Raw Normal View History

2022-06-04 18:10:21 +00:00
use async_trait::async_trait;
2022-06-04 19:34:53 +00:00
use servers::{
2022-06-16 17:31:09 +00:00
plugins::{
Command, CommandManagerType, CommandRegistrar, Event, EventRegistrar, Plugin,
PluginRegistrar,
},
tcp::Client,
2022-06-04 19:34:53 +00:00
};
2022-06-04 18:10:21 +00:00
struct PluginTest;
#[async_trait]
impl Plugin for PluginTest {
fn name(&self) -> &'static str {
"test"
}
async fn on_plugin_load(&self) {}
async fn on_plugin_unload(&self) {}
}
#[async_trait]
impl Command for PluginTest {
fn name(&self) -> &'static str {
"/test"
}
fn help(&self) -> &'static str {
"test command"
}
async fn execute(&self, client: &mut Client, _args: Vec<&str>, _commands: &CommandManagerType) {
client.send("content").expect("send message")
2022-06-04 18:10:21 +00:00
}
}
2022-06-16 17:31:09 +00:00
#[async_trait]
impl Event for PluginTest {
fn name(&self) -> &'static str {
"onConnect"
}
async fn execute(&self, client: &mut Client) {
client
.send(&format!("Welcome {}", client.stream.peer_addr().unwrap()))
.expect("send message")
}
}
2022-06-04 18:10:21 +00:00
#[no_mangle]
2022-06-16 17:31:09 +00:00
pub fn plugin_entry(
plugin: &mut dyn PluginRegistrar,
command: &mut dyn CommandRegistrar,
event: &mut dyn EventRegistrar,
) {
// register plugin
plugin.register(Box::new(PluginTest));
// register command
command.register(Box::new(PluginTest));
// register plugin
event.register(Box::new(PluginTest));
2022-06-04 18:10:21 +00:00
}