mij-discord 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +2 -0
- data/lib/mij-discord/bot.rb +2 -2
- data/lib/mij-discord/core/api/channel.rb +3 -2
- data/lib/mij-discord/core/gateway.rb +1 -1
- data/lib/mij-discord/data/channel.rb +46 -8
- data/lib/mij-discord/data/role.rb +4 -0
- data/lib/mij-discord/data/server.rb +15 -2
- data/lib/mij-discord/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: 48c0f016e36771e9039a514a7a7ffbd2395e0fd2
|
4
|
+
data.tar.gz: dbdc6fdff7a9aa2517ab6c52744d4c098e988309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 274edf535044862a7ce570f94495f1eee69b2e136e3807068e12c441b58a3174545e824eac4d91245bf2a16b48129fbeedff74fb08a181103866eabad3509243
|
7
|
+
data.tar.gz: dd4ece4b29888a70aee6e58c54dfe9e21a344f1894b78f072a478303f76a40488672a54da9e4fff4b515f5b8d098c92520457ea27fb68ac5cfc751a81cebb085
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
My Discord bot library that's partially based on Discordrb. Was made because I found Discordrb to be not satisfactory for my purposes.
|
4
4
|
|
5
|
+
TODO: Write goddamn documentation because there's currently none.
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
data/lib/mij-discord/bot.rb
CHANGED
@@ -187,7 +187,7 @@ module MijDiscord
|
|
187
187
|
end
|
188
188
|
|
189
189
|
def application
|
190
|
-
raise
|
190
|
+
raise 'Cannot get OAuth application for non-bot user' if @type != :bot
|
191
191
|
|
192
192
|
response = MijDiscord::Core::API.oauth_application(@token)
|
193
193
|
MijDiscord::Data::Application.new(JSON.parse(response), self)
|
@@ -563,7 +563,7 @@ module MijDiscord
|
|
563
563
|
private
|
564
564
|
|
565
565
|
def gateway_check
|
566
|
-
raise
|
566
|
+
raise 'A gateway connection is required for this action' unless connected?
|
567
567
|
end
|
568
568
|
|
569
569
|
def notify_ready
|
@@ -16,7 +16,7 @@ module MijDiscord::Core::API::Channel
|
|
16
16
|
|
17
17
|
# Update a channel's data
|
18
18
|
# https://discordapp.com/developers/docs/resources/channel#modify-channel
|
19
|
-
def update(token, channel_id, name, topic, nsfw, parent_id, position, bitrate, user_limit, reason = nil)
|
19
|
+
def update(token, channel_id, name, topic, nsfw, parent_id, position, bitrate, user_limit, overwrites, reason = nil)
|
20
20
|
MijDiscord::Core::API.request(
|
21
21
|
:channels_cid,
|
22
22
|
channel_id,
|
@@ -25,7 +25,8 @@ module MijDiscord::Core::API::Channel
|
|
25
25
|
{
|
26
26
|
name: name, topic: topic, nsfw: nsfw,
|
27
27
|
parent_id: parent_id, position: position,
|
28
|
-
bitrate: bitrate, user_limit: user_limit
|
28
|
+
bitrate: bitrate, user_limit: user_limit,
|
29
|
+
permission_overwrites: overwrites
|
29
30
|
}.delete_if {|_, v| v.nil? }.to_json,
|
30
31
|
Authorization: token,
|
31
32
|
content_type: :json,
|
@@ -414,7 +414,7 @@ module MijDiscord::Core
|
|
414
414
|
|
415
415
|
def ws_send(data, type)
|
416
416
|
unless @handshake_done && !@ws_closed
|
417
|
-
raise
|
417
|
+
raise 'Tried to send something to the websocket while not being connected!'
|
418
418
|
end
|
419
419
|
|
420
420
|
frame = WebSocket::Frame::Outgoing::Client.new(data: data, type: type, version: @handshake.version)
|
@@ -50,7 +50,7 @@ module MijDiscord::Data
|
|
50
50
|
when :category
|
51
51
|
ChannelCategory.new(data, bot, server)
|
52
52
|
else
|
53
|
-
raise
|
53
|
+
raise 'Broken channel object!'
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -114,6 +114,8 @@ module MijDiscord::Data
|
|
114
114
|
@parent_id ? @server.cache.get_channel(@parent_id) : nil
|
115
115
|
end
|
116
116
|
|
117
|
+
alias_method :category, :parent
|
118
|
+
|
117
119
|
def member_overwrites
|
118
120
|
@permission_overwrites.values.select {|v| v.type == :member }
|
119
121
|
end
|
@@ -123,30 +125,47 @@ module MijDiscord::Data
|
|
123
125
|
end
|
124
126
|
|
125
127
|
def set_name(name, reason = nil)
|
126
|
-
return if private?
|
127
|
-
|
128
128
|
set_options(reason, name: name)
|
129
|
+
nil
|
129
130
|
end
|
130
131
|
|
131
132
|
alias_method :name=, :set_name
|
132
133
|
|
133
134
|
def set_position(position, reason = nil)
|
134
135
|
set_options(reason, position: position)
|
136
|
+
nil
|
135
137
|
end
|
136
138
|
|
137
139
|
alias_method :position=, :set_position
|
138
140
|
|
139
141
|
def set_parent(parent, reason = nil)
|
140
|
-
|
142
|
+
channel = @server.cache.get_channel(parent)
|
143
|
+
raise ArgumentError, 'Specified channel is not a category' unless channel&.category?
|
144
|
+
|
145
|
+
set_options(reason, parent: channel)
|
146
|
+
nil
|
141
147
|
end
|
142
148
|
|
149
|
+
alias_method :parent=, :set_parent
|
150
|
+
alias_method :set_category, :set_parent
|
151
|
+
alias_method :category=, :set_parent
|
152
|
+
|
143
153
|
def set_options(reason = nil, name: nil, topic: nil, nsfw: nil,
|
144
|
-
parent: nil, position: nil, bitrate: nil, user_limit: nil)
|
154
|
+
parent: nil, position: nil, bitrate: nil, user_limit: nil, overwrites: nil)
|
145
155
|
response = MijDiscord::Core::API::Channel.update(@bot.token, @id,
|
146
|
-
name, topic, nsfw,parent&.to_id, position, bitrate, user_limit, reason)
|
156
|
+
name, topic, nsfw,parent&.to_id, position, bitrate, user_limit, overwrites, reason)
|
147
157
|
@server.cache.put_channel(JSON.parse(response), update: true)
|
148
158
|
end
|
149
159
|
|
160
|
+
def set_overwrites(overwrites, reason = nil)
|
161
|
+
set_options(reason, overwrites: overwrites)
|
162
|
+
nil
|
163
|
+
end
|
164
|
+
|
165
|
+
alias_method :overwrites=, :set_overwrites
|
166
|
+
alias_method :set_permission_overwrites, :set_overwrites
|
167
|
+
alias_method :permission_overwrites=, :set_overwrites
|
168
|
+
|
150
169
|
def define_overwrite(object, reason = nil, allow: 0, deny: 0)
|
151
170
|
unless object.is_a?(Overwrite)
|
152
171
|
allow_bits = allow.respond_to?(:bits) ? allow.bits : allow
|
@@ -160,6 +179,10 @@ module MijDiscord::Data
|
|
160
179
|
nil
|
161
180
|
end
|
162
181
|
|
182
|
+
alias_method :add_overwrite, :define_overwrite
|
183
|
+
alias_method :define_permission_overwrite, :define_overwrite
|
184
|
+
alias_method :add_permission_overwrite, :define_overwrite
|
185
|
+
|
163
186
|
def delete_overwrite(object, reason = nil)
|
164
187
|
raise ArgumentError, 'Invalid overwrite target' unless object.respond_to?(:to_id)
|
165
188
|
MijDiscord::Core::API::Channel.delete_permission(@bot.token, @id,
|
@@ -167,6 +190,16 @@ module MijDiscord::Data
|
|
167
190
|
nil
|
168
191
|
end
|
169
192
|
|
193
|
+
alias_method :delete_permission_overwrite, :delete_overwrite
|
194
|
+
|
195
|
+
def sync_overwrites(reason = nil)
|
196
|
+
raise 'Cannot sync overwrites on a channel with no category set' unless @parent_id
|
197
|
+
set_overwrites(parent.overwrites, reason)
|
198
|
+
nil
|
199
|
+
end
|
200
|
+
|
201
|
+
alias_method :sync_permission_overwrites, :sync_overwrites
|
202
|
+
|
170
203
|
def delete(reason = nil)
|
171
204
|
MijDiscord::Core::API::Channel.delete(@bot.token, @id, reason)
|
172
205
|
@server.cache.remove_channel(@id)
|
@@ -239,6 +272,7 @@ module MijDiscord::Data
|
|
239
272
|
return unless text?
|
240
273
|
|
241
274
|
set_options(reason, topic: topic)
|
275
|
+
nil
|
242
276
|
end
|
243
277
|
|
244
278
|
alias_method :topic=, :set_topic
|
@@ -247,6 +281,7 @@ module MijDiscord::Data
|
|
247
281
|
return unless text?
|
248
282
|
|
249
283
|
set_options(reason, nsfw: nsfw)
|
284
|
+
nil
|
250
285
|
end
|
251
286
|
|
252
287
|
alias_method :nsfw=, :set_nsfw
|
@@ -297,6 +332,7 @@ module MijDiscord::Data
|
|
297
332
|
|
298
333
|
MijDiscord::Core::API::Channel.bulk_delete_messages(@bot.token, @id, ids)
|
299
334
|
ids.each {|m| @cache.remove_message(m) }
|
335
|
+
nil
|
300
336
|
end
|
301
337
|
|
302
338
|
def invites
|
@@ -362,8 +398,6 @@ module MijDiscord::Data
|
|
362
398
|
|
363
399
|
def initialize(data, bot, server)
|
364
400
|
super(data, bot, server)
|
365
|
-
|
366
|
-
|
367
401
|
end
|
368
402
|
|
369
403
|
def update_data(data)
|
@@ -375,12 +409,14 @@ module MijDiscord::Data
|
|
375
409
|
|
376
410
|
def set_bitrate(rate, reason = nil)
|
377
411
|
set_options(reason, bitrate: rate)
|
412
|
+
nil
|
378
413
|
end
|
379
414
|
|
380
415
|
alias_method :bitrate=, :set_bitrate
|
381
416
|
|
382
417
|
def set_user_limit(limit, reason = nil)
|
383
418
|
set_options(reason, user_limit: limit)
|
419
|
+
nil
|
384
420
|
end
|
385
421
|
|
386
422
|
alias_method :user_limit=, :set_user_limit
|
@@ -400,5 +436,7 @@ module MijDiscord::Data
|
|
400
436
|
def channels
|
401
437
|
@server.channels.select! {|x| x.parent_id == @id }
|
402
438
|
end
|
439
|
+
|
440
|
+
alias_method :children, :channels
|
403
441
|
end
|
404
442
|
end
|
@@ -58,24 +58,28 @@ module MijDiscord::Data
|
|
58
58
|
|
59
59
|
def set_name(name)
|
60
60
|
set_options(name: name)
|
61
|
+
nil
|
61
62
|
end
|
62
63
|
|
63
64
|
alias_method :name=, :set_name
|
64
65
|
|
65
66
|
def set_hoist(flag)
|
66
67
|
set_options(hoist: flag)
|
68
|
+
nil
|
67
69
|
end
|
68
70
|
|
69
71
|
alias_method :hoist=, :set_hoist
|
70
72
|
|
71
73
|
def set_mentionable(flag)
|
72
74
|
set_options(mentionable: flag)
|
75
|
+
nil
|
73
76
|
end
|
74
77
|
|
75
78
|
alias_method :mentionable=, :set_mentionable
|
76
79
|
|
77
80
|
def set_color(color)
|
78
81
|
set_options(color: color)
|
82
|
+
nil
|
79
83
|
end
|
80
84
|
|
81
85
|
alias_method :color=, :set_color
|
@@ -21,6 +21,12 @@ module MijDiscord::Data
|
|
21
21
|
1 => :mentions,
|
22
22
|
}.freeze
|
23
23
|
|
24
|
+
CHANNEL_TYPES = {
|
25
|
+
:text => 0,
|
26
|
+
:voice => 2,
|
27
|
+
:category => 4,
|
28
|
+
}.freeze
|
29
|
+
|
24
30
|
include IDObject
|
25
31
|
|
26
32
|
attr_reader :bot
|
@@ -237,10 +243,12 @@ module MijDiscord::Data
|
|
237
243
|
channels.select!(&:voice?)
|
238
244
|
end
|
239
245
|
|
240
|
-
def create_channel(name, reason = nil,
|
246
|
+
def create_channel(name, reason = nil, type: :text, bitrate: nil, user_limit: nil, permissions: [], nsfw: false)
|
247
|
+
raise ArgumentError, 'Invalid channel type specified' unless CHANNEL_TYPES.has_key?(type)
|
248
|
+
|
241
249
|
permissions = permissions.map {|x| x.is_a(Overwrite) ? x.to_hash : x }
|
242
250
|
response = MijDiscord::Core::API::Server.create_channel(@bot.token, @id,
|
243
|
-
name,
|
251
|
+
name, CHANNEL_TYPES[type], bitrate, user_limit, permissions, nsfw, reason)
|
244
252
|
@cache.put_channel(JSON.parse(response))
|
245
253
|
end
|
246
254
|
|
@@ -294,6 +302,7 @@ module MijDiscord::Data
|
|
294
302
|
|
295
303
|
def set_name(name, reason = nil)
|
296
304
|
set_options(reason, name: name)
|
305
|
+
nil
|
297
306
|
end
|
298
307
|
|
299
308
|
alias_method :name=, :set_name
|
@@ -314,6 +323,7 @@ module MijDiscord::Data
|
|
314
323
|
raise ArgumentError, 'Invalid region' unless available_regions.find {|x| x.id == region }
|
315
324
|
|
316
325
|
set_options(reason, region: region)
|
326
|
+
nil
|
317
327
|
end
|
318
328
|
|
319
329
|
alias_method :region=, :set_region
|
@@ -326,18 +336,21 @@ module MijDiscord::Data
|
|
326
336
|
else
|
327
337
|
set_options(reason, icon: icon.to_s)
|
328
338
|
end
|
339
|
+
nil
|
329
340
|
end
|
330
341
|
|
331
342
|
alias_method :icon=, :set_icon
|
332
343
|
|
333
344
|
def set_afk_channel(channel, reason = nil)
|
334
345
|
set_options(reason, afk_channel: channel.to_id)
|
346
|
+
nil
|
335
347
|
end
|
336
348
|
|
337
349
|
alias_method :afk_channel=, :set_afk_channel
|
338
350
|
|
339
351
|
def set_afk_timeout(timeout, reason = nil)
|
340
352
|
set_options(reason, afk_timeout: timeout)
|
353
|
+
nil
|
341
354
|
end
|
342
355
|
|
343
356
|
alias_method :afk_timeout=, :set_afk_timeout
|
data/lib/mij-discord/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mij-discord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mijyuoon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|