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 @@
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 @@
1mod commands; 1mod commands;
2mod config;
2mod executor; 3mod executor;
3mod room_buffer; 4mod room_buffer;
4mod server; 5mod server;
@@ -11,6 +12,7 @@ use weechat::{
11}; 12};
12 13
13use crate::commands::Commands; 14use crate::commands::Commands;
15use crate::config::Config;
14use crate::executor::{cleanup_executor, spawn_weechat}; 16use crate::executor::{cleanup_executor, spawn_weechat};
15use crate::server::MatrixServer; 17use crate::server::MatrixServer;
16 18
@@ -19,6 +21,7 @@ const PLUGIN_NAME: &str = "matrix";
19struct Matrix { 21struct Matrix {
20 servers: HashMap<String, MatrixServer>, 22 servers: HashMap<String, MatrixServer>,
21 commands: Commands, 23 commands: Commands,
24 config: Config,
22} 25}
23 26
24impl Matrix { 27impl Matrix {
@@ -31,11 +34,12 @@ impl Matrix {
31 34
32impl WeechatPlugin for Matrix { 35impl 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;
22use crate::executor::spawn_weechat; 22use crate::executor::spawn_weechat;
23use crate::plugin; 23use crate::plugin;
24use crate::room_buffer::RoomBuffer; 24use crate::room_buffer::RoomBuffer;
25use crate::Config;
25 26
26const DEFAULT_SYNC_TIMEOUT: i32 = 30000; 27const DEFAULT_SYNC_TIMEOUT: i32 = 30000;
27 28
@@ -69,7 +70,7 @@ pub(crate) struct MatrixServer {
69} 70}
70 71
71impl MatrixServer { 72impl 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()