discordrb 1.0.4 → 1.0.5
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/lib/discordrb/bot.rb +21 -3
- data/lib/discordrb/data.rb +23 -4
- data/lib/discordrb/endpoints/endpoints.rb +2 -0
- 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: 4553a299935a6bdc2eabefbfb3457eea8549b108
|
4
|
+
data.tar.gz: cecbbcba26ee274e071e36a6198c5ebf7a488ea4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f4693a18e7b29449038662944e6d91514dc5d7c127ba18f1d27e8a5de87666142bf831dea05cfac0b982bf7628e56e6461cc66b33ca490fb8b8b9ff4c5535ef
|
7
|
+
data.tar.gz: 37fd4cd938da34073f15a5c28bceadfdd05e2fa64f37abe42736fb5ee861a7b72c02375d97b8d17cd618da7c8407aba7a7126054741764bf73f58e0af10b0dc2
|
data/lib/discordrb/bot.rb
CHANGED
@@ -15,7 +15,9 @@ require 'discordrb/data'
|
|
15
15
|
module Discordrb
|
16
16
|
class Bot
|
17
17
|
include Discordrb::Events
|
18
|
-
def initialize(email, password)
|
18
|
+
def initialize(email, password, debug = false)
|
19
|
+
@debug = debug
|
20
|
+
|
19
21
|
@email = email
|
20
22
|
@password = password
|
21
23
|
|
@@ -25,8 +27,6 @@ module Discordrb
|
|
25
27
|
|
26
28
|
@channels = {}
|
27
29
|
@users = {}
|
28
|
-
|
29
|
-
@debug = false
|
30
30
|
end
|
31
31
|
|
32
32
|
def run
|
@@ -52,6 +52,15 @@ module Discordrb
|
|
52
52
|
@channels[id] = channel
|
53
53
|
end
|
54
54
|
|
55
|
+
def private_channel(id)
|
56
|
+
debug("Creating private channel with user id #{id}")
|
57
|
+
return @private_channels[id] if @private_channels[id]
|
58
|
+
|
59
|
+
response = RestClient.get Discordrb::Endpoints::USERS + "/#{id}/channels", {:Authorization => @token}
|
60
|
+
channel = Channel.new(JSON.parse(response), self)
|
61
|
+
@private_channels[id] = channel
|
62
|
+
end
|
63
|
+
|
55
64
|
def user(id)
|
56
65
|
@users[id]
|
57
66
|
end
|
@@ -114,6 +123,7 @@ module Discordrb
|
|
114
123
|
login_response_object = JSON.parse(login_response)
|
115
124
|
raise InvalidAuthenticationException unless login_response_object['token']
|
116
125
|
|
126
|
+
debug("Received token: #{login_response_object['token']}")
|
117
127
|
login_response_object['token']
|
118
128
|
end
|
119
129
|
|
@@ -162,6 +172,14 @@ module Discordrb
|
|
162
172
|
end
|
163
173
|
end
|
164
174
|
|
175
|
+
# Add private channels
|
176
|
+
@private_channels = {}
|
177
|
+
data['private_channels'].each do |element|
|
178
|
+
channel = Channel.new(element, self)
|
179
|
+
@channels[channel.id] = channel
|
180
|
+
@private_channels[channel.recipient.id] = channel
|
181
|
+
end
|
182
|
+
|
165
183
|
# Make sure to raise the event
|
166
184
|
raise_event(ReadyEvent.new)
|
167
185
|
when "MESSAGE_CREATE"
|
data/lib/discordrb/data.rb
CHANGED
@@ -17,18 +17,37 @@ module Discordrb
|
|
17
17
|
def mention
|
18
18
|
"<@#{@id}>"
|
19
19
|
end
|
20
|
+
|
21
|
+
# Utility function to send a PM
|
22
|
+
def pm(content = nil)
|
23
|
+
if content
|
24
|
+
# Recursively call pm to get the channel, then send a message to it
|
25
|
+
channel = pm
|
26
|
+
channel.send_message(content)
|
27
|
+
else
|
28
|
+
# If no message was specified, return the PM channel
|
29
|
+
@bot.private_channel(@id)
|
30
|
+
end
|
31
|
+
end
|
20
32
|
end
|
21
33
|
|
22
34
|
class Channel
|
23
|
-
attr_reader :name, :server, :type, :id, :is_private
|
35
|
+
attr_reader :name, :server, :type, :id, :is_private, :recipient
|
24
36
|
|
25
37
|
def initialize(data, bot)
|
26
38
|
@bot = bot
|
27
|
-
|
28
|
-
@server = bot.server(data['guild_id'].to_i)
|
29
|
-
@type = data['type']
|
39
|
+
|
30
40
|
@id = data['id']
|
41
|
+
@type = data['type'] || 'text'
|
42
|
+
|
31
43
|
@is_private = data['is_private']
|
44
|
+
if @is_private
|
45
|
+
@recipient = User.new(data['recipient'], bot)
|
46
|
+
@name = @recipient.username
|
47
|
+
else
|
48
|
+
@name = data['name']
|
49
|
+
@server = bot.server(data['guild_id'].to_i)
|
50
|
+
end
|
32
51
|
end
|
33
52
|
|
34
53
|
def send_message(content)
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- meew0
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faye-websocket
|