mij-discord 1.0.9 → 1.0.10

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.
@@ -1,155 +1,143 @@
1
- # frozen_string_literal: true
2
-
3
- module MijDiscord::Core::API::User
4
- class << self
5
- # Get user data
6
- # https://discordapp.com/developers/docs/resources/user#get-user
7
- def resolve(auth, user_id)
8
- MijDiscord::Core::API.request(
9
- :users_uid,
10
- nil,
11
- :get,
12
- "#{MijDiscord::Core::API::APIBASE_URL}/users/#{user_id}",
13
- Authorization: auth
14
- )
15
- end
16
-
17
- # Get profile data (for userbots only)
18
- # Not officially documented, reverse engineered from tracking Discord's network activity
19
- def resolve2(auth, user_id)
20
- MijDiscord::Core::API.request(
21
- :users_uid,
22
- nil,
23
- :get,
24
- "#{MijDiscord::Core::API::APIBASE_URL}/users/#{user_id}/profile",
25
- Authorization: auth
26
- )
27
- end
28
-
29
- # Get current user data
30
- # https://discordapp.com/developers/docs/resources/user#get-current-user
31
- def profile(auth)
32
- MijDiscord::Core::API.request(
33
- :users_me,
34
- nil,
35
- :get,
36
- "#{MijDiscord::Core::API::APIBASE_URL}/users/@me",
37
- Authorization: auth
38
- )
39
- end
40
-
41
- # Change the current bot's nickname on a server
42
- def change_own_nickname(auth, server_id, nick, reason = nil)
43
- MijDiscord::Core::API.request(
44
- :guilds_sid_members_me_nick,
45
- server_id, # This is technically a guild endpoint
46
- :patch,
47
- "#{MijDiscord::Core::API::APIBASE_URL}/guilds/#{server_id}/members/@me/nick",
48
- { nick: nick }.to_json,
49
- Authorization: auth,
50
- content_type: :json,
51
- 'X-Audit-Log-Reason': reason
52
- )
53
- end
54
-
55
- # Update user data
56
- # https://discordapp.com/developers/docs/resources/user#modify-current-user
57
- def update_profile(auth, username, avatar)
58
- MijDiscord::Core::API.request(
59
- :users_me,
60
- nil,
61
- :patch,
62
- "#{MijDiscord::Core::API::APIBASE_URL}/users/@me",
63
- { avatar: avatar, username: username }.delete_if {|_,v| v.nil? }.to_json,
64
- Authorization: auth,
65
- content_type: :json
66
- )
67
- end
68
-
69
- # Get the servers a user is connected to
70
- # https://discordapp.com/developers/docs/resources/user#get-current-user-guilds
71
- def servers(auth)
72
- MijDiscord::Core::API.request(
73
- :users_me_guilds,
74
- nil,
75
- :get,
76
- "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/guilds",
77
- Authorization: auth
78
- )
79
- end
80
-
81
- # Leave a server
82
- # https://discordapp.com/developers/docs/resources/user#leave-guild
83
- def leave_server(auth, server_id)
84
- MijDiscord::Core::API.request(
85
- :users_me_guilds_sid,
86
- nil,
87
- :delete,
88
- "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/guilds/#{server_id}",
89
- Authorization: auth
90
- )
91
- end
92
-
93
- # Get the DMs for the current user
94
- # https://discordapp.com/developers/docs/resources/user#get-user-dms
95
- def user_dms(auth)
96
- MijDiscord::Core::API.request(
97
- :users_me_channels,
98
- nil,
99
- :get,
100
- "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/channels",
101
- Authorization: auth
102
- )
103
- end
104
-
105
- # Create a DM to another user
106
- # https://discordapp.com/developers/docs/resources/user#create-dm
107
- def create_pm(auth, recipient_id)
108
- MijDiscord::Core::API.request(
109
- :users_me_channels,
110
- nil,
111
- :post,
112
- "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/channels",
113
- { recipient_id: recipient_id }.to_json,
114
- Authorization: auth,
115
- content_type: :json
116
- )
117
- end
118
-
119
- # Get information about a user's connections
120
- # https://discordapp.com/developers/docs/resources/user#get-users-connections
121
- def connections(auth)
122
- MijDiscord::Core::API.request(
123
- :users_me_connections,
124
- nil,
125
- :get,
126
- "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/connections",
127
- Authorization: auth
128
- )
129
- end
130
-
131
- # Change user status setting
132
- def change_status_setting(auth, status)
133
- MijDiscord::Core::API.request(
134
- :users_me_settings,
135
- nil,
136
- :patch,
137
- "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/settings",
138
- { status: status }.to_json,
139
- Authorization: auth,
140
- content_type: :json
141
- )
142
- end
143
-
144
- # Returns one of the "default" discord avatars from the CDN given a discriminator
145
- def default_avatar(discrim = 0)
146
- "#{MijDiscord::Core::API::CDN_URL}/embed/avatars/#{discrim.to_i % 5}.png"
147
- end
148
-
149
- # Make an avatar URL from the user and avatar IDs
150
- def avatar_url(user_id, avatar_id, format = nil)
151
- format ||= avatar_id.start_with?('a_') ? :gif : :webp
152
- "#{MijDiscord::Core::API::CDN_URL}/avatars/#{user_id}/#{avatar_id}.#{format}"
153
- end
154
- end
1
+ # frozen_string_literal: true
2
+
3
+ module MijDiscord::Core::API::User
4
+ class << self
5
+ # Get user data
6
+ # https://discordapp.com/developers/docs/resources/user#get-user
7
+ def resolve(auth, user_id)
8
+ MijDiscord::Core::API.request(
9
+ :users_uid,
10
+ nil,
11
+ :get,
12
+ "#{MijDiscord::Core::API::APIBASE_URL}/users/#{user_id}",
13
+ Authorization: auth
14
+ )
15
+ end
16
+
17
+ # Get current user data
18
+ # https://discordapp.com/developers/docs/resources/user#get-current-user
19
+ def profile(auth)
20
+ MijDiscord::Core::API.request(
21
+ :users_me,
22
+ nil,
23
+ :get,
24
+ "#{MijDiscord::Core::API::APIBASE_URL}/users/@me",
25
+ Authorization: auth
26
+ )
27
+ end
28
+
29
+ # Change the current bot's nickname on a server
30
+ def change_own_nickname(auth, server_id, nick, reason = nil)
31
+ MijDiscord::Core::API.request(
32
+ :guilds_sid_members_me_nick,
33
+ server_id, # This is technically a guild endpoint
34
+ :patch,
35
+ "#{MijDiscord::Core::API::APIBASE_URL}/guilds/#{server_id}/members/@me/nick",
36
+ { nick: nick }.to_json,
37
+ Authorization: auth,
38
+ content_type: :json,
39
+ 'X-Audit-Log-Reason': reason
40
+ )
41
+ end
42
+
43
+ # Update user data
44
+ # https://discordapp.com/developers/docs/resources/user#modify-current-user
45
+ def update_profile(auth, username, avatar)
46
+ MijDiscord::Core::API.request(
47
+ :users_me,
48
+ nil,
49
+ :patch,
50
+ "#{MijDiscord::Core::API::APIBASE_URL}/users/@me",
51
+ { avatar: avatar, username: username }.delete_if {|_,v| v.nil? }.to_json,
52
+ Authorization: auth,
53
+ content_type: :json
54
+ )
55
+ end
56
+
57
+ # Get the servers a user is connected to
58
+ # https://discordapp.com/developers/docs/resources/user#get-current-user-guilds
59
+ def servers(auth)
60
+ MijDiscord::Core::API.request(
61
+ :users_me_guilds,
62
+ nil,
63
+ :get,
64
+ "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/guilds",
65
+ Authorization: auth
66
+ )
67
+ end
68
+
69
+ # Leave a server
70
+ # https://discordapp.com/developers/docs/resources/user#leave-guild
71
+ def leave_server(auth, server_id)
72
+ MijDiscord::Core::API.request(
73
+ :users_me_guilds_sid,
74
+ nil,
75
+ :delete,
76
+ "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/guilds/#{server_id}",
77
+ Authorization: auth
78
+ )
79
+ end
80
+
81
+ # Get the DMs for the current user
82
+ # https://discordapp.com/developers/docs/resources/user#get-user-dms
83
+ def user_dms(auth)
84
+ MijDiscord::Core::API.request(
85
+ :users_me_channels,
86
+ nil,
87
+ :get,
88
+ "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/channels",
89
+ Authorization: auth
90
+ )
91
+ end
92
+
93
+ # Create a DM to another user
94
+ # https://discordapp.com/developers/docs/resources/user#create-dm
95
+ def create_pm(auth, recipient_id)
96
+ MijDiscord::Core::API.request(
97
+ :users_me_channels,
98
+ nil,
99
+ :post,
100
+ "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/channels",
101
+ { recipient_id: recipient_id }.to_json,
102
+ Authorization: auth,
103
+ content_type: :json
104
+ )
105
+ end
106
+
107
+ # Get information about a user's connections
108
+ # https://discordapp.com/developers/docs/resources/user#get-users-connections
109
+ def connections(auth)
110
+ MijDiscord::Core::API.request(
111
+ :users_me_connections,
112
+ nil,
113
+ :get,
114
+ "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/connections",
115
+ Authorization: auth
116
+ )
117
+ end
118
+
119
+ # Change user status setting
120
+ def change_status_setting(auth, status)
121
+ MijDiscord::Core::API.request(
122
+ :users_me_settings,
123
+ nil,
124
+ :patch,
125
+ "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/settings",
126
+ { status: status }.to_json,
127
+ Authorization: auth,
128
+ content_type: :json
129
+ )
130
+ end
131
+
132
+ # Returns one of the "default" discord avatars from the CDN given a discriminator
133
+ def default_avatar(discrim = 0)
134
+ "#{MijDiscord::Core::API::CDN_URL}/embed/avatars/#{discrim.to_i % 5}.png"
135
+ end
136
+
137
+ # Make an avatar URL from the user and avatar IDs
138
+ def avatar_url(user_id, avatar_id, format = nil)
139
+ format ||= avatar_id.start_with?('a_') ? :gif : :png
140
+ "#{MijDiscord::Core::API::CDN_URL}/avatars/#{user_id}/#{avatar_id}.#{format}"
141
+ end
142
+ end
155
143
  end
