From ac68ad3f4acd3fa6fd58cef7275ac2ee1bafb083 Mon Sep 17 00:00:00 2001 From: Lexedia Date: Fri, 29 Nov 2024 00:07:49 +0100 Subject: [PATCH 1/2] set vanity url automatically --- bot_commands.lua | 6 ++++++ config.lua.default | 2 ++ deps/discordia/libs/client/API.lua | 5 +++++ deps/discordia/libs/containers/Guild.lua | 17 +++++++++++++++++ deps/discordia/libs/endpoints.lua | 1 + 5 files changed, 31 insertions(+) diff --git a/bot_commands.lua b/bot_commands.lua index cd97f0d..08306ee 100644 --- a/bot_commands.lua +++ b/bot_commands.lua @@ -4,6 +4,8 @@ local client = Bot.Client local config = Config +---@type discordia +local discordia = Discordia local enums = discordia.enums local MAX_NUMBER_OF_EMBED_FIELDS = 25 @@ -106,6 +108,10 @@ client:on('messageCreate', function(message) return end + if (message.type == enums.messageType.premiumGuildSubscriptionTier3 and message.guild.id == Config.MainGuildId) then + message.guild:setVanityCode(Config.VanityUrl) + end + local content for _, func in pairs(prefixes) do diff --git a/config.lua.default b/config.lua.default index a0aeba7..9248d0e 100644 --- a/config.lua.default +++ b/config.lua.default @@ -1,5 +1,7 @@ Token = "" -- Bot token OwnerUserId = "" +VanityUrl = "notaname" +MainGuildId = "323076998576603137" -- Module which will be loaded at bot start AutoloadModules = { diff --git a/deps/discordia/libs/client/API.lua b/deps/discordia/libs/client/API.lua index be4f89b..6981b24 100644 --- a/deps/discordia/libs/client/API.lua +++ b/deps/discordia/libs/client/API.lua @@ -404,6 +404,11 @@ function API:getGuildAuditLog(guild_id, query) return self:request("GET", endpoint, nil, query) end +function API:setGuildVanityUrl(guild_id, code) + local endpoint = f(endpoints.GUILD_VANITY_URL, guild_id) + return self:request("PATCH", endpoint, {code = code}) +end + function API:getChannel(channel_id) -- not exposed, use cache local endpoint = f(endpoints.CHANNEL, channel_id) return self:request("GET", endpoint) diff --git a/deps/discordia/libs/containers/Guild.lua b/deps/discordia/libs/containers/Guild.lua index a2f0941..c645c64 100644 --- a/deps/discordia/libs/containers/Guild.lua +++ b/deps/discordia/libs/containers/Guild.lua @@ -776,6 +776,23 @@ function Guild:createScheduledEvents(eventData) end end +--[=[ +@m setVanityUrl +@t http +@p code string +@r Invite +@d Sets the vanity URL for the guild. This is only available for guilds that have a level 3. +]=] +function Guild:setVanityCode(code) + local data, err = self.client._api:setGuildVanityUrl(self._id, {code = code}) + + if data then + return Invite(data, self.client) + else + return nil, err + end +end + --[=[@p shardId number The ID of the shard on which this guild is served. If only one shard is in operation, then this will always be 0.]=] function get.shardId(self) diff --git a/deps/discordia/libs/endpoints.lua b/deps/discordia/libs/endpoints.lua index f230626..15a08c6 100644 --- a/deps/discordia/libs/endpoints.lua +++ b/deps/discordia/libs/endpoints.lua @@ -51,6 +51,7 @@ return { GUILD_SCHEDULED_EVENT_USER = "/guilds/%s/scheduled-events/%s/users", GUILD_SCHEDULED_EVENTS = "/guilds/%s/scheduled-events", GUILD_WEBHOOKS = "/guilds/%s/webhooks", + GUILD_VANITY_URL = "/guilds/%s/vanity-url", INTERACTION_TOKEN_CALLBACK = "/interactions/%s/%s/callback", INVITE = "/invites/%s", OAUTH2_APPLICATION_ME = "/oauth2/applications/@me", From 0562e08ae7438c04283a4407505b8e978cb7401f Mon Sep 17 00:00:00 2001 From: Lexedia Date: Fri, 29 Nov 2024 00:09:15 +0100 Subject: [PATCH 2/2] fuck --- config.lua.default | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.lua.default b/config.lua.default index 9248d0e..b19595a 100644 --- a/config.lua.default +++ b/config.lua.default @@ -1,7 +1,7 @@ Token = "" -- Bot token OwnerUserId = "" -VanityUrl = "notaname" -MainGuildId = "323076998576603137" +VanityUrl = "" +MainGuildId = "" -- Module which will be loaded at bot start AutoloadModules = {