src/lib.rs
59 lines · 1262 bytes
1mod executor;
2mod room_buffer;
3mod server;
4
5use std::collections::HashMap;
6use tokio::runtime::Runtime;
7
8use weechat::{
9 weechat_plugin, ArgsWeechat, Weechat, WeechatPlugin, WeechatResult,
10};
11
12use crate::executor::cleanup_executor;
13use crate::server::MatrixServer;
14
15const PLUGIN_NAME: &str = "matrix";
16
17struct Matrix {
18 tokio: Option<Runtime>,
19 servers: HashMap<String, MatrixServer>,
20}
21
22impl WeechatPlugin for Matrix {
23 fn init(weechat: &Weechat, _args: ArgsWeechat) -> WeechatResult<Self> {
24 let runtime = Runtime::new().unwrap();
25
26 let server_name = "localhost";
27
28 let mut server = MatrixServer::new(server_name);
29 let mut servers = HashMap::new();
30
31 server.connect(&runtime);
32 servers.insert(server_name.to_owned(), server);
33
34 Ok(Matrix {
35 tokio: Some(runtime),
36 servers,
37 })
38 }
39}
40
41impl Drop for Matrix {
42 fn drop(&mut self) {
43 let runtime = self.tokio.take();
44
45 if let Some(r) = runtime {
46 r.shutdown_now();
47 }
48 cleanup_executor();
49 }
50}
51
52weechat_plugin!(
53 Matrix,
54 name: "matrix",
55 author: "Damir Jelić <poljar@termina.org.uk>",
56 description: "Matrix protocol",
57 version: "0.1.0",
58 license: "ISC"
59);