discordrb 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of discordrb might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +33 -7
- data/Rakefile +3 -0
- data/examples/pm.rb +11 -0
- data/lib/discordrb/bot.rb +47 -4
- data/lib/discordrb/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2296feb0a038652aa89be29c52175bc0f11eaf34
|
4
|
+
data.tar.gz: 6ddb6b25676a6c62c337a90cbd353f3f8657ef09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b15a87221c8c796400ddff8689c324a8fb554855b268fda56d45bfce7ac1513897647bc22bb939fd9fb140598a5d7739e3f74b35166263210c579d9c368b02da
|
7
|
+
data.tar.gz: 520abf9af895c57671e502f0294e7aa23baa4c5cdda02d410d4dc050055870f84d06677e9b93418b17ab4c30cb696ecb91d18eb6731d0fdec66fa1cf26e07587
|
data/README.md
CHANGED
@@ -1,23 +1,49 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/meew0/discordrb.svg?branch=master)](https://travis-ci.org/meew0/discordrb)
|
2
|
+
|
1
3
|
# discordrb
|
2
4
|
|
3
5
|
An implementation of the [Discord](https://discordapp.com/) API using Ruby.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
7
|
-
|
9
|
+
### Linux
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
On Linux, it should be as simple as running:
|
12
|
+
|
13
|
+
$ gem install discordrb
|
14
|
+
|
15
|
+
### Windows
|
16
|
+
|
17
|
+
On Windows, to install discordrb, run this in a shell:
|
18
|
+
|
19
|
+
$ gem install discordrb
|
20
|
+
|
21
|
+
Run the [ping example](https://github.com/meew0/discordrb/blob/master/examples/ping.rb) to verify that the installation works:
|
22
|
+
|
23
|
+
$ ruby ping.rb
|
24
|
+
|
25
|
+
#### Troubleshooting
|
12
26
|
|
13
|
-
|
27
|
+
**If you get an error like this when installing the gem**:
|
14
28
|
|
15
|
-
|
29
|
+
ERROR: Error installing discordrb:
|
30
|
+
The 'websocket-driver' native gem requires installed build tools.
|
16
31
|
|
17
|
-
|
32
|
+
You're missing the development kit required to build native extensions. Follow [these instructions](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit#installation-instructions) and reinstall discordrb:
|
18
33
|
|
34
|
+
$ gem uninstall discordrb
|
19
35
|
$ gem install discordrb
|
20
36
|
|
37
|
+
**If you get an error like this when running the example**:
|
38
|
+
|
39
|
+
terminate called after throwing an instance of 'std::runtime_error'
|
40
|
+
what(): Encryption not available on this event-machine
|
41
|
+
|
42
|
+
You're missing the OpenSSL libraries that EventMachine, a dependency of discordrb, needs to be built with to use encrypted connections (which Discord requires). Download the OpenSSL libraries from [here](http://slproweb.com/download/Win32OpenSSL-1_0_2d.exe), install them to their default location and reinstall EventMachine using these libraries:
|
43
|
+
|
44
|
+
$ gem uninstall eventmachine
|
45
|
+
$ gem install eventmachine -- --with-ssl-dir=C:/OpenSSL-Win32
|
46
|
+
|
21
47
|
## Usage
|
22
48
|
|
23
49
|
You can make a simple bot like this:
|
data/Rakefile
CHANGED
data/examples/pm.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# This bot shows off PM functionality by sending a PM every time the bot is mentioned.
|
2
|
+
|
3
|
+
require 'discordrb'
|
4
|
+
|
5
|
+
bot = Discordrb::Bot.new "email@example.com", "hunter2"
|
6
|
+
|
7
|
+
bot.mention do |event|
|
8
|
+
event.user.pm("You have mentioned me!")
|
9
|
+
end
|
10
|
+
|
11
|
+
bot.run
|
data/lib/discordrb/bot.rb
CHANGED
@@ -40,7 +40,12 @@ module Discordrb
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
while true do
|
44
|
+
@token = login
|
45
|
+
websocket_connect
|
46
|
+
puts "disconnected. attempting to reconnect."
|
47
|
+
sleep 5
|
48
|
+
end
|
44
49
|
end
|
45
50
|
|
46
51
|
def channel(id)
|
@@ -107,6 +112,18 @@ module Discordrb
|
|
107
112
|
register_event(MentionEvent, attributes, block)
|
108
113
|
end
|
109
114
|
|
115
|
+
def remove_handler(handler)
|
116
|
+
clazz = event_class(handler.class)
|
117
|
+
@event_handlers[clazz].delete(handler)
|
118
|
+
end
|
119
|
+
|
120
|
+
def add_handler(handler)
|
121
|
+
clazz = event_class(handler.class)
|
122
|
+
@event_handlers[clazz] << handler
|
123
|
+
end
|
124
|
+
|
125
|
+
alias_method :<<, :add_handler
|
126
|
+
|
110
127
|
private
|
111
128
|
|
112
129
|
def debug(message)
|
@@ -115,6 +132,8 @@ module Discordrb
|
|
115
132
|
|
116
133
|
def login
|
117
134
|
debug("Logging in")
|
135
|
+
login_attempts = login_attempts || 0
|
136
|
+
|
118
137
|
# Login
|
119
138
|
login_response = RestClient.post Discordrb::Endpoints::LOGIN, :email => @email, :password => @password
|
120
139
|
raise HTTPStatusException.new(login_response.code) if login_response.code >= 400
|
@@ -125,6 +144,15 @@ module Discordrb
|
|
125
144
|
|
126
145
|
debug("Received token: #{login_response_object['token']}")
|
127
146
|
login_response_object['token']
|
147
|
+
rescue SocketError => e
|
148
|
+
if login_attempts < 100 && e.inspect.include?("No such host is known.")
|
149
|
+
sleep 15
|
150
|
+
puts "login failed. reattempting."
|
151
|
+
login_attempts = login_attempts + 1
|
152
|
+
retry
|
153
|
+
else
|
154
|
+
raise $!
|
155
|
+
end
|
128
156
|
end
|
129
157
|
|
130
158
|
def websocket_connect
|
@@ -202,6 +230,7 @@ module Discordrb
|
|
202
230
|
|
203
231
|
def websocket_close(event)
|
204
232
|
raise_event(DisconnectEvent.new)
|
233
|
+
EM.stop
|
205
234
|
end
|
206
235
|
|
207
236
|
def websocket_open(event)
|
@@ -233,10 +262,13 @@ module Discordrb
|
|
233
262
|
end
|
234
263
|
|
235
264
|
def register_event(clazz, attributes, block)
|
236
|
-
|
237
|
-
|
265
|
+
handler = handler_class(clazz).new(attributes, block)
|
266
|
+
|
238
267
|
@event_handlers[clazz] ||= []
|
239
|
-
@event_handlers[clazz] << handler
|
268
|
+
@event_handlers[clazz] << handler
|
269
|
+
|
270
|
+
# Return the handler so it can be removed later
|
271
|
+
handler
|
240
272
|
end
|
241
273
|
|
242
274
|
def send_heartbeat
|
@@ -255,5 +287,16 @@ module Discordrb
|
|
255
287
|
mod.const_get(class_name)
|
256
288
|
end
|
257
289
|
end
|
290
|
+
|
291
|
+
def event_class(handler_class)
|
292
|
+
class_name = handler_class.to_s
|
293
|
+
return nil unless class_name.end_with? "Handler"
|
294
|
+
|
295
|
+
class_from_string(class_name[0..-8])
|
296
|
+
end
|
297
|
+
|
298
|
+
def handler_class(event_class)
|
299
|
+
class_from_string(event_class.to_s + "Handler")
|
300
|
+
end
|
258
301
|
end
|
259
302
|
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.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- meew0
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faye-websocket
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- bin/setup
|
84
84
|
- discordrb.gemspec
|
85
85
|
- examples/ping.rb
|
86
|
+
- examples/pm.rb
|
86
87
|
- lib/discordrb.rb
|
87
88
|
- lib/discordrb/bot.rb
|
88
89
|
- lib/discordrb/data.rb
|