aboutsummaryrefslogtreecommitdiff
path: root/src/gateway
diff options
context:
space:
mode:
authorLakelezz <[email protected]>2017-10-23 21:10:47 +0200
committerZeyla Hellyer <[email protected]>2017-10-23 12:10:47 -0700
commite02d5fb8171b11214e1502c6754fef1972bbf1b9 (patch)
tree180de3f7201d36d2a81a8d85d9d4870d82efddc6 /src/gateway
parentUpdate dependencies (diff)
downloadserenity-e02d5fb8171b11214e1502c6754fef1972bbf1b9.tar.xz
serenity-e02d5fb8171b11214e1502c6754fef1972bbf1b9.zip
Properly update emojis, fix shard retries, fix cs
* If a guild's emojis are being altered, Serenity will straight up use the new `HashMap` instead of just extending. If `connect()` returns an `Err`, it will retry connecting. Cleaned up `help_command.rs`.
Diffstat (limited to 'src/gateway')
-rw-r--r--src/gateway/shard.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/gateway/shard.rs b/src/gateway/shard.rs
index 87940fd..3a8209d 100644
--- a/src/gateway/shard.rs
+++ b/src/gateway/shard.rs
@@ -5,6 +5,7 @@ use std::io::Write;
use std::net::Shutdown;
use std::sync::{Arc, Mutex};
use std::time::{Duration as StdDuration, Instant};
+use std::thread;
use super::{ConnectionStage, GatewayError};
use websocket::client::Url;
use websocket::message::{CloseData, OwnedMessage};
@@ -126,7 +127,7 @@ impl Shard {
token: Arc<Mutex<String>>,
shard_info: [u64; 2])
-> Result<Shard> {
- let client = connect(&*ws_url.lock().unwrap())?;
+ let client = connecting(&*ws_url.lock().unwrap());
let current_presence = (None, OnlineStatus::Online, false);
let heartbeat_instants = (None, None);
@@ -1047,3 +1048,18 @@ fn build_gateway_url(base: &str) -> Result<Url> {
Error::Gateway(GatewayError::BuildingUrl)
})
}
+
+/// Tries to connect and upon failure, retries.
+fn connecting(uri: &str) -> WsClient {
+ let waiting_time = 30;
+
+ loop {
+ match connect(&uri) {
+ Ok(client) => return client,
+ Err(why) => {
+ warn!("Connecting failed: {:?}\n Will retry in {} seconds.", why, waiting_time);
+ thread::sleep(StdDuration::from_secs(waiting_time));
+ },
+ };
+ }
+}