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