Skip to content

Commit

Permalink
feat: add experimental getGuildMemberRoleList
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 6, 2025
1 parent a513aa1 commit 7292c07
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions adapters/discord/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ export class DiscordBot<C extends Context = Context> extends Bot<C, DiscordBot.C
return this.internal.removeGuildMemberRole(guildId, userId, roleId)
}

async getGuildMemberRoleList(guildId: string, userId: string, next?: string) {
const data = await this.internal.getGuildMember(guildId, userId)
return { data: data.roles.map(id => ({ id })) }
}

async getGuildRoleList(guildId: string) {
const data = await this.internal.getGuildRoles(guildId)
return { data: data.map(Discord.decodeRole) }
Expand Down
6 changes: 6 additions & 0 deletions adapters/discord/src/types/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ declare module './internal' {
* @see https://discord.com/developers/docs/resources/guild#modify-guild-role-positions
*/
modifyGuildRolePositions(guild_id: snowflake, param: Role.Params.ModifyPositions): Promise<Role[]>
/**
* Returns a role object for the specified role.
* @see https://discord.com/developers/docs/resources/guild#get-guild-role
*/
getGuildRole(guild_id: snowflake, role_id: snowflake): Promise<Role>
/**
* Modify a guild role. Requires the MANAGE_ROLES permission. Returns the updated role on success. Fires a Guild Role Update Gateway event.
* @see https://discord.com/developers/docs/resources/guild#modify-guild-role
Expand All @@ -247,6 +252,7 @@ Internal.define({
PATCH: 'modifyGuildRolePositions',
},
'/guilds/{guild.id}/roles/{role.id}': {
GET: 'getGuildRole',
PATCH: 'modifyGuildRole',
DELETE: 'deleteGuildRole',
},
Expand Down
8 changes: 6 additions & 2 deletions packages/protocol/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Element from '@satorijs/element'
import { Dict, isNullable, pick } from 'cosmokit'

type PartialWithPick<T, K extends keyof T> = Partial<T> & Pick<T, K>

export interface SendOptions {
linkPreview?: boolean
}
Expand Down Expand Up @@ -66,6 +68,7 @@ export const Methods: Dict<Method> = {
'guild.member.mute': Method('muteGuildMember', ['guild_id', 'user_id', 'duration', 'reason']),
'guild.member.role.set': Method('setGuildMemberRole', ['guild_id', 'user_id', 'role_id']),
'guild.member.role.unset': Method('unsetGuildMemberRole', ['guild_id', 'user_id', 'role_id']),
'guild.member.role.list': Method('getGuildMemberRoleList', ['guild_id', 'user_id', 'next']),

'guild.role.list': Method('getGuildRoleList', ['guild_id', 'next']),
'guild.role.create': Method('createGuildRole', ['guild_id', 'data']),
Expand Down Expand Up @@ -137,10 +140,11 @@ export interface Methods {
getGuildMemberIter(guildId: string): AsyncIterable<GuildMember>
kickGuildMember(guildId: string, userId: string, permanent?: boolean): Promise<void>
muteGuildMember(guildId: string, userId: string, duration: number, reason?: string): Promise<void>

// role
setGuildMemberRole(guildId: string, userId: string, roleId: string): Promise<void>
unsetGuildMemberRole(guildId: string, userId: string, roleId: string): Promise<void>
getGuildMemberRoleList(guildId: string, userId: string, next?: string): Promise<List<PartialWithPick<GuildRole, 'id'>>>

// role
getGuildRoleList(guildId: string, next?: string): Promise<List<GuildRole>>
getGuildRoleIter(guildId: string): AsyncIterable<GuildRole>
createGuildRole(guildId: string, data: Partial<GuildRole>): Promise<GuildRole>
Expand Down

0 comments on commit 7292c07

Please sign in to comment.