Skip to content

Commit

Permalink
feat: add notes for future api support in other classes
Browse files Browse the repository at this point in the history
  • Loading branch information
4x8Matrix committed Nov 5, 2024
1 parent 90b8599 commit cf87475
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 69 deletions.
38 changes: 4 additions & 34 deletions development.luau
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ local intentsBuilder = require("@builders/intents")

local env = require(".env")

local PENGU_BOT_ID = "726819179054891149"
local DISCORD_LUAU_SERVER = "1273035219561091193"

local discordIntents = intentsBuilder.new()

discordIntents:addIntent("Guilds")
Expand All @@ -16,40 +19,7 @@ local discordBot = botObject.new({
discordBot.onAllShardsReady:listen(function()
assert(discordBot.application, ``)

-- local guild = discordBot:getGuildAsync("1273035219561091193"):expect("1")

-- for _, member in guild:listGuildMembersAsync(nil, 10):expect("2") do
-- print(member.user)
-- end

-- local member = guild:getGuildMemberAsync("685566749516628033"):expect("2")

-- print(member)

-- local threads = guild:getThreadsAsync():catch(function(error, traceback)
-- warn(error)
-- print(traceback)
-- end)

-- print(threads:expect(`Uh oh, but on the second one?!`))

-- guild
-- :modifyGuildAsync(guildBuilder
-- .new({
-- name = "Discord Luau",
-- })
-- :build())
-- :after(function()
-- print("RENAMED!")
-- end)

-- local preview = guild:fetchGuildPreviewAsync():expect(`2`)

-- local guildTextChannels = guild:getTextChannelsAsync():expect(`Uh oh, but on the second one?!`)

-- for _, channel in guildTextChannels do
-- print(channel.name)
-- end
local guild = discordBot:getGuildAsync(DISCORD_LUAU_SERVER):expect("1")
end)

discordBot:connectAsync():after(function()
Expand Down
10 changes: 10 additions & 0 deletions packages/classes/src/guild/member.luau
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ local Member = {}
Member.Interface = {}
Member.Prototype = {}

-- https://discord.com/developers/docs/resources/guild#modify-guild-member
-- https://discord.com/developers/docs/resources/guild#modify-current-member
-- https://discord.com/developers/docs/resources/guild#add-guild-member-role
-- https://discord.com/developers/docs/resources/guild#remove-guild-member-role

-- https://discord.com/developers/docs/resources/voice#get-current-user-voice-state
-- https://discord.com/developers/docs/resources/voice#get-user-voice-state
-- https://discord.com/developers/docs/resources/voice#modify-current-user-voice-state
-- https://discord.com/developers/docs/resources/voice#modify-user-voice-state

function Member.Prototype.sync(self: Member, guildMemberData: apiTypes.GuildMemberObject)
self.user = guildMemberData.user and user.new(guildMemberData.user)

Expand Down
4 changes: 4 additions & 0 deletions packages/classes/src/guild/role.luau
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ local Role = {}
Role.Interface = {}
Role.Prototype = {}

-- https://discord.com/developers/docs/resources/guild#modify-guild-role-positions
-- https://discord.com/developers/docs/resources/guild#modify-guild-role
-- https://discord.com/developers/docs/resources/guild#delete-guild-role

function Role.Prototype.sync(self: Role, roleData: apiTypes.GuildRoleObject)
local tagArray = {}

Expand Down
34 changes: 0 additions & 34 deletions packages/classes/src/guild/unavailableGuild.luau
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
https://discord.com/developers/docs/resources/guild#unavailable-guild-object
]]

local future = require("@vendor/future")

local restGuild = require("@rest/guild")
local classGuild = require("@classes/guild/guild")

local apiTypes = require("@api-types/apiTypes")

local state = require("@classes/state")
Expand All @@ -18,35 +13,6 @@ local UnavailableGuild = {}
UnavailableGuild.Interface = {}
UnavailableGuild.Prototype = {}

--[[
Asynchronously retrieves the full Guild object for this UnavailableGuild.
]]
function UnavailableGuild.Prototype.getAsync(
self: UnavailableGuild,
withCounts: boolean?
): future.Future<classGuild.Guild>
return future.new(function()
local guildData = self.state.cache.guilds:get(self.id)

if guildData then
return classGuild.new(self.state, guildData)
end

local request = self.state.rest:newRequest()
local status, response = restGuild
.getGuildAsync(request, self.id, {
withCounts = withCounts,
})
:await()

assert(status == "Fulfilled", tostring(response))

self.state.cache.guilds:set(self.id, response)

return classGuild.new(self.state, response)
end)
end

function UnavailableGuild.Interface.new(state: state.State, id: apiTypes.Snowflake): UnavailableGuild
local self = setmetatable(
{
Expand Down
22 changes: 21 additions & 1 deletion packages/rest/src/guild.luau
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,26 @@ function Guild.getGuildRolesAsync(
end)
end

-- https://discord.com/developers/docs/resources/guild#get-guild-role
function Guild.getGuildRoleAsync(
instance: request.Request,
guildId: apiTypes.Snowflake,
roleId: apiTypes.Snowflake
): future.Future<restTypes.GetGuildRoleResponse>
return future.new(function()
instance:assertToken()

instance:setMethod("GET")
instance:setUrl(string.format(restEndpoints.GetGuildRole, guildId, roleId))

local status, response = instance:executeAsync():await()

assert(status == "Fulfilled", tostring(response))

return response.body
end)
end

-- https://discord.com/developers/docs/resources/guild#create-guild-role
function Guild.createGuildRoleAsync(
instance: request.Request,
Expand Down Expand Up @@ -674,7 +694,7 @@ function Guild.getGuildPruneCountAsync(
instance:assertToken()

instance:addUrlParam("days", tostring(urlParams.days))
instance:addUrlParam("includeRoles", tostring(urlParams.includeRoles))
instance:addUrlParam("include_roles", tostring(urlParams.includeRoles))

instance:setMethod("GET")
instance:setUrl(string.format(restEndpoints.GetGuildPruneCount, guildId))
Expand Down

0 comments on commit cf87475

Please sign in to comment.