lib_discord 0.1.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0ae3f9c953b2390c8747f37d3d70fb8169a694a81469eba034a343badfffd1e7
4
+ data.tar.gz: a7f5b5cf92875e3911973f25b7a1bd1ddab7351c9c9f6aad2c2d5c0bbcdfa44d
5
+ SHA512:
6
+ metadata.gz: e7310c98cfbf7f99ef6cb655172295347ca32ff03840e9c6ad3f3310ad7f27640661047b398139cae38704d2fe57b71e6d779c8a1ba9f9e4e4e1e64667c70c28
7
+ data.tar.gz: c29182660904ea451dfd131b3118b5d65b587e1966469a52ff818209dcdf18bab49a9c9191a4eac8fcf83ac7d306601739378ae1d4d3ea6271fe0df1333de9e5
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry-container"
4
+ require "forwardable"
5
+ require "logger"
6
+
7
+ require "lib_discord/resources"
8
+ require "lib_discord/types"
9
+ require "lib_discord/urls"
10
+ require "lib_discord/version"
11
+
12
+ module LibDiscord
13
+ class Client
14
+ extend Forwardable
15
+
16
+ def initialize(auth_header:, base_url: nil, user_agent: nil, logger: nil)
17
+ auth_header = Types::Strict::String[auth_header]
18
+ base_url = Types::Strict::String[base_url || "https://discord.com/api/v10"]
19
+ user_agent = Types::Strict::String[user_agent || "LibDiscord (#{LibDiscord.project_url}, #{LibDiscord.version})"]
20
+
21
+ unless logger
22
+ logger = Logger.new($stdout)
23
+ logger.level = :info
24
+ end
25
+
26
+ @container = Dry::Container.new
27
+
28
+ @container.register("application") do
29
+ Application.new(auth_header, base_url, user_agent, logger)
30
+ end
31
+
32
+ @container.register("application.command") do
33
+ ApplicationCommand.new(auth_header, base_url, user_agent, logger)
34
+ end
35
+
36
+ @container.register("application.role_connection_metadata") do
37
+ ApplicationRoleConnectionMetadata.new(auth_header, base_url, user_agent, logger)
38
+ end
39
+
40
+ @container.register("audit_log") do
41
+ AuditLog.new(auth_header, base_url, user_agent, logger)
42
+ end
43
+
44
+ @container.register("auto_moderation") do
45
+ AutoModeration.new(auth_header, base_url, user_agent, logger)
46
+ end
47
+
48
+ @container.register("channel") do
49
+ Channel.new(auth_header, base_url, user_agent, logger)
50
+ end
51
+
52
+ @container.register("emoji") do
53
+ Emoji.new(auth_header, base_url, user_agent, logger)
54
+ end
55
+
56
+ @container.register("guild") do
57
+ Guild.new(auth_header, base_url, user_agent, logger)
58
+ end
59
+
60
+ @container.register("guild.scheduled_event") do
61
+ GuildScheduledEvent.new(auth_header, base_url, user_agent, logger)
62
+ end
63
+
64
+ @container.register("guild.template") do
65
+ GuildTemplate.new(auth_header, base_url, user_agent, logger)
66
+ end
67
+
68
+ @container.register("interaction") do
69
+ Interaction.new(auth_header, base_url, user_agent, logger)
70
+ end
71
+
72
+ @container.register("invite") do
73
+ Invite.new(auth_header, base_url, user_agent, logger)
74
+ end
75
+
76
+ @container.register("stage_instance") do
77
+ StageInstance.new(auth_header, base_url, user_agent, logger)
78
+ end
79
+
80
+ @container.register("sticker") do
81
+ Sticker.new(auth_header, base_url, user_agent, logger)
82
+ end
83
+
84
+ @container.register("user") do
85
+ User.new(auth_header, base_url, user_agent, logger)
86
+ end
87
+
88
+ @container.register("voice") do
89
+ Voice.new(auth_header, base_url, user_agent, logger)
90
+ end
91
+
92
+ @container.register("webhook") do
93
+ Webhook.new(auth_header, base_url, user_agent, logger)
94
+ end
95
+ end
96
+
97
+ def_delegators :@container, :[], :keys
98
+ end
99
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "http"
4
+
5
+ module LibDiscord
6
+ class TimeoutError < HTTP::TimeoutError; end
7
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "http"
4
+ require "logger"
5
+
6
+ require "lib_discord/errors"
7
+ require "lib_discord/response"
8
+ require "lib_discord/types"
9
+
10
+ module LibDiscord
11
+ class Resource
12
+ def initialize(auth_header, base_url, user_agent, logger)
13
+ @auth_header = Types::Strict::String[auth_header]
14
+ @base_url = Types::Strict::String[base_url]
15
+
16
+ @default_headers = {user_agent: Types::Strict::String[user_agent]}
17
+ @logger = logger
18
+ end
19
+
20
+ private
21
+
22
+ def clientjson = client(content_type: "application/json")
23
+
24
+ def client(**additional_headers)
25
+ headers = @default_headers.merge(
26
+ Types::Resource::ClientHeaders[additional_headers]
27
+ )
28
+ HTTP.use(logging: {logger: @logger}).auth(@auth_header).headers(**headers)
29
+ end
30
+
31
+ def request_url(path)
32
+ @base_url + Types::Strict::String[path]
33
+ end
34
+
35
+ def send_request(verb, relative_path, http_client: clientjson, **kwargs)
36
+ # TODO: account for any reasonable errors that HTTP may throw
37
+ discord_response = http_client.send(
38
+ Types::Strict::Symbol[verb],
39
+ request_url(relative_path),
40
+ **Types::Resource::HttpKwargs[kwargs]
41
+ )
42
+
43
+ resp = Response.new(
44
+ code: discord_response.code,
45
+ headers: discord_response.headers.to_h,
46
+ body_raw: discord_response.to_s
47
+ )
48
+
49
+ begin
50
+ resp.body_parsed = discord_response.parse
51
+ rescue HTTP::Error
52
+ # we'll get here if HTTP doesn't have a parser for the response's mime
53
+ # type. we simply want to try to parse it, and skip over it if it
54
+ # fails.
55
+
56
+ msg = "Could not parse HTTP response body with content-type #{resp.headers["Content-Type"]}."
57
+ @logger.add(Logger::DEBUG, msg, "lib_discord")
58
+ end
59
+
60
+ resp
61
+ rescue HTTP::TimeoutError => e
62
+ raise TimeoutError.new(e.message)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class Application < Resource
7
+ def get_current_application
8
+ send_request(:get, "/applications/@me")
9
+ end
10
+
11
+ def edit_current_application(json:)
12
+ send_request(:patch, "/applications/@me", json:)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class ApplicationCommand < Resource
7
+ def get_global_application_commands(application_id:, params: {})
8
+ send_request(:get, "/applications/#{application_id}/commands", params:)
9
+ end
10
+
11
+ def create_global_application_command(application_id:, json:)
12
+ send_request(:post, "/applications/#{application_id}/commands", json:)
13
+ end
14
+
15
+ def get_global_application_command(application_id:, command_id:)
16
+ send_request(:get, "/applications/#{application_id}/commands/#{command_id}")
17
+ end
18
+
19
+ def edit_global_application_command(application_id:, command_id:, json:)
20
+ send_request(:patch, "/applications/#{application_id}/commands/#{command_id}", json:)
21
+ end
22
+
23
+ def delete_global_application_command(application_id:, command_id:)
24
+ send_request(:delete, "/applications/#{application_id}/commands/#{command_id}")
25
+ end
26
+
27
+ def bulk_overwrite_global_application_commands(application_id:, json:)
28
+ send_request(:put, "/applications/#{application_id}/commands", json:)
29
+ end
30
+
31
+ def get_guild_application_commands(application_id:, guild_id:, params: {})
32
+ send_request(:get, "/applications/#{application_id}/guilds/#{guild_id}/commands", params:)
33
+ end
34
+
35
+ def create_guild_application_command(application_id:, guild_id:, json:)
36
+ send_request(:post, "/applications/#{application_id}/guilds/#{guild_id}/commands", json:)
37
+ end
38
+
39
+ def get_guild_application_command(application_id:, guild_id:, command_id:)
40
+ send_request(:get, "/applications/#{application_id}/guilds/#{guild_id}/commands/#{command_id}")
41
+ end
42
+
43
+ def edit_guild_application_command(application_id:, guild_id:, command_id:, json:)
44
+ send_request(:patch, "/applications/#{application_id}/guilds/#{guild_id}/commands/#{command_id}", json:)
45
+ end
46
+
47
+ def delete_guild_application_command(application_id:, guild_id:, command_id:)
48
+ send_request(:delete, "/applications/#{application_id}/guilds/#{guild_id}/commands/#{command_id}")
49
+ end
50
+
51
+ def bulk_overwrite_guild_application_commands(application_id:, guild_id:, json:)
52
+ send_request(:put, "/applications/#{application_id}/guilds/#{guild_id}/commands", json:)
53
+ end
54
+
55
+ def get_guild_application_command_permissions(application_id:, guild_id:)
56
+ send_request(:get, "/applications/#{application_id}/guilds/#{guild_id}/commands/permissions")
57
+ end
58
+
59
+ def get_application_command_permissions(application_id:, guild_id:, command_id:)
60
+ send_request(:get, "/applications/#{application_id}/guilds/#{guild_id}/commands/#{command_id}/permissions")
61
+ end
62
+
63
+ def edit_application_command_permissions(application_id:, guild_id:, command_id:, json:)
64
+ send_request(:put, "/applications/#{application_id}/guilds/#{guild_id}/commands/#{command_id}/permissions", json:)
65
+ end
66
+
67
+ def batch_edit_application_command_permissions(application_id:, guild_id:, json:)
68
+ send_request(:put, "/applications/#{application_id}/guilds/#{guild_id}/commands/permissions", json:)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class ApplicationRoleConnectionMetadata < Resource
7
+ def get_application_role_connection_metadata_records(application_id:)
8
+ send_request(:get, "/applications/#{application_id}/role-connections/metadata")
9
+ end
10
+
11
+ def update_application_role_connection_metadata_records(application_id:, json:)
12
+ send_request(:put, "/applications/#{application_id}/role-connections/metadata", json:)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class AuditLog < Resource
7
+ def get_guild_audit_log(guild_id:, params: {})
8
+ send_request(:get, "/guilds/#{guild_id}/audit-logs", params:)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class AutoModeration < Resource
7
+ def list_auto_moderation_rules_for_guild(guild_id:)
8
+ send_request(:get, "/guilds/#{guild_id}/auto-moderation/rules")
9
+ end
10
+
11
+ def get_auto_moderation_rule(guild_id:, auto_moderation_rule_id:)
12
+ send_request(:get, "/guilds/#{guild_id}/auto-moderation/rules/#{auto_moderation_rule_id}")
13
+ end
14
+
15
+ def create_auto_moderation_rule(guild_id:, json:)
16
+ send_request(:post, "/guilds/#{guild_id}/auto-moderation/rules", json:)
17
+ end
18
+
19
+ def modify_auto_moderation_rule(guild_id:, auto_moderation_rule_id:, json:)
20
+ send_request(:patch, "/guilds/#{guild_id}/auto-moderation/rules/#{auto_moderation_rule_id}", json:)
21
+ end
22
+
23
+ def delete_auto_moderation_rule(guild_id:, auto_moderation_rule_id:)
24
+ send_request(:delete, "/guilds/#{guild_id}/auto-moderation/rules/#{auto_moderation_rule_id}")
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,168 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class Channel < Resource
7
+ def get_channel(channel_id:)
8
+ send_request(:get, "/channels/#{channel_id}")
9
+ end
10
+
11
+ def modify_channel(channel_id:, json:)
12
+ send_request(:patch, "/channels/#{channel_id}", json:)
13
+ end
14
+
15
+ def delete_channel(channel_id:)
16
+ send_request(:delete, "/channels/#{channel_id}")
17
+ end
18
+
19
+ alias_method :close_channel, :delete_channel
20
+
21
+ def get_channel_messages(channel_id:, params: {})
22
+ send_request(:get, "/channels/#{channel_id}/messages", params:)
23
+ end
24
+
25
+ def get_channel_message(channel_id:, message_id:)
26
+ send_request(:get, "/channels/#{channel_id}/messages/#{message_id}")
27
+ end
28
+
29
+ def create_message(channel_id:, json:)
30
+ send_request(:post, "/channels/#{channel_id}/messages", json:)
31
+ end
32
+
33
+ def crosspost_message(channel_id:, message_id:)
34
+ send_request(:post, "/channels/#{channel_id}/messages/#{message_id}/crosspost")
35
+ end
36
+
37
+ def create_reaction(channel_id:, message_id:, emoji:)
38
+ send_request(:put, "/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me")
39
+ end
40
+
41
+ def delete_own_reaction(channel_id:, message_id:, emoji:)
42
+ send_request(:delete, "/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me")
43
+ end
44
+
45
+ def delete_user_reaction(channel_id:, message_id:, emoji:, user_id:)
46
+ send_request(:delete, "/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/#{user_id}")
47
+ end
48
+
49
+ def get_reactions(channel_id:, message_id:, emoji:, params: {})
50
+ send_request(:get, "/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}", params:)
51
+ end
52
+
53
+ def delete_all_reactions(channel_id:, message_id:)
54
+ send_request(:delete, "/channels/#{channel_id}/messages/#{message_id}/reactions")
55
+ end
56
+
57
+ def delete_all_reactions_for_emoji(channel_id:, message_id:, emoji:)
58
+ send_request(:delete, "/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}")
59
+ end
60
+
61
+ def edit_message(channel_id:, message_id:, json:)
62
+ send_request(:patch, "/channels/#{channel_id}/messages/#{message_id}", json:)
63
+ end
64
+
65
+ def delete_message(channel_id:, message_id:)
66
+ send_request(:delete, "/channels/#{channel_id}/messages/#{message_id}")
67
+ end
68
+
69
+ def bulk_delete_messages(channel_id:, json:)
70
+ send_request(:post, "/channels/#{channel_id}/messages/bulk-delete", json:)
71
+ end
72
+
73
+ def edit_channel_permissions(channel_id:, overwrite_id:, json:)
74
+ send_request(:put, "/channels/#{channel_id}/permissions/#{overwrite_id}", json:)
75
+ end
76
+
77
+ def get_channel_invites(channel_id:)
78
+ send_request(:get, "/channels/#{channel_id}/invites")
79
+ end
80
+
81
+ def create_channel_invite(channel_id:, json:)
82
+ send_request(:post, "/channels/#{channel_id}/invites", json:)
83
+ end
84
+
85
+ def delete_channel_permission(channel_id:, overwrite_id:)
86
+ send_request(:delete, "/channels/#{channel_id}/permissions/#{overwrite_id}")
87
+ end
88
+
89
+ def follow_announcement_channel(channel_id:, json:)
90
+ send_request(:post, "/channels/#{channel_id}/followers", json:)
91
+ end
92
+
93
+ def trigger_typing_indicator(channel_id:)
94
+ send_request(:post, "/channels/#{channel_id}/typing")
95
+ end
96
+
97
+ def get_pinned_messages(channel_id:)
98
+ send_request(:get, "/channels/#{channel_id}/pins")
99
+ end
100
+
101
+ def pin_message(channel_id:, message_id:)
102
+ send_request(:put, "/channels/#{channel_id}/pins/#{message_id}")
103
+ end
104
+
105
+ def unpin_message(channel_id:, message_id:)
106
+ send_request(:delete, "/channels/#{channel_id}/pins/#{message_id}")
107
+ end
108
+
109
+ def group_dm_add_recipient(channel_id:, user_id:, json:)
110
+ send_request(:put, "/channels/#{channel_id}/recipients/#{user_id}", json:)
111
+ end
112
+
113
+ def group_dm_remove_recipient(channel_id:, user_id:)
114
+ send_request(:delete, "/channels/#{channel_id}/recipients/#{user_id}")
115
+ end
116
+
117
+ def start_thread_from_message(channel_id:, message_id:, json:)
118
+ send_request(:post, "/channels/#{channel_id}/messages/#{message_id}/threads", json:)
119
+ end
120
+
121
+ def start_thread_without_message(channel_id:, json:)
122
+ send_request(:post, "/channels/#{channel_id}/threads", json:)
123
+ end
124
+
125
+ # NOTE: this is clearly identical to `start_thread_without_message`, but i
126
+ # guess Discord treats the action differently based on what's in the JSON
127
+ # payload?
128
+ def start_thread_in_forum_or_media_channel(channel_id:, json:)
129
+ send_request(:post, "/channels/#{channel_id}/threads", json:)
130
+ end
131
+
132
+ def join_thread(channel_id:)
133
+ send_request(:put, "/channels/#{channel_id}/thread-members/@me")
134
+ end
135
+
136
+ def add_thread_member(channel_id:, user_id:)
137
+ send_request(:put, "/channels/#{channel_id}/thread-members/#{user_id}")
138
+ end
139
+
140
+ def leave_thread(channel_id:)
141
+ send_request(:delete, "/channels/#{channel_id}/thread-members/@me")
142
+ end
143
+
144
+ def remove_thread_member(channel_id:, user_id:)
145
+ send_request(:delete, "/channels/#{channel_id}/thread-members/#{user_id}")
146
+ end
147
+
148
+ def get_thread_member(channel_id:, user_id:, params: {})
149
+ send_request(:get, "/channels/#{channel_id}/thread-members/#{user_id}", params:)
150
+ end
151
+
152
+ def list_thread_members(channel_id:, params: {})
153
+ send_request(:get, "/channels/#{channel_id}/thread-members", params:)
154
+ end
155
+
156
+ def list_public_archived_threads(channel_id:, params: {})
157
+ send_request(:get, "/channels/#{channel_id}/threads/archived/public", params:)
158
+ end
159
+
160
+ def list_private_archived_threads(channel_id:, params: {})
161
+ send_request(:get, "/channels/#{channel_id}/threads/archived/private", params:)
162
+ end
163
+
164
+ def list_joined_private_archived_threads(channel_id:, params: {})
165
+ send_request(:get, "/channels/#{channel_id}/users/@me/threads/archived/private", params:)
166
+ end
167
+ end
168
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class Emoji < Resource
7
+ def list_guild_emojis(guild_id:)
8
+ send_request(:get, "/guilds/#{guild_id}/emojis")
9
+ end
10
+
11
+ def get_guild_emoji(guild_id:, emoji_id:)
12
+ send_request(:get, "/guilds/#{guild_id}/emojis/#{emoji_id}")
13
+ end
14
+
15
+ def create_guild_emoji(guild_id:, json:)
16
+ send_request(:post, "/guilds/#{guild_id}/emojis", json:)
17
+ end
18
+
19
+ def modify_guild_emoji(guild_id:, emoji_id:, json:)
20
+ send_request(:patch, "/guilds/#{guild_id}/emojis/#{emoji_id}", json:)
21
+ end
22
+
23
+ def delete_guild_emoji(guild_id:, emoji_id:)
24
+ send_request(:delete, "/guilds/#{guild_id}/emojis/#{emoji_id}")
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,196 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class Guild < Resource
7
+ def create_guild(json:)
8
+ send_request(:post, "/guilds", json:)
9
+ end
10
+
11
+ def get_guild(guild_id:, params: {})
12
+ send_request(:get, "/guilds/#{guild_id}", params:)
13
+ end
14
+
15
+ def get_guild_preview(guild_id:)
16
+ send_request(:get, "/guilds/#{guild_id}/preview")
17
+ end
18
+
19
+ def modify_guild(guild_id:, json:)
20
+ send_request(:patch, "/guilds/#{guild_id}", json:)
21
+ end
22
+
23
+ def delete_guild(guild_id:)
24
+ send_request(:delete, "/guilds/#{guild_id}")
25
+ end
26
+
27
+ def get_guild_channels(guild_id:)
28
+ send_request(:get, "/guilds/#{guild_id}/channels")
29
+ end
30
+
31
+ def create_guild_channel(guild_id:, json:)
32
+ send_request(:post, "/guilds/#{guild_id}/channels", json:)
33
+ end
34
+
35
+ def modify_guild_channel_positions(guild_id:, json:)
36
+ send_request(:patch, "/guilds/#{guild_id}/channels", json:)
37
+ end
38
+
39
+ def list_active_guild_threads(guild_id:)
40
+ send_request(:get, "/guilds/#{guild_id}/threads/active")
41
+ end
42
+
43
+ def get_guild_member(guild_id:, user_id:)
44
+ send_request(:get, "/guilds/#{guild_id}/members/#{user_id}")
45
+ end
46
+
47
+ def list_guild_members(guild_id:, params: {})
48
+ send_request(:get, "/guilds/#{guild_id}/members", params:)
49
+ end
50
+
51
+ def search_guild_members(guild_id:, params: {})
52
+ send_request(:get, "/guilds/#{guild_id}/members/search", params:)
53
+ end
54
+
55
+ def add_guild_member(guild_id:, user_id:, json:)
56
+ send_request(:put, "/guilds/#{guild_id}/members/#{user_id}", json:)
57
+ end
58
+
59
+ def modify_guild_member(guild_id:, user_id:, json:)
60
+ send_request(:patch, "/guilds/#{guild_id}/members/#{user_id}", json:)
61
+ end
62
+
63
+ def modify_current_member(guild_id:, json:)
64
+ send_request(:patch, "/guilds/#{guild_id}/members/@me", json:)
65
+ end
66
+
67
+ # NOTE: deprecated in favor of `modify_current_member`
68
+ def modify_current_user_nick(guild_id:, json:)
69
+ send_request(:patch, "/guilds/#{guild_id}/members/@me/nick", json:)
70
+ end
71
+
72
+ def add_guild_member_role(guild_id:, user_id:, role_id:)
73
+ send_request(:put, "/guilds/#{guild_id}/members/#{user_id}/roles/#{role_id}")
74
+ end
75
+
76
+ def remove_guild_member_role(guild_id:, user_id:, role_id:)
77
+ send_request(:delete, "/guilds/#{guild_id}/members/#{user_id}/roles/#{role_id}")
78
+ end
79
+
80
+ def remove_guild_member(guild_id:, user_id:)
81
+ send_request(:delete, "/guilds/#{guild_id}/members/#{user_id}")
82
+ end
83
+
84
+ def get_guild_bans(guild_id:, params: {})
85
+ send_request(:get, "/guilds/#{guild_id}/bans", params:)
86
+ end
87
+
88
+ def get_guild_ban(guild_id:, user_id:)
89
+ send_request(:get, "/guilds/#{guild_id}/bans/#{user_id}")
90
+ end
91
+
92
+ def create_guild_ban(guild_id:, user_id:, json:)
93
+ send_request(:put, "/guilds/#{guild_id}/bans/#{user_id}", json:)
94
+ end
95
+
96
+ def remove_guild_ban(guild_id:, user_id:)
97
+ send_request(:delete, "/guilds/#{guild_id}/bans/#{user_id}")
98
+ end
99
+
100
+ def bulk_guild_ban(guild_id:, json:)
101
+ send_request(:post, "/guilds/#{guild_id}/bulk-ban", json:)
102
+ end
103
+
104
+ def get_guild_roles(guild_id:)
105
+ send_request(:get, "/guilds/#{guild_id}/roles")
106
+ end
107
+
108
+ def create_guild_role(guild_id:, json:)
109
+ send_request(:post, "/guilds/#{guild_id}/roles", json:)
110
+ end
111
+
112
+ def modify_guild_role_positions(guild_id:, json:)
113
+ send_request(:patch, "/guilds/#{guild_id}/roles", json:)
114
+ end
115
+
116
+ def modify_guild_role(guild_id:, role_id:, json:)
117
+ send_request(:patch, "/guilds/#{guild_id}/roles/#{role_id}", json:)
118
+ end
119
+
120
+ def modify_guild_mfa_level(guild_id:, json:)
121
+ send_request(:post, "/guilds/#{guild_id}/mfa", json:)
122
+ end
123
+
124
+ def delete_guild_role(guild_id:, role_id:)
125
+ send_request(:delete, "/guilds/#{guild_id}/roles/#{role_id}")
126
+ end
127
+
128
+ def get_guild_prune_count(guild_id:, params: {})
129
+ send_request(:get, "/guilds/#{guild_id}/prune", params:)
130
+ end
131
+
132
+ def begin_guild_prune(guild_id:, json:)
133
+ send_request(:post, "/guilds/#{guild_id}/prune", json:)
134
+ end
135
+
136
+ def get_guild_voice_regions(guild_id:)
137
+ send_request(:get, "/guilds/#{guild_id}/regions")
138
+ end
139
+
140
+ def get_guild_invites(guild_id:)
141
+ send_request(:get, "/guilds/#{guild_id}/invites")
142
+ end
143
+
144
+ def get_guild_integrations(guild_id:)
145
+ send_request(:get, "/guilds/#{guild_id}/integrations")
146
+ end
147
+
148
+ def delete_guild_integration(guild_id:, integration_id:)
149
+ send_request(:delete, "/guilds/#{guild_id}/integrations/#{integration_id}")
150
+ end
151
+
152
+ def get_guild_widget_settings(guild_id:)
153
+ send_request(:get, "/guilds/#{guild_id}/widget")
154
+ end
155
+
156
+ def modify_guild_widget(guild_id:, json:)
157
+ send_request(:patch, "/guilds/#{guild_id}/widget", json:)
158
+ end
159
+
160
+ def get_guild_widget(guild_id:)
161
+ send_request(:get, "/guilds/#{guild_id}/widget.json")
162
+ end
163
+
164
+ def get_guild_vanity_url(guild_id:)
165
+ send_request(:get, "/guilds/#{guild_id}/vanity-url")
166
+ end
167
+
168
+ def get_guild_widget_image(guild_id:, params: {})
169
+ send_request(:get, "/guilds/#{guild_id}/widget.png", params:)
170
+ end
171
+
172
+ def get_guild_welcome_screen(guild_id:)
173
+ send_request(:get, "/guilds/#{guild_id}/welcome-screen")
174
+ end
175
+
176
+ def modify_guild_welcome_screen(guild_id:, json:)
177
+ send_request(:patch, "/guilds/#{guild_id}/welcome-screen", json:)
178
+ end
179
+
180
+ def get_guild_onboarding(guild_id:)
181
+ send_request(:get, "/guilds/#{guild_id}/onboarding")
182
+ end
183
+
184
+ def modify_guild_onboarding(guild_id:, json:)
185
+ send_request(:put, "/guilds/#{guild_id}/onboarding", json:)
186
+ end
187
+
188
+ def modify_current_user_voice_state(guild_id:, json:)
189
+ send_request(:patch, "/guilds/#{guild_id}/voice-states/@me", json:)
190
+ end
191
+
192
+ def modify_user_voice_state(guild_id:, user_id:, json:)
193
+ send_request(:patch, "/guilds/#{guild_id}/voice-states/#{user_id}", json:)
194
+ end
195
+ end
196
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class GuildScheduledEvent < Resource
7
+ def list_scheduled_events_for_guild(guild_id:, params: {})
8
+ send_request(:get, "/guilds/#{guild_id}/scheduled-events", params:)
9
+ end
10
+
11
+ def create_guild_scheduled_event(guild_id:, json:)
12
+ send_request(:post, "/guilds/#{guild_id}/scheduled-events", json:)
13
+ end
14
+
15
+ def get_guild_scheduled_event(guild_id:, guild_scheduled_event_id:, params: {})
16
+ send_request(:get, "/guilds/#{guild_id}/scheduled-events/#{guild_scheduled_event_id}", params:)
17
+ end
18
+
19
+ def modify_guild_scheduled_event(guild_id:, guild_scheduled_event_id:, json:)
20
+ send_request(:patch, "/guilds/#{guild_id}/scheduled-events/#{guild_scheduled_event_id}", json:)
21
+ end
22
+
23
+ def delete_guild_scheduled_event(guild_id:, guild_scheduled_event_id:)
24
+ send_request(:delete, "/guilds/#{guild_id}/scheduled-events/#{guild_scheduled_event_id}")
25
+ end
26
+
27
+ def get_guild_scheduled_event_users(guild_id:, guild_scheduled_event_id:, params: {})
28
+ send_request(:get, "/guilds/#{guild_id}/scheduled-events/#{guild_scheduled_event_id}/users", params:)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class GuildTemplate < Resource
7
+ def get_guild_template(template_code:)
8
+ send_request(:get, "/guilds/templates/#{template_code}")
9
+ end
10
+
11
+ def create_guild_from_template(template_code:, json:)
12
+ send_request(:post, "/guilds/templates/#{template_code}", json:)
13
+ end
14
+
15
+ def get_guild_templates(guild_id:)
16
+ send_request(:get, "/guilds/#{guild_id}/templates")
17
+ end
18
+
19
+ def create_guild_template(guild_id:, json:)
20
+ send_request(:post, "/guilds/#{guild_id}/templates", json:)
21
+ end
22
+
23
+ def sync_guild_template(guild_id:, template_code:)
24
+ send_request(:put, "/guilds/#{guild_id}/templates/#{template_code}")
25
+ end
26
+
27
+ def modify_guild_template(guild_id:, template_code:, json:)
28
+ send_request(:patch, "/guilds/#{guild_id}/templates/#{template_code}", json:)
29
+ end
30
+
31
+ def delete_guild_template(guild_id:, template_code:)
32
+ send_request(:delete, "/guilds/#{guild_id}/templates/#{template_code}")
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class Interaction < Resource
7
+ def create_interaction_response(interaction_id:, interaction_token:, json:)
8
+ send_request(:post, "/interactions/#{interaction_id}/#{interaction_token}/callback", json:)
9
+ end
10
+
11
+ def get_original_interaction_response(application_id:, interaction_token:)
12
+ send_request(:get, "/webhooks/#{application_id}/#{interaction_token}/messages/@original")
13
+ end
14
+
15
+ def edit_original_interaction_response(application_id:, interaction_token:, json:)
16
+ send_request(:patch, "/webhooks/#{application_id}/#{interaction_token}/messages/@original", json:)
17
+ end
18
+
19
+ def delete_original_interaction_response(application_id:, interaction_token:)
20
+ send_request(:delete, "/webhooks/#{application_id}/#{interaction_token}/messages/@original")
21
+ end
22
+
23
+ def create_followup_message(application_id:, interaction_token:, json:)
24
+ send_request(:post, "/webhooks/#{application_id}/#{interaction_token}", json:)
25
+ end
26
+
27
+ def get_followup_message(application_id:, interaction_token:, message_id:)
28
+ send_request(:get, "/webhooks/#{application_id}/#{interaction_token}/messages/#{message_id}")
29
+ end
30
+
31
+ def edit_followup_message(application_id:, interaction_token:, message_id:, json:)
32
+ send_request(:patch, "/webhooks/#{application_id}/#{interaction_token}/messages/#{message_id}", json:)
33
+ end
34
+
35
+ def delete_followup_message(application_id:, interaction_token:, message_id:)
36
+ send_request(:delete, "/webhooks/#{application_id}/#{interaction_token}/messages/#{message_id}")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class Invite < Resource
7
+ def get_invite(invite_code:, params: {})
8
+ send_request(:get, "/invites/#{invite_code}", params:)
9
+ end
10
+
11
+ def delete_invite(invite_code:)
12
+ send_request(:delete, "/invites/#{invite_code}")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class StageInstance < Resource
7
+ def create_stage_instance(json:)
8
+ send_request(:post, "/stage-instances", json:)
9
+ end
10
+
11
+ def get_stage_instance(channel_id:)
12
+ send_request(:get, "/stage-instances/#{channel_id}")
13
+ end
14
+
15
+ def modify_stage_instance(channel_id:, json:)
16
+ send_request(:patch, "/stage-instances/#{channel_id}", json:)
17
+ end
18
+
19
+ def delete_stage_instance(channel_id:)
20
+ send_request(:delete, "/stage-instances/#{channel_id}")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class Sticker < Resource
7
+ def get_sticker(sticker_id:)
8
+ send_request(:get, "/stickers/#{sticker_id}")
9
+ end
10
+
11
+ def list_sticker_packs
12
+ send_request(:get, "/sticker-packs")
13
+ end
14
+
15
+ def list_guild_stickers(guild_id:)
16
+ send_request(:get, "/guilds/#{guild_id}/stickers")
17
+ end
18
+
19
+ def get_guild_sticker(guild_id:, sticker_id:)
20
+ send_request(:get, "/guilds/#{guild_id}/stickers/#{sticker_id}")
21
+ end
22
+
23
+ def create_guild_sticker(guild_id:, json:)
24
+ send_request(:post, "/guilds/#{guild_id}/stickers", json:)
25
+ end
26
+
27
+ def modify_guild_sticker(guild_id:, sticker_id:, json:)
28
+ send_request(:patch, "/guilds/#{guild_id}/stickers/#{sticker_id}", json:)
29
+ end
30
+
31
+ def delete_guild_sticker(guild_id:, sticker_id:)
32
+ send_request(:delete, "/guilds/#{guild_id}/stickers/#{sticker_id}")
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class User < Resource
7
+ def get_current_user
8
+ send_request(:get, "/users/@me")
9
+ end
10
+
11
+ def get_user(user_id:)
12
+ send_request(:get, "/users/#{user_id}")
13
+ end
14
+
15
+ def modify_current_user(json:)
16
+ send_request(:patch, "/users/@me", json:)
17
+ end
18
+
19
+ def get_current_user_guilds(params: {})
20
+ send_request(:get, "/users/@me/guilds", params:)
21
+ end
22
+
23
+ def get_current_user_guild_member(guild_id:)
24
+ send_request(:get, "/users/@me/guilds/#{guild_id}/member")
25
+ end
26
+
27
+ def leave_guild(guild_id:)
28
+ send_request(:delete, "/users/@me/guilds/#{guild_id}")
29
+ end
30
+
31
+ def create_dm(json:)
32
+ send_request(:post, "/users/@me/channels", json:)
33
+ end
34
+
35
+ def create_group_dm(json:)
36
+ send_request(:post, "/users/@me/channels", json:)
37
+ end
38
+
39
+ def get_current_user_connections
40
+ send_request(:get, "/users/@me/connections")
41
+ end
42
+
43
+ def get_current_user_application_role_connection(application_id:)
44
+ send_request(:get, "/users/@me/applications/#{application_id}/role-connections")
45
+ end
46
+
47
+ def update_current_user_application_role_connection(application_id:, json:)
48
+ send_request(:put, "/users/@me/applications/#{application_id}/role-connection", json:)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class Voice < Resource
7
+ def list_voice_regions
8
+ send_request(:get, "/voice/regions")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resource"
4
+
5
+ module LibDiscord
6
+ class Webhook < Resource
7
+ def create_webhook(channel_id:, json:)
8
+ send_request(:post, "/channels/#{channel_id}/webhooks", json:)
9
+ end
10
+
11
+ def get_channel_webhooks(channel_id:)
12
+ send_request(:get, "/channels/#{channel_id}/webhooks")
13
+ end
14
+
15
+ def get_guild_webhooks(guild_id:)
16
+ send_request(:get, "/guilds/#{guild_id}/webhooks")
17
+ end
18
+
19
+ def get_webhook(webhook_id:)
20
+ send_request(:get, "/webhooks/#{webhook_id}")
21
+ end
22
+
23
+ def get_webhook_with_token(webhook_id:, webhook_token:)
24
+ send_request(:get, "/webhooks/#{webhook_id}/#{webhook_token}")
25
+ end
26
+
27
+ def modify_webhook(webhook_id:, json:)
28
+ send_request(:patch, "/webhooks/#{webhook_id}", json:)
29
+ end
30
+
31
+ def modify_webhook_with_token(webhook_id:, webhook_token:, json:)
32
+ send_request(:patch, "/webhooks/#{webhook_id}/#{webhook_token}", json:)
33
+ end
34
+
35
+ def delete_webhook(webhook_id:)
36
+ send_request(:delete, "/webhooks/#{webhook_id}")
37
+ end
38
+
39
+ def delete_webhook_with_token(webhook_id:, webhook_token:)
40
+ send_request(:delete, "/webhooks/#{webhook_id}/#{webhook_token}")
41
+ end
42
+
43
+ def execute_webhook(webhook_id:, webhook_token:, json:, params: {})
44
+ send_request(:post, "/webhooks/#{webhook_id}/#{webhook_token}", json:, params:)
45
+ end
46
+
47
+ def execute_slack_compatible_webhook(webhook_id:, webhook_token:, params: {})
48
+ send_request(:post, "/webhooks/#{webhook_id}/#{webhook_token}/slack", params:)
49
+ end
50
+
51
+ def execute_github_compatible_webhook(webhook_id:, webhook_token:, params: {})
52
+ send_request(:post, "/webhooks/#{webhook_id}/#{webhook_token}/github", params:)
53
+ end
54
+
55
+ def get_webhook_message(webhook_id:, webhook_token:, message_id:, params: {})
56
+ send_request(:get, "/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}", params:)
57
+ end
58
+
59
+ def edit_webhook_message(webhook_id:, webhook_token:, message_id:, json:, params: {})
60
+ send_request(:patch, "/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}", json:, params:)
61
+ end
62
+
63
+ def delete_webhook_message(webhook_id:, webhook_token:, message_id:)
64
+ send_request(:delete, "/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}")
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/resources/application"
4
+ require "lib_discord/resources/application_command"
5
+ require "lib_discord/resources/application_role_connection_metadata"
6
+ require "lib_discord/resources/audit_log"
7
+ require "lib_discord/resources/auto_moderation"
8
+ require "lib_discord/resources/channel"
9
+ require "lib_discord/resources/emoji"
10
+ require "lib_discord/resources/guild"
11
+ require "lib_discord/resources/guild_scheduled_event"
12
+ require "lib_discord/resources/guild_template"
13
+ require "lib_discord/resources/interaction"
14
+ require "lib_discord/resources/invite"
15
+ require "lib_discord/resources/stage_instance"
16
+ require "lib_discord/resources/sticker"
17
+ require "lib_discord/resources/user"
18
+ require "lib_discord/resources/voice"
19
+ require "lib_discord/resources/webhook"
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LibDiscord
4
+ Response = Struct.new(
5
+ :code,
6
+ :headers,
7
+ :body_raw,
8
+ :body_parsed,
9
+ keyword_init: true
10
+ )
11
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/types"
4
+
5
+ module LibDiscord
6
+ module Types
7
+ include Dry::Types()
8
+
9
+ module Resource
10
+ HttpKwargs = Types::Hash.schema(
11
+ params?: Types::Params::Hash,
12
+ json?: Types::JSON::Hash
13
+ )
14
+
15
+ ClientHeaders = Types::Hash.map(
16
+ Types::Strict::Symbol,
17
+ Types::Strict::String
18
+ )
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LibDiscord
4
+ def self.project_url
5
+ "https://sr.ht/~komidore64/lib_discord"
6
+ end
7
+
8
+ def self.source_url
9
+ "https://git.sr.ht/~komidore64/lib_discord"
10
+ end
11
+
12
+ def self.bug_tracker_url
13
+ "https://todo.sr.ht/~komidore64/lib_discord"
14
+ end
15
+
16
+ def self.mailing_list_url
17
+ "https://sr.ht/~komidore64/lib_discord/lists"
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LibDiscord
4
+ def self.version
5
+ @version ||= Gem::Version.new("0.1.0.pre2")
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lib_discord/client"
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lib_discord
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre2
5
+ platform: ruby
6
+ authors:
7
+ - Adam Price
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-container
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-types
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: http
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.1'
55
+ description:
56
+ email:
57
+ - komidore64@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/lib_discord.rb
63
+ - lib/lib_discord/client.rb
64
+ - lib/lib_discord/errors.rb
65
+ - lib/lib_discord/resource.rb
66
+ - lib/lib_discord/resources.rb
67
+ - lib/lib_discord/resources/application.rb
68
+ - lib/lib_discord/resources/application_command.rb
69
+ - lib/lib_discord/resources/application_role_connection_metadata.rb
70
+ - lib/lib_discord/resources/audit_log.rb
71
+ - lib/lib_discord/resources/auto_moderation.rb
72
+ - lib/lib_discord/resources/channel.rb
73
+ - lib/lib_discord/resources/emoji.rb
74
+ - lib/lib_discord/resources/guild.rb
75
+ - lib/lib_discord/resources/guild_scheduled_event.rb
76
+ - lib/lib_discord/resources/guild_template.rb
77
+ - lib/lib_discord/resources/interaction.rb
78
+ - lib/lib_discord/resources/invite.rb
79
+ - lib/lib_discord/resources/stage_instance.rb
80
+ - lib/lib_discord/resources/sticker.rb
81
+ - lib/lib_discord/resources/user.rb
82
+ - lib/lib_discord/resources/voice.rb
83
+ - lib/lib_discord/resources/webhook.rb
84
+ - lib/lib_discord/response.rb
85
+ - lib/lib_discord/types.rb
86
+ - lib/lib_discord/urls.rb
87
+ - lib/lib_discord/version.rb
88
+ homepage:
89
+ licenses:
90
+ - AGPL-3.0-only
91
+ metadata:
92
+ rubygems_mfa_required: 'true'
93
+ bug_tracker_uri: https://todo.sr.ht/~komidore64/lib_discord
94
+ homepage_uri: https://sr.ht/~komidore64/lib_discord
95
+ mailing_list_uri: https://sr.ht/~komidore64/lib_discord/lists
96
+ source_code_uri: https://git.sr.ht/~komidore64/lib_discord
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '3.2'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubygems_version: 3.5.8
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Unfancy Discord API Ruby-bindings
116
+ test_files: []