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:
1313 language: system
1414 types: [file, rust]
1515 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 @@
1use crate::PLUGIN_NAME;
2use weechat::Weechat;
3
4pub struct Config(weechat::Config);
5
6impl 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 @@
11mod commands;
2mod config;
23mod executor;
34mod room_buffer;
45mod server;
@@ -11,6 +12,7 @@ use weechat::{
1112};
1213
1314use crate::commands::Commands;
15use crate::config::Config;
1416use crate::executor::{cleanup_executor, spawn_weechat};
1517use crate::server::MatrixServer;
1618
@@ -19,6 +21,7 @@ const PLUGIN_NAME: &str = "matrix";
1921struct Matrix {
2022 servers: HashMap<String, MatrixServer>,
2123 commands: Commands,
24 config: Config,
2225}
2326
2427impl Matrix {
@@ -31,11 +34,12 @@ impl Matrix {
3134
3235impl WeechatPlugin for Matrix {
3336 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);
3539
36 let mut server = MatrixServer::new(server_name);
40 let server_name = "localhost";
41 let server = MatrixServer::new(server_name, &config);
3742 let mut servers = HashMap::new();
38
3943 servers.insert(server_name.to_owned(), server);
4044
4145 spawn_weechat(async move {
@@ -43,9 +47,12 @@ impl WeechatPlugin for Matrix {
4347 let matrix = plugin();
4448 matrix.autoconnect();
4549 });
46 let commands = Commands::hook_all(weechat);
4750
48 Ok(Matrix { servers, commands })
51 Ok(Matrix {
52 servers,
53 commands,
54 config,
55 })
4956 }
5057}
5158
src/server.rs +2 −1
@@ -22,6 +22,7 @@ use weechat::Weechat;
2222use crate::executor::spawn_weechat;
2323use crate::plugin;
2424use crate::room_buffer::RoomBuffer;
25use crate::Config;
2526
2627const DEFAULT_SYNC_TIMEOUT: i32 = 30000;
2728
@@ -69,7 +70,7 @@ pub(crate) struct MatrixServer {
6970}
7071
7172impl MatrixServer {
72 pub fn new(name: &str) -> Self {
73 pub fn new(name: &str, config: &Config) -> Self {
7374 let homeserver = Url::parse("http://localhost:8008").unwrap();
7475
7576 let config = AsyncClientConfig::new()