mij-discord 1.0.7 → 1.0.8
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.
- checksums.yaml +4 -4
- data/lib/mij-discord.rb +5 -10
- data/lib/mij-discord/bot.rb +32 -20
- data/lib/mij-discord/cache.rb +23 -8
- data/lib/mij-discord/core/api.rb +15 -4
- data/lib/mij-discord/core/api/channel.rb +0 -6
- data/lib/mij-discord/core/api/invite.rb +3 -2
- data/lib/mij-discord/core/api/webhook.rb +94 -0
- data/lib/mij-discord/data.rb +5 -1
- data/lib/mij-discord/data/application.rb +4 -0
- data/lib/mij-discord/data/channel.rb +34 -6
- data/lib/mij-discord/data/embed.rb +112 -0
- data/lib/mij-discord/data/emoji.rb +15 -2
- data/lib/mij-discord/data/invite.rb +20 -0
- data/lib/mij-discord/data/member.rb +10 -0
- data/lib/mij-discord/data/message.rb +25 -4
- data/lib/mij-discord/data/permissions.rb +16 -0
- data/lib/mij-discord/data/role.rb +5 -0
- data/lib/mij-discord/data/server.rb +22 -3
- data/lib/mij-discord/data/user.rb +43 -22
- data/lib/mij-discord/data/voice.rb +11 -0
- data/lib/mij-discord/data/webhook.rb +121 -0
- data/lib/mij-discord/errors.rb +44 -0
- data/lib/mij-discord/events.rb +4 -0
- data/lib/mij-discord/events/channel.rb +2 -0
- data/lib/mij-discord/extensions.rb +16 -0
- data/lib/mij-discord/logger.rb +9 -0
- data/lib/mij-discord/version.rb +1 -1
- metadata +6 -3
- data/lib/mij-discord/core/errors.rb +0 -106
data/lib/mij-discord/data.rb
CHANGED
@@ -31,7 +31,7 @@ module MijDiscord::Data
|
|
31
31
|
end
|
32
32
|
|
33
33
|
module PermissionObject
|
34
|
-
|
34
|
+
# TODO: Figure out what this was for
|
35
35
|
end
|
36
36
|
|
37
37
|
class ColorRGB
|
@@ -61,5 +61,9 @@ module MijDiscord::Data
|
|
61
61
|
def to_hex
|
62
62
|
'%06x' % @value
|
63
63
|
end
|
64
|
+
|
65
|
+
def inspect
|
66
|
+
%(#<ColorRGB ##{to_hex}>)
|
67
|
+
end
|
64
68
|
end
|
65
69
|
end
|
@@ -204,6 +204,10 @@ module MijDiscord::Data
|
|
204
204
|
MijDiscord::Core::API::Channel.delete(@bot.auth, @id, reason)
|
205
205
|
@server.cache.remove_channel(@id)
|
206
206
|
end
|
207
|
+
|
208
|
+
def inspect
|
209
|
+
MijDiscord.make_inspect(self, :id, :name, :type, :position)
|
210
|
+
end
|
207
211
|
end
|
208
212
|
|
209
213
|
class TextChannel < Channel
|
@@ -295,16 +299,19 @@ module MijDiscord::Data
|
|
295
299
|
alias_method :nsfw=, :set_nsfw
|
296
300
|
|
297
301
|
def send_message(text: '', embed: nil, tts: false)
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
+
embed = case embed
|
303
|
+
when nil then nil
|
304
|
+
when Hash
|
305
|
+
Embed.construct(embed)
|
306
|
+
when Embed then embed
|
307
|
+
else raise ArgumentError, 'Invalid embed'
|
308
|
+
end&.to_hash
|
309
|
+
|
310
|
+
response = MijDiscord::Core::API::Channel.create_message(@bot.auth, @id, text, tts, embed)
|
302
311
|
@cache.put_message(JSON.parse(response))
|
303
312
|
end
|
304
313
|
|
305
314
|
def send_file(file, caption: '', tts: false)
|
306
|
-
raise MijDiscord::Core::Errors::MessageTooLong if caption.length > 2000
|
307
|
-
|
308
315
|
response = MijDiscord::Core::API::Channel.upload_file(@bot.auth, @id, file, caption, tts)
|
309
316
|
@cache.put_message(JSON.parse(response))
|
310
317
|
end
|
@@ -348,6 +355,11 @@ module MijDiscord::Data
|
|
348
355
|
JSON.parse(response).map {|x| Invite.new(x, @bot) }
|
349
356
|
end
|
350
357
|
|
358
|
+
def webhooks
|
359
|
+
response = MijDiscord::Core::API::Channel.webhooks(@bot.auth, @id)
|
360
|
+
JSON.parse(response).map {|x| Webhook.new(x, @bot) }
|
361
|
+
end
|
362
|
+
|
351
363
|
def make_invite(reason = nil, max_age: 0, max_uses: 0, temporary: false, unique: false)
|
352
364
|
response = MijDiscord::Core::API::Channel.create_invite(@bot.auth, @id,
|
353
365
|
max_age, max_uses, temporary, unique, reason)
|
@@ -356,6 +368,14 @@ module MijDiscord::Data
|
|
356
368
|
|
357
369
|
alias_method :invite, :make_invite
|
358
370
|
|
371
|
+
def make_webhook(reason = nil, name:, avatar: :empty, format: :png)
|
372
|
+
avatar = User.process_avatar(avatar, format, true)
|
373
|
+
response = MijDiscord::Core::API::Channel.create_webhook(@bot.auth, @id, name, avatar, reason)
|
374
|
+
Webhook.new(JSON.parse(response), @bot)
|
375
|
+
end
|
376
|
+
|
377
|
+
alias_method :webhook, :make_webhook
|
378
|
+
|
359
379
|
def start_typing
|
360
380
|
MijDiscord::Core::API::Channel.start_typing(@bot.auth, @id)
|
361
381
|
nil
|
@@ -396,6 +416,10 @@ module MijDiscord::Data
|
|
396
416
|
MijDiscord::Core::API::Channel.leave_group(@bot.auth, @id)
|
397
417
|
nil
|
398
418
|
end
|
419
|
+
|
420
|
+
def inspect
|
421
|
+
MijDiscord.make_inspect(self, :id, :name, :type, :position, :topic, :nsfw)
|
422
|
+
end
|
399
423
|
end
|
400
424
|
|
401
425
|
class VoiceChannel < Channel
|
@@ -430,6 +454,10 @@ module MijDiscord::Data
|
|
430
454
|
alias_method :user_limit=, :set_user_limit
|
431
455
|
alias_method :set_limit, :set_user_limit
|
432
456
|
alias_method :limit=, :set_user_limit
|
457
|
+
|
458
|
+
def inspect
|
459
|
+
MijDiscord.make_inspect(self, :id, :name, :type, :position, :bitrate, :user_limit)
|
460
|
+
end
|
433
461
|
end
|
434
462
|
|
435
463
|
class ChannelCategory < Channel
|
@@ -46,6 +46,60 @@ module MijDiscord::Data
|
|
46
46
|
|
47
47
|
@fields = data['fields']&.map {|x| EmbedField.new(x) }
|
48
48
|
end
|
49
|
+
|
50
|
+
def inspect
|
51
|
+
MijDiscord.make_inspect(self,
|
52
|
+
:type, :title, :description, :url, :color, :timestamp, :image,
|
53
|
+
:video, :thumbnail, :footer, :author, :provider, :fields)
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_hash
|
57
|
+
self.class.construct({
|
58
|
+
type: @type,
|
59
|
+
title: @title,
|
60
|
+
description: @description,
|
61
|
+
url: @url,
|
62
|
+
|
63
|
+
color: @color,
|
64
|
+
timestamp: @timestamp,
|
65
|
+
|
66
|
+
footer: @footer,
|
67
|
+
thumbnail: @thumbnail,
|
68
|
+
|
69
|
+
image: @image,
|
70
|
+
video: @video,
|
71
|
+
|
72
|
+
author: @author,
|
73
|
+
provider: @provider,
|
74
|
+
|
75
|
+
fields: @fields,
|
76
|
+
})
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.construct(data)
|
80
|
+
embed = {
|
81
|
+
type: data.try_keys(:type, 'type') || :rich,
|
82
|
+
title: data.try_keys(:title, 'title'),
|
83
|
+
description: data.try_keys(:description, 'description'),
|
84
|
+
url: data.try_keys(:url, 'url'),
|
85
|
+
|
86
|
+
color: data.try_keys(:color, 'color')&.to_i,
|
87
|
+
timestamp: data.try_keys(:timestamp, 'timestamp')&.iso8601,
|
88
|
+
|
89
|
+
footer: data.try_keys(:footer, 'footer')&.to_hash,
|
90
|
+
thumbnail: data.try_keys(:thumbnail, 'thumbnail')&.to_hash,
|
91
|
+
|
92
|
+
image: data.try_keys(:image, 'image')&.to_hash,
|
93
|
+
video: data.try_keys(:video, 'video')&.to_hash,
|
94
|
+
|
95
|
+
author: data.try_keys(:author, 'author')&.to_hash,
|
96
|
+
provider: data.try_keys(:provider, 'provider')&.to_hash,
|
97
|
+
|
98
|
+
fields: data.try_keys(:fields, 'fields')&.map(&:to_hash),
|
99
|
+
}.delete_if {|_,v| v.nil? }
|
100
|
+
|
101
|
+
embed
|
102
|
+
end
|
49
103
|
end
|
50
104
|
|
51
105
|
class EmbedFooter
|
@@ -59,6 +113,17 @@ module MijDiscord::Data
|
|
59
113
|
@text, @icon_url = data['text'], data['icon_url']
|
60
114
|
@proxy_icon_url = data['proxy_icon_url']
|
61
115
|
end
|
116
|
+
|
117
|
+
def inspect
|
118
|
+
MijDiscord.make_inspect(self, :text, :icon_url)
|
119
|
+
end
|
120
|
+
|
121
|
+
def to_hash
|
122
|
+
{
|
123
|
+
text: @text,
|
124
|
+
icon_url: @icon_url,
|
125
|
+
}.delete_if {|_,v| v.nil? }
|
126
|
+
end
|
62
127
|
end
|
63
128
|
|
64
129
|
class EmbedMedia
|
@@ -74,6 +139,18 @@ module MijDiscord::Data
|
|
74
139
|
@url, @width, @height = data['url'], data['width'], data['height']
|
75
140
|
@proxy_url = data['proxy_url']
|
76
141
|
end
|
142
|
+
|
143
|
+
def inspect
|
144
|
+
MijDiscord.make_inspect(self, :url, :width, :height)
|
145
|
+
end
|
146
|
+
|
147
|
+
def to_hash
|
148
|
+
{
|
149
|
+
url: @url,
|
150
|
+
width: @width,
|
151
|
+
height: @height,
|
152
|
+
}.delete_if {|_,v| v.nil? }
|
153
|
+
end
|
77
154
|
end
|
78
155
|
|
79
156
|
class EmbedAuthor
|
@@ -89,6 +166,18 @@ module MijDiscord::Data
|
|
89
166
|
@name, @url, @icon_url = data['name'], data['url'], data['icon_url']
|
90
167
|
@proxy_icon_url = data['proxy_icon_url']
|
91
168
|
end
|
169
|
+
|
170
|
+
def inspect
|
171
|
+
MijDiscord.make_inspect(self, :name, :url, :icon_url)
|
172
|
+
end
|
173
|
+
|
174
|
+
def to_hash
|
175
|
+
{
|
176
|
+
name: @name,
|
177
|
+
url: @url,
|
178
|
+
icon_url: @icon_url,
|
179
|
+
}.delete_if {|_,v| v.nil? }
|
180
|
+
end
|
92
181
|
end
|
93
182
|
|
94
183
|
class EmbedProvider
|
@@ -99,6 +188,17 @@ module MijDiscord::Data
|
|
99
188
|
def initialize(data)
|
100
189
|
@name, @url = data['name'], data['url']
|
101
190
|
end
|
191
|
+
|
192
|
+
def inspect
|
193
|
+
MijDiscord.make_inspect(self, :name, :url)
|
194
|
+
end
|
195
|
+
|
196
|
+
def to_hash
|
197
|
+
{
|
198
|
+
name: @name,
|
199
|
+
url: @url,
|
200
|
+
}.delete_if {|_,v| v.nil? }
|
201
|
+
end
|
102
202
|
end
|
103
203
|
|
104
204
|
class EmbedField
|
@@ -111,5 +211,17 @@ module MijDiscord::Data
|
|
111
211
|
def initialize(data)
|
112
212
|
@name, @value, @inline = data['name'], data['value'], data['inline']
|
113
213
|
end
|
214
|
+
|
215
|
+
def inspect
|
216
|
+
MijDiscord.make_inspect(self, :name, :value, :inline)
|
217
|
+
end
|
218
|
+
|
219
|
+
def to_hash
|
220
|
+
{
|
221
|
+
name: @name,
|
222
|
+
value: @value,
|
223
|
+
inline: @inline,
|
224
|
+
}.delete_if {|_,v| v.nil? }
|
225
|
+
end
|
114
226
|
end
|
115
227
|
end
|
@@ -10,11 +10,14 @@ module MijDiscord::Data
|
|
10
10
|
|
11
11
|
attr_reader :roles
|
12
12
|
|
13
|
+
attr_reader :animated
|
14
|
+
|
13
15
|
def initialize(data, bot, server)
|
14
16
|
@bot, @server = bot, server
|
15
17
|
|
16
18
|
@id = data['id'].to_i
|
17
19
|
@name = data['name']
|
20
|
+
@animated = !!data['animated']
|
18
21
|
|
19
22
|
@roles = []
|
20
23
|
if @server && (roles = data['roles'])
|
@@ -23,7 +26,8 @@ module MijDiscord::Data
|
|
23
26
|
end
|
24
27
|
|
25
28
|
def mention
|
26
|
-
|
29
|
+
a = @animated ? 'a' : ''
|
30
|
+
"<#{a}:#{@name}:#{@id}>"
|
27
31
|
end
|
28
32
|
|
29
33
|
alias_method :to_s, :mention
|
@@ -32,9 +36,14 @@ module MijDiscord::Data
|
|
32
36
|
@id.zero? ? @name : "#{@name}:#{@id}"
|
33
37
|
end
|
34
38
|
|
35
|
-
def icon_url(format =
|
39
|
+
def icon_url(format = nil)
|
40
|
+
format = @animated ? :gif : :png if format.nil?
|
36
41
|
MijDiscord::Core::API.emoji_icon_url(@id, format)
|
37
42
|
end
|
43
|
+
|
44
|
+
def inspect
|
45
|
+
MijDiscord.make_inspect(self, :id, :name, :animated)
|
46
|
+
end
|
38
47
|
end
|
39
48
|
|
40
49
|
class Reaction
|
@@ -54,5 +63,9 @@ module MijDiscord::Data
|
|
54
63
|
@id = data['emoji']['id']&.to_i
|
55
64
|
@name = data['emoji']['name']
|
56
65
|
end
|
66
|
+
|
67
|
+
def inspect
|
68
|
+
MijDiscord.make_inspect(self, :id, :name, :count, :me)
|
69
|
+
end
|
57
70
|
end
|
58
71
|
end
|
@@ -15,6 +15,10 @@ module MijDiscord::Data
|
|
15
15
|
@name = data['name']
|
16
16
|
@type = data['type']
|
17
17
|
end
|
18
|
+
|
19
|
+
def inspect
|
20
|
+
MijDiscord.make_inspect(self, :id, :name, :type)
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
class InviteServer
|
@@ -31,6 +35,10 @@ module MijDiscord::Data
|
|
31
35
|
@name = data['name']
|
32
36
|
@splash_hash = data['splash_hash']
|
33
37
|
end
|
38
|
+
|
39
|
+
def inspect
|
40
|
+
MijDiscord.make_inspect(self, :id, :name)
|
41
|
+
end
|
34
42
|
end
|
35
43
|
|
36
44
|
class Invite
|
@@ -52,6 +60,10 @@ module MijDiscord::Data
|
|
52
60
|
attr_reader :revoked
|
53
61
|
alias_method :revoked?, :revoked
|
54
62
|
|
63
|
+
attr_reader :online_members
|
64
|
+
|
65
|
+
attr_reader :total_members
|
66
|
+
|
55
67
|
def initialize(data, bot)
|
56
68
|
@bot = bot
|
57
69
|
|
@@ -61,6 +73,9 @@ module MijDiscord::Data
|
|
61
73
|
@code, @max_uses = data['code'], data['uses']
|
62
74
|
@temporary, @revoked = data['temporary'], data['revoked']
|
63
75
|
|
76
|
+
@online_members = data['approximate_presence_count']
|
77
|
+
@total_members = data['approximate_member_count']
|
78
|
+
|
64
79
|
@inviter = data['inviter'] ? @bot.cache.put_user(data['inviter']) : nil
|
65
80
|
end
|
66
81
|
|
@@ -79,5 +94,10 @@ module MijDiscord::Data
|
|
79
94
|
def invite_url
|
80
95
|
"https://discord.gg/#{@code}"
|
81
96
|
end
|
97
|
+
|
98
|
+
def inspect
|
99
|
+
MijDiscord.make_inspect(self,
|
100
|
+
:code, :channel, :server, :max_uses, :temporary, :revoked, :inviter)
|
101
|
+
end
|
82
102
|
end
|
83
103
|
end
|
@@ -135,6 +135,11 @@ module MijDiscord::Data
|
|
135
135
|
nickname.empty? ? username : nickname
|
136
136
|
end
|
137
137
|
|
138
|
+
def inspect
|
139
|
+
MijDiscord.make_inspect(self,
|
140
|
+
:id, :username, :discriminator, :avatar_id, :bot_account, :joined_at, :nickname, :roles)
|
141
|
+
end
|
142
|
+
|
138
143
|
private
|
139
144
|
|
140
145
|
def voice_state_attribute(key)
|
@@ -162,5 +167,10 @@ module MijDiscord::Data
|
|
162
167
|
@voice_channel, @server, @roles = nil, nil, []
|
163
168
|
@nickname, @joined_at = '', @channel.creation_time
|
164
169
|
end
|
170
|
+
|
171
|
+
def inspect
|
172
|
+
MijDiscord.make_inspect(self,
|
173
|
+
:id, :username, :discriminator, :avatar_id, :bot_account, :joined_at)
|
174
|
+
end
|
165
175
|
end
|
166
176
|
end
|
@@ -35,7 +35,7 @@ module MijDiscord::Data
|
|
35
35
|
attr_reader :tts
|
36
36
|
alias_method :tts?, :tts
|
37
37
|
|
38
|
-
|
38
|
+
attr_reader :nonce
|
39
39
|
|
40
40
|
attr_reader :edited
|
41
41
|
alias_method :edited?, :edited
|
@@ -48,10 +48,12 @@ module MijDiscord::Data
|
|
48
48
|
def initialize(data, bot)
|
49
49
|
@bot = bot
|
50
50
|
|
51
|
+
data = data.first if data.is_a?(Array)
|
52
|
+
|
51
53
|
@id = data['id'].to_i
|
52
54
|
@channel = @bot.channel(data['channel_id'])
|
53
55
|
|
54
|
-
|
56
|
+
@nonce = data['nonce']
|
55
57
|
@webhook_id = data['webhook_id']&.to_i
|
56
58
|
|
57
59
|
if (author = data['author'])
|
@@ -114,8 +116,17 @@ module MijDiscord::Data
|
|
114
116
|
end
|
115
117
|
|
116
118
|
def edit(text: '', embed: nil)
|
117
|
-
|
118
|
-
|
119
|
+
raise MijDiscord::Errors::MessageTooLong if text.length > 2000
|
120
|
+
|
121
|
+
embed = case embed
|
122
|
+
when nil then nil
|
123
|
+
when Hash
|
124
|
+
MijDiscord::Data::Embed.construct(embed)
|
125
|
+
when MijDiscord::Data::Embed then embed
|
126
|
+
else raise ArgumentError, 'Invalid embed'
|
127
|
+
end&.to_hash
|
128
|
+
|
129
|
+
response = MijDiscord::Core::API::Channel.edit_message(@bot.auth, @channel.id, @id, text, [], embed)
|
119
130
|
@channel.cache.put_message(JSON.parse(response), update: true)
|
120
131
|
end
|
121
132
|
|
@@ -170,6 +181,12 @@ module MijDiscord::Data
|
|
170
181
|
MijDiscord::Core::API::Channel.delete_message(@bot.auth, @channel.id, @id)
|
171
182
|
nil
|
172
183
|
end
|
184
|
+
|
185
|
+
def inspect
|
186
|
+
MijDiscord.make_inspect(self,
|
187
|
+
:id, :content, :author, :channel, :timestamp, :edited, :pinned, :edited_timestamp,
|
188
|
+
:user_mentions, :role_mentions, :attachments, :embeds, :tts, :webhook_id)
|
189
|
+
end
|
173
190
|
end
|
174
191
|
|
175
192
|
class Attachment
|
@@ -198,5 +215,9 @@ module MijDiscord::Data
|
|
198
215
|
def image?
|
199
216
|
!@width.nil? && !@height.nil?
|
200
217
|
end
|
218
|
+
|
219
|
+
def inspect
|
220
|
+
MijDiscord.make_inspect(self, :url, :filename, :size, :width, :height)
|
221
|
+
end
|
201
222
|
end
|
202
223
|
end
|