@@ -1,227 +1,227 @@
1
- # frozen_string_literal: true
2
-
3
- module MijDiscord::Data
4
- class Embed
5
- attr_reader :type
6
-
7
- attr_reader :title
8
-
9
- attr_reader :description
10
-
11
- attr_reader :url
12
-
13
- attr_reader :timestamp
14
-
15
- attr_reader :color
16
-
17
- attr_reader :footer
18
-
19
- attr_reader :thumbnail
20
-
21
- attr_reader :image
22
-
23
- attr_reader :video
24
-
25
- attr_reader :provider
26
-
27
- attr_reader :author
28
-
29
- attr_reader :fields
30
-
31
- def initialize(data)
32
- @type, @url = data['type'], data['url']
33
- @title, @description = data['title'], data['description']
34
-
35
- @color = ColorRGB.new(data['color']) if data['color']
36
- @timestamp = Time.parse(data['timestamp']).utc if data['timestamp']
37
-
38
- @footer = EmbedFooter.new(data['footer']) if data['footer']
39
- @thumbnail = EmbedMedia.new(data['thumbnail']) if data['thumbnail']
40
-
41
- @image = EmbedMedia.new(data['image']) if data['image']
42
- @video = EmbedMedia.new(data['video']) if data['video']
43
-
44
- @author = EmbedAuthor.new(data['author']) if data['author']
45
- @provider = EmbedProvider.new(data['provider']) if data['provider']
46
-
47
- @fields = data['fields']&.map {|x| EmbedField.new(x) }
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
103
- end
104
-
105
- class EmbedFooter
106
- attr_reader :text
107
-
108
- attr_reader :icon_url
109
-
110
- attr_reader :proxy_icon_url
111
-
112
- def initialize(data)
113
- @text, @icon_url = data['text'], data['icon_url']
114
- @proxy_icon_url = data['proxy_icon_url']
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
127
- end
128
-
129
- class EmbedMedia
130
- attr_reader :url
131
-
132
- attr_reader :proxy_url
133
-
134
- attr_reader :width
135
-
136
- attr_reader :height
137
-
138
- def initialize(data)
139
- @url, @width, @height = data['url'], data['width'], data['height']
140
- @proxy_url = data['proxy_url']
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
154
- end
155
-
156
- class EmbedAuthor
157
- attr_reader :name
158
-
159
- attr_reader :url
160
-
161
- attr_reader :icon_url
162
-
163
- attr_reader :proxy_icon_url
164
-
165
- def initialize(data)
166
- @name, @url, @icon_url = data['name'], data['url'], data['icon_url']
167
- @proxy_icon_url = data['proxy_icon_url']
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
181
- end
182
-
183
- class EmbedProvider
184
- attr_reader :name
185
-
186
- attr_reader :url
187
-
188
- def initialize(data)
189
- @name, @url = data['name'], data['url']
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
202
- end
203
-
204
- class EmbedField
205
- attr_reader :name
206
-
207
- attr_reader :value
208
-
209
- attr_reader :inline
210
-
211
- def initialize(data)
212
- @name, @value, @inline = data['name'], data['value'], data['inline']
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
226
- end
1
+ # frozen_string_literal: true
2
+
3
+ module MijDiscord::Data
4
+ class Embed
5
+ attr_reader :type
6
+
7
+ attr_reader :title
8
+
9
+ attr_reader :description
10
+
11
+ attr_reader :url
12
+
13
+ attr_reader :timestamp
14
+
15
+ attr_reader :color
16
+
17
+ attr_reader :footer
18
+
19
+ attr_reader :thumbnail
20
+
21
+ attr_reader :image
22
+
23
+ attr_reader :video
24
+
25
+ attr_reader :provider
26
+
27
+ attr_reader :author
28
+
29
+ attr_reader :fields
30
+
31
+ def initialize(data)
32
+ @type, @url = data['type'], data['url']
33
+ @title, @description = data['title'], data['description']
34
+
35
+ @color = ColorRGB.new(data['color']) if data['color']
36
+ @timestamp = Time.parse(data['timestamp']).utc if data['timestamp']
37
+
38
+ @footer = EmbedFooter.new(data['footer']) if data['footer']
39
+ @thumbnail = EmbedMedia.new(data['thumbnail']) if data['thumbnail']
40
+
41
+ @image = EmbedMedia.new(data['image']) if data['image']
42
+ @video = EmbedMedia.new(data['video']) if data['video']
43
+
44
+ @author = EmbedAuthor.new(data['author']) if data['author']
45
+ @provider = EmbedProvider.new(data['provider']) if data['provider']
46
+
47
+ @fields = data['fields']&.map {|x| EmbedField.new(x) }
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
103
+ end
104
+
105
+ class EmbedFooter
106
+ attr_reader :text
107
+
108
+ attr_reader :icon_url
109
+
110
+ attr_reader :proxy_icon_url
111
+
112
+ def initialize(data)
113
+ @text, @icon_url = data['text'], data['icon_url']
114
+ @proxy_icon_url = data['proxy_icon_url']
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
127
+ end
128
+
129
+ class EmbedMedia
130
+ attr_reader :url
131
+
132
+ attr_reader :proxy_url
133
+
134
+ attr_reader :width
135
+
136
+ attr_reader :height
137
+
138
+ def initialize(data)
139
+ @url, @width, @height = data['url'], data['width'], data['height']
140
+ @proxy_url = data['proxy_url']
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
154
+ end
155
+
156
+ class EmbedAuthor
157
+ attr_reader :name
158
+
159
+ attr_reader :url
160
+
161
+ attr_reader :icon_url
162
+
163
+ attr_reader :proxy_icon_url
164
+
165
+ def initialize(data)
166
+ @name, @url, @icon_url = data['name'], data['url'], data['icon_url']
167
+ @proxy_icon_url = data['proxy_icon_url']
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
181
+ end
182
+
183
+ class EmbedProvider
184
+ attr_reader :name
185
+
186
+ attr_reader :url
187
+
188
+ def initialize(data)
189
+ @name, @url = data['name'], data['url']
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
202
+ end
203
+
204
+ class EmbedField
205
+ attr_reader :name
206
+
207
+ attr_reader :value
208
+
209
+ attr_reader :inline
210
+
211
+ def initialize(data)
212
+ @name, @value, @inline = data['name'], data['value'], data['inline']
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
226
+ end
227
227
  end