| @@ -52,8 +52,6 @@ Use /matrix [command] help to find out more.\n", |
| 52 | } |
52 | } |
| 53 | |
53 | |
| 54 | fn add_server(args: &ArgMatches, servers: &Servers, config: &ConfigHandle) { |
54 | fn add_server(args: &ArgMatches, servers: &Servers, config: &ConfigHandle) { |
| 55 | let weechat = unsafe { Weechat::weechat() }; |
| |
| 56 | |
| |
| 57 | let server_name = args |
55 | let server_name = args |
| 58 | .value_of("name") |
56 | .value_of("name") |
| 59 | .expect("Server name not set but was required"); |
57 | .expect("Server name not set but was required"); |
| @@ -79,18 +77,16 @@ Use /matrix [command] help to find out more.\n", |
| 79 | .expect("Homeserver option wasn't created"); |
77 | .expect("Homeserver option wasn't created"); |
| 80 | homeserver_option.set(homeserver.as_str(), true); |
78 | homeserver_option.set(homeserver.as_str(), true); |
| 81 | |
79 | |
| 82 | weechat.print(&format!( |
80 | Weechat::print(&format!( |
| 83 | "{}: Server {}{}{} has been added.", |
81 | "{}: Server {}{}{} has been added.", |
| 84 | PLUGIN_NAME, |
82 | PLUGIN_NAME, |
| 85 | weechat.color("chat_server"), |
83 | Weechat::color("chat_server"), |
| 86 | server_name, |
84 | server_name, |
| 87 | weechat.color("reset") |
85 | Weechat::color("reset") |
| 88 | )); |
86 | )); |
| 89 | } |
87 | } |
| 90 | |
88 | |
| 91 | fn delete_server(args: &ArgMatches, servers: &Servers) { |
89 | fn delete_server(args: &ArgMatches, servers: &Servers) { |
| 92 | let weechat = unsafe { Weechat::weechat() }; |
| |
| 93 | |
| |
| 94 | let server_name = args |
90 | let server_name = args |
| 95 | .value_of("name") |
91 | .value_of("name") |
| 96 | .expect("Server name not set but was required"); |
92 | .expect("Server name not set but was required"); |
| @@ -103,24 +99,24 @@ Use /matrix [command] help to find out more.\n", |
| 103 | if let Some(s) = server { |
99 | if let Some(s) = server { |
| 104 | s.connected() |
100 | s.connected() |
| 105 | } else { |
101 | } else { |
| 106 | weechat.print(&format!( |
102 | Weechat::print(&format!( |
| 107 | "{}: No such server {}{}{} found.", |
103 | "{}: No such server {}{}{} found.", |
| 108 | PLUGIN_NAME, |
104 | PLUGIN_NAME, |
| 109 | weechat.color("chat_server"), |
105 | Weechat::color("chat_server"), |
| 110 | server_name, |
106 | server_name, |
| 111 | weechat.color("reset") |
107 | Weechat::color("reset") |
| 112 | )); |
108 | )); |
| 113 | return; |
109 | return; |
| 114 | } |
110 | } |
| 115 | }; |
111 | }; |
| 116 | |
112 | |
| 117 | if connected { |
113 | if connected { |
| 118 | weechat.print(&format!( |
114 | Weechat::print(&format!( |
| 119 | "{}: Server {}{}{} is still connected.", |
115 | "{}: Server {}{}{} is still connected.", |
| 120 | PLUGIN_NAME, |
116 | PLUGIN_NAME, |
| 121 | weechat.color("chat_server"), |
117 | Weechat::color("chat_server"), |
| 122 | server_name, |
118 | server_name, |
| 123 | weechat.color("reset") |
119 | Weechat::color("reset") |
| 124 | )); |
120 | )); |
| 125 | return; |
121 | return; |
| 126 | } |
122 | } |
| @@ -129,29 +125,27 @@ Use /matrix [command] help to find out more.\n", |
| 129 | |
125 | |
| 130 | drop(server); |
126 | drop(server); |
| 131 | |
127 | |
| 132 | weechat.print(&format!( |
128 | Weechat::print(&format!( |
| 133 | "{}: Server {}{}{} has been deleted.", |
129 | "{}: Server {}{}{} has been deleted.", |
| 134 | PLUGIN_NAME, |
130 | PLUGIN_NAME, |
| 135 | weechat.color("chat_server"), |
131 | Weechat::color("chat_server"), |
| 136 | server_name, |
132 | server_name, |
| 137 | weechat.color("reset") |
133 | Weechat::color("reset") |
| 138 | )); |
134 | )); |
| 139 | } |
135 | } |
| 140 | |
136 | |
| 141 | fn list_servers(servers: &Servers) { |
137 | fn list_servers(servers: &Servers) { |
| 142 | let weechat = unsafe { Weechat::weechat() }; |
| |
| 143 | |
| |
| 144 | if servers.borrow().is_empty() { |
138 | if servers.borrow().is_empty() { |
| 145 | return; |
139 | return; |
| 146 | } |
140 | } |
| 147 | |
141 | |
| 148 | weechat.print("\nAll Matrix servers:"); |
142 | Weechat::print("\nAll Matrix servers:"); |
| 149 | |
143 | |
| 150 | // TODO print out some stats if the server is connected. |
144 | // TODO print out some stats if the server is connected. |
| 151 | for server in servers.borrow().keys() { |
145 | for server in servers.borrow().keys() { |
| 152 | weechat.print(&format!( |
146 | Weechat::print(&format!( |
| 153 | " {}{}", |
147 | " {}{}", |
| 154 | weechat.color("chat_server"), |
148 | Weechat::color("chat_server"), |
| 155 | server |
149 | server |
| 156 | )); |
150 | )); |
| 157 | } |
151 | } |
| @@ -175,21 +169,17 @@ Use /matrix [command] help to find out more.\n", |
| 175 | } |
169 | } |
| 176 | |
170 | |
| 177 | fn server_not_found(server_name: &str) { |
171 | fn server_not_found(server_name: &str) { |
| 178 | let weechat = unsafe { Weechat::weechat() }; |
172 | Weechat::print(&format!( |
| 179 | |
| |
| 180 | weechat.print(&format!( |
| |
| 181 | "{}{}: Server \"{}{}{}\" not found.", |
173 | "{}{}: Server \"{}{}{}\" not found.", |
| 182 | weechat.prefix("error"), |
174 | Weechat::prefix("error"), |
| 183 | PLUGIN_NAME, |
175 | PLUGIN_NAME, |
| 184 | weechat.color("chat_server"), |
176 | Weechat::color("chat_server"), |
| 185 | server_name, |
177 | server_name, |
| 186 | weechat.color("reset") |
178 | Weechat::color("reset") |
| 187 | )); |
179 | )); |
| 188 | } |
180 | } |
| 189 | |
181 | |
| 190 | fn connect_command(args: &ArgMatches, servers: &Servers) { |
182 | fn connect_command(args: &ArgMatches, servers: &Servers) { |
| 191 | let weechat = unsafe { Weechat::weechat() }; |
| |
| 192 | |
| |
| 193 | let server_names = args |
183 | let server_names = args |
| 194 | .values_of("name") |
184 | .values_of("name") |
| 195 | .expect("Server names not set but were required"); |
185 | .expect("Server names not set but were required"); |
| @@ -201,7 +191,7 @@ Use /matrix [command] help to find out more.\n", |
| 201 | if let Some(s) = server { |
191 | if let Some(s) = server { |
| 202 | match s.connect() { |
192 | match s.connect() { |
| 203 | Ok(_) => (), |
193 | Ok(_) => (), |
| 204 | Err(e) => weechat.print(&format!("{:?}", e)), |
194 | Err(e) => Weechat::print(&format!("{:?}", e)), |
| 205 | } |
195 | } |
| 206 | } else { |
196 | } else { |
| 207 | Commands::server_not_found(server_name) |
197 | Commands::server_not_found(server_name) |
| @@ -230,7 +220,6 @@ Use /matrix [command] help to find out more.\n", |
| 230 | _buffer: Buffer, |
220 | _buffer: Buffer, |
| 231 | args: ArgsWeechat, |
221 | args: ArgsWeechat, |
| 232 | ) { |
222 | ) { |
| 233 | let weechat = unsafe { Weechat::weechat() }; |
| |
| 234 | let server_command = SubCommand::with_name("server") |
223 | let server_command = SubCommand::with_name("server") |
| 235 | .about("List, add or delete Matrix servers.") |
224 | .about("List, add or delete Matrix servers.") |
| 236 | .subcommand( |
225 | .subcommand( |
| @@ -288,7 +277,7 @@ Use /matrix [command] help to find out more.\n", |
| 288 | let matches = match argparse.get_matches_from_safe(args) { |
277 | let matches = match argparse.get_matches_from_safe(args) { |
| 289 | Ok(m) => m, |
278 | Ok(m) => m, |
| 290 | Err(e) => { |
279 | Err(e) => { |
| 291 | weechat.print(&e.to_string()); |
280 | Weechat::print(&e.to_string()); |
| 292 | return; |
281 | return; |
| 293 | } |
282 | } |
| 294 | }; |
283 | }; |