discordrb 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of discordrb might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/discordrb/bot.rb +21 -10
- data/lib/discordrb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 17194fcdf12b5f81b55a74f37cd276dcf9e13071
|
|
4
|
+
data.tar.gz: cb7bd42eb2b78807e44646c35b1717e6a89a3825
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aa692f6814a8440a5783f7c3881e9472b4094e7000c52a762fe0231becf8dad7a1c08b05cfb37aad4bda0f5c0371dad97bdfd88536ebf02e3c1288b0202b6e19
|
|
7
|
+
data.tar.gz: 86caf5985693e9cf07d64b385b5bab07286c0c06e2e50c16325115e55a5fb1fbb2d47ba7b2ca4effa1887f04825fc6b96b939625c674f5e43aa56f7fb991c864
|
data/lib/discordrb/bot.rb
CHANGED
|
@@ -42,8 +42,8 @@ module Discordrb
|
|
|
42
42
|
|
|
43
43
|
while true do
|
|
44
44
|
websocket_connect
|
|
45
|
-
|
|
46
|
-
sleep
|
|
45
|
+
debug("Disconnected! Attempting to reconnect in 5 seconds.")
|
|
46
|
+
sleep 5
|
|
47
47
|
@token = login
|
|
48
48
|
end
|
|
49
49
|
end
|
|
@@ -130,7 +130,7 @@ module Discordrb
|
|
|
130
130
|
private
|
|
131
131
|
|
|
132
132
|
def debug(message)
|
|
133
|
-
puts "[DEBUG] #{message}" if @debug
|
|
133
|
+
puts "[DEBUG @ #{Time.now.to_s}] #{message}" if @debug
|
|
134
134
|
end
|
|
135
135
|
|
|
136
136
|
def login
|
|
@@ -149,26 +149,34 @@ module Discordrb
|
|
|
149
149
|
login_response_object['token']
|
|
150
150
|
rescue Exception => e
|
|
151
151
|
response_code = login_response.nil? ? 0 : login_response.code ######## mackmm145
|
|
152
|
-
if login_attempts < 100 && (
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
if login_attempts < 100 && (e.inspect.include?("No such host is known.") || response_code == 523)
|
|
153
|
+
debug("Login failed! Reattempting in 5 seconds. #{100 - login_attempts} attempts remaining.")
|
|
154
|
+
debug("Error was: #{e.inspect}")
|
|
155
|
+
sleep 5
|
|
156
|
+
login_attempts += 1
|
|
156
157
|
retry
|
|
157
158
|
else
|
|
159
|
+
debug("Login failed permanently after #{login_attempts + 1} attempts")
|
|
160
|
+
|
|
161
|
+
# Apparently we get a 400 if the password or username is incorrect. In that case, tell the user
|
|
162
|
+
debug("Are you sure you're using the correct username and password?") if e.class == RestClient::BadRequest
|
|
158
163
|
raise $!
|
|
159
164
|
end
|
|
160
165
|
end
|
|
161
166
|
|
|
162
167
|
def get_gateway
|
|
163
|
-
|
|
164
|
-
response
|
|
168
|
+
# Get updated websocket_hub
|
|
169
|
+
response = RestClient.get Discordrb::Endpoints::GATEWAY, :authorization => @token
|
|
170
|
+
JSON.parse(response)["url"]
|
|
165
171
|
end
|
|
166
172
|
|
|
167
173
|
def websocket_connect
|
|
174
|
+
debug("Attempting to get gateway URL...")
|
|
168
175
|
websocket_hub = get_gateway
|
|
176
|
+
debug("Success! Gateway URL is #{websocket_hub}.")
|
|
177
|
+
debug("Now running bot")
|
|
169
178
|
|
|
170
179
|
EM.run {
|
|
171
|
-
#@ws = Faye::WebSocket::Client.new(Discordrb::Endpoints::WEBSOCKET_HUB)
|
|
172
180
|
@ws = Faye::WebSocket::Client.new(websocket_hub)
|
|
173
181
|
|
|
174
182
|
@ws.on :open do |event|; websocket_open(event); end
|
|
@@ -238,6 +246,9 @@ module Discordrb
|
|
|
238
246
|
end
|
|
239
247
|
|
|
240
248
|
def websocket_close(event)
|
|
249
|
+
debug("Disconnected from WebSocket!")
|
|
250
|
+
debug(" (Reason: #{event.reason})")
|
|
251
|
+
debug(" (Code: #{event.code})")
|
|
241
252
|
raise_event(DisconnectEvent.new)
|
|
242
253
|
EM.stop
|
|
243
254
|
end
|
data/lib/discordrb/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: discordrb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- meew0
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-10-
|
|
11
|
+
date: 2015-10-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faye-websocket
|