discordrb 1.4.6 → 1.4.7
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 +10 -10
- data/lib/discordrb/bot.rb +12 -1
- data/lib/discordrb/commands/command_bot.rb +2 -1
- data/lib/discordrb/data.rb +3 -1
- data/lib/discordrb/events/presence.rb +46 -1
- data/lib/discordrb/events/typing.rb +1 -1
- 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: 86cdc8d762e8e04b93959b865ed2edfdd828b5b4
|
4
|
+
data.tar.gz: 4c5a94198f98bea68dede91ad56eb5440cffa3b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8674eba850238067f0de5c1841475e225279cda28d6e587bdec1b8aecc1844550078df9279c3ab14c6598e010a22719973a48b8fc6534d4a5b3650384399cc3a
|
7
|
+
data.tar.gz: 2a715d046b1dc8af3113e0c3c3e6dd0177e4ad18d5162a63b112367bb32986eeeca8c8037e181f01c449bdf31fcb26d3efeaa7408b49eaf3c4f86c9c14942977
|
data/README.md
CHANGED
@@ -10,17 +10,17 @@ An implementation of the [Discord](https://discordapp.com/) API using Ruby.
|
|
10
10
|
|
11
11
|
On Linux, it should be as simple as running:
|
12
12
|
|
13
|
-
|
13
|
+
gem install discordrb
|
14
14
|
|
15
15
|
### Windows
|
16
16
|
|
17
17
|
On Windows, to install discordrb, run this in a shell:
|
18
18
|
|
19
|
-
|
19
|
+
gem install discordrb
|
20
20
|
|
21
21
|
Run the [ping example](https://github.com/meew0/discordrb/blob/master/examples/ping.rb) to verify that the installation works (make sure to replace the username and password in there with your own or your bots'!):
|
22
22
|
|
23
|
-
|
23
|
+
ruby ping.rb
|
24
24
|
|
25
25
|
#### Troubleshooting
|
26
26
|
|
@@ -31,23 +31,23 @@ Run the [ping example](https://github.com/meew0/discordrb/blob/master/examples/p
|
|
31
31
|
|
32
32
|
You're missing the development kit required to build native extensions. Download the development kit [here](http://rubyinstaller.org/downloads/) (scroll down to "Development Kit", then choose the one for Ruby 2.0 and your system architecture) and extract it somewhere. Open a command prompt in that folder and run:
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
ruby dk.rb init
|
35
|
+
ruby dk.rb install
|
36
36
|
|
37
37
|
Then reinstall discordrb:
|
38
38
|
|
39
|
-
|
40
|
-
|
39
|
+
gem uninstall discordrb
|
40
|
+
gem install discordrb
|
41
41
|
|
42
42
|
**If you get an error like this when running the example**:
|
43
43
|
|
44
44
|
terminate called after throwing an instance of 'std::runtime_error'
|
45
45
|
what(): Encryption not available on this event-machine
|
46
46
|
|
47
|
-
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](
|
47
|
+
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](https://slproweb.com/download/Win32OpenSSL-1_0_2e.exe), install them to their default location and reinstall EventMachine using these libraries:
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
gem uninstall eventmachine
|
50
|
+
gem install eventmachine -- --with-ssl-dir=C:/OpenSSL-Win32
|
51
51
|
|
52
52
|
## Usage
|
53
53
|
|
data/lib/discordrb/bot.rb
CHANGED
@@ -401,6 +401,10 @@ module Discordrb
|
|
401
401
|
register_event(PresenceEvent, attributes, block)
|
402
402
|
end
|
403
403
|
|
404
|
+
def playing(attributes = {}, &block)
|
405
|
+
register_event(PlayingEvent, attributes, block)
|
406
|
+
end
|
407
|
+
|
404
408
|
def mention(attributes = {}, &block)
|
405
409
|
register_event(MentionEvent, attributes, block)
|
406
410
|
end
|
@@ -860,9 +864,16 @@ module Discordrb
|
|
860
864
|
event = TypingEvent.new(data, self)
|
861
865
|
raise_event(event)
|
862
866
|
when 'PRESENCE_UPDATE'
|
867
|
+
now_playing = data['game']
|
868
|
+
played_before = user(data['user']['id'].to_i).game
|
863
869
|
update_presence(data)
|
864
870
|
|
865
|
-
|
871
|
+
if now_playing != played_before
|
872
|
+
event = PlayingEvent.new(data, self)
|
873
|
+
else
|
874
|
+
event = PresenceEvent.new(data, self)
|
875
|
+
end
|
876
|
+
|
866
877
|
raise_event(event)
|
867
878
|
when 'VOICE_STATE_UPDATE'
|
868
879
|
update_voice_state(data)
|
@@ -94,7 +94,8 @@ module Discordrb::Commands
|
|
94
94
|
end
|
95
95
|
if permission?(user(event.user.id), command.attributes[:permission_level], event.server)
|
96
96
|
event.command = command
|
97
|
-
command.call(event, arguments, chained)
|
97
|
+
result = command.call(event, arguments, chained)
|
98
|
+
result.to_s
|
98
99
|
else
|
99
100
|
event.respond "You don't have permission to execute command `#{name}`!"
|
100
101
|
return
|
data/lib/discordrb/data.rb
CHANGED
@@ -58,6 +58,7 @@ module Discordrb
|
|
58
58
|
|
59
59
|
# Set this user's roles
|
60
60
|
def update_roles(server, roles)
|
61
|
+
@roles ||= {}
|
61
62
|
@roles[server.id] = roles
|
62
63
|
end
|
63
64
|
|
@@ -416,11 +417,12 @@ module Discordrb
|
|
416
417
|
attr_reader :content, :author, :channel, :timestamp, :id, :mentions
|
417
418
|
alias_method :user, :author
|
418
419
|
alias_method :text, :content
|
420
|
+
alias_method :to_s, :content
|
419
421
|
|
420
422
|
def initialize(data, bot)
|
421
423
|
@bot = bot
|
422
424
|
@content = data['content']
|
423
|
-
@author =
|
425
|
+
@author = bot.user(data['author']['id'].to_i)
|
424
426
|
@channel = bot.channel(data['channel_id'].to_i)
|
425
427
|
@timestamp = Time.parse(data['timestamp'])
|
426
428
|
@id = data['id'].to_i
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'discordrb/events/generic'
|
2
2
|
require 'discordrb/data'
|
3
|
+
require 'discordrb/games'
|
3
4
|
|
4
5
|
module Discordrb::Events
|
5
|
-
# Event raised when a user's presence state updates (
|
6
|
+
# Event raised when a user's presence state updates (idle or online)
|
6
7
|
class PresenceEvent
|
7
8
|
attr_reader :server, :user, :status
|
8
9
|
|
@@ -39,4 +40,48 @@ module Discordrb::Events
|
|
39
40
|
].reduce(true, &:&)
|
40
41
|
end
|
41
42
|
end
|
43
|
+
|
44
|
+
# Event raised when a user starts or stops playing a game
|
45
|
+
class PlayingEvent
|
46
|
+
attr_reader :server, :user, :game
|
47
|
+
|
48
|
+
def initialize(data, bot)
|
49
|
+
@user = bot.user(data['user']['id'].to_i)
|
50
|
+
|
51
|
+
if data['game']
|
52
|
+
@game = Discordrb::Games.find_game(data['game']['name'])
|
53
|
+
else
|
54
|
+
@game = nil
|
55
|
+
end
|
56
|
+
|
57
|
+
@server = bot.server(data['guild_id'].to_i)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Event handler for PlayingEvent
|
62
|
+
class PlayingEventHandler < EventHandler
|
63
|
+
def matches?(event)
|
64
|
+
# Check for the proper event type
|
65
|
+
return false unless event.is_a? PlayingEvent
|
66
|
+
|
67
|
+
[
|
68
|
+
matches_all(@attributes[:from], event.user) do |a, e|
|
69
|
+
if a.is_a? String
|
70
|
+
a == e.name
|
71
|
+
elsif a.is_a? Fixnum
|
72
|
+
a == e.id
|
73
|
+
else
|
74
|
+
a == e
|
75
|
+
end
|
76
|
+
end,
|
77
|
+
matches_all(@attributes[:game], event.game) do |a, e|
|
78
|
+
if a.is_a? String
|
79
|
+
a == e.name
|
80
|
+
else
|
81
|
+
a == e
|
82
|
+
end
|
83
|
+
end
|
84
|
+
].reduce(true, &:&)
|
85
|
+
end
|
86
|
+
end
|
42
87
|
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.4.
|
4
|
+
version: 1.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- meew0
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faye-websocket
|