Commit 5c8d88fb27
5c8d88fb27c1359272af0364a4b8fb82b8037540
parent: 87041345e6
Unsigned
Damir Jelić <poljar@termina.org.uk> · 2019-12-01 14:37 UTC
config: Add initial config.
Layout: unified · split
.pre-commit-config.yaml
−7
| @@ -13,10 +13,3 @@ repos: |
| 13 | language: system |
13 | language: system |
| 14 | types: [file, rust] |
14 | types: [file, rust] |
| 15 | entry: cargo fmt -- --check |
15 | entry: cargo fmt -- --check |
| 16 | |
| |
| 17 | - id: test |
| |
| 18 | name: test |
| |
| 19 | language: system |
| |
| 20 | files: '\.rs$' |
| |
| 21 | entry: cargo test --lib |
| |
| 22 | pass_filenames: false |
| |
src/config.rs
added
+14
| @@ -0,0 +1,14 @@ |
| |
1 | use crate::PLUGIN_NAME; |
| |
2 | use weechat::Weechat; |
| |
3 | |
| |
4 | pub struct Config(weechat::Config); |
| |
5 | |
| |
6 | impl Config { |
| |
7 | pub fn new(weechat: &Weechat) -> Config { |
| |
8 | let config = weechat |
| |
9 | .config_new(PLUGIN_NAME, || {}) |
| |
10 | .expect("Can't create new config"); |
| |
11 | |
| |
12 | Config(config) |
| |
13 | } |
| |
14 | } |
src/lib.rs
+12 −5
| @@ -1,4 +1,5 @@ |
| 1 | mod commands; |
1 | mod commands; |
| |
2 | mod config; |
| 2 | mod executor; |
3 | mod executor; |
| 3 | mod room_buffer; |
4 | mod room_buffer; |
| 4 | mod server; |
5 | mod server; |
| @@ -11,6 +12,7 @@ use weechat::{ |
| 11 | }; |
12 | }; |
| 12 | |
13 | |
| 13 | use crate::commands::Commands; |
14 | use crate::commands::Commands; |
| |
15 | use crate::config::Config; |
| 14 | use crate::executor::{cleanup_executor, spawn_weechat}; |
16 | use crate::executor::{cleanup_executor, spawn_weechat}; |
| 15 | use crate::server::MatrixServer; |
17 | use crate::server::MatrixServer; |
| 16 | |
18 | |
| @@ -19,6 +21,7 @@ const PLUGIN_NAME: &str = "matrix"; |
| 19 | struct Matrix { |
21 | struct Matrix { |
| 20 | servers: HashMap<String, MatrixServer>, |
22 | servers: HashMap<String, MatrixServer>, |
| 21 | commands: Commands, |
23 | commands: Commands, |
| |
24 | config: Config, |
| 22 | } |
25 | } |
| 23 | |
26 | |
| 24 | impl Matrix { |
27 | impl Matrix { |
| @@ -31,11 +34,12 @@ impl Matrix { |
| 31 | |
34 | |
| 32 | impl WeechatPlugin for Matrix { |
35 | impl WeechatPlugin for Matrix { |
| 33 | fn init(weechat: &Weechat, _args: ArgsWeechat) -> WeechatResult<Self> { |
36 | fn init(weechat: &Weechat, _args: ArgsWeechat) -> WeechatResult<Self> { |
| 34 | let server_name = "localhost"; |
37 | let commands = Commands::hook_all(weechat); |
| |
38 | let config = Config::new(weechat); |
| 35 | |
39 | |
| 36 | let mut server = MatrixServer::new(server_name); |
40 | let server_name = "localhost"; |
| |
41 | let server = MatrixServer::new(server_name, &config); |
| 37 | let mut servers = HashMap::new(); |
42 | let mut servers = HashMap::new(); |
| 38 | |
| |
| 39 | servers.insert(server_name.to_owned(), server); |
43 | servers.insert(server_name.to_owned(), server); |
| 40 | |
44 | |
| 41 | spawn_weechat(async move { |
45 | spawn_weechat(async move { |
| @@ -43,9 +47,12 @@ impl WeechatPlugin for Matrix { |
| 43 | let matrix = plugin(); |
47 | let matrix = plugin(); |
| 44 | matrix.autoconnect(); |
48 | matrix.autoconnect(); |
| 45 | }); |
49 | }); |
| 46 | let commands = Commands::hook_all(weechat); |
| |
| 47 | |
50 | |
| 48 | Ok(Matrix { servers, commands }) |
51 | Ok(Matrix { |
| |
52 | servers, |
| |
53 | commands, |
| |
54 | config, |
| |
55 | }) |
| 49 | } |
56 | } |
| 50 | } |
57 | } |
| 51 | |
58 | |
src/server.rs
+2 −1
| @@ -22,6 +22,7 @@ use weechat::Weechat; |
| 22 | use crate::executor::spawn_weechat; |
22 | use crate::executor::spawn_weechat; |
| 23 | use crate::plugin; |
23 | use crate::plugin; |
| 24 | use crate::room_buffer::RoomBuffer; |
24 | use crate::room_buffer::RoomBuffer; |
| |
25 | use crate::Config; |
| 25 | |
26 | |
| 26 | const DEFAULT_SYNC_TIMEOUT: i32 = 30000; |
27 | const DEFAULT_SYNC_TIMEOUT: i32 = 30000; |
| 27 | |
28 | |
| @@ -69,7 +70,7 @@ pub(crate) struct MatrixServer { |
| 69 | } |
70 | } |
| 70 | |
71 | |
| 71 | impl MatrixServer { |
72 | impl MatrixServer { |
| 72 | pub fn new(name: &str) -> Self { |
73 | pub fn new(name: &str, config: &Config) -> Self { |
| 73 | let homeserver = Url::parse("http://localhost:8008").unwrap(); |
74 | let homeserver = Url::parse("http://localhost:8008").unwrap(); |
| 74 | |
75 | |
| 75 | let config = AsyncClientConfig::new() |
76 | let config = AsyncClientConfig::new() |