mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 21:16:09 +00:00
Fix for ChannelFactory and add Guild.fetchVoiceRegions (#74)
* Add CategoryChannel and update ChannelFactory * Add Guild.fetchVoiceRegions method * Remove no used type * Update CategoryChannel * Update guilds cache * Fix
This commit is contained in:
parent
2e011a4b11
commit
5021374970
@ -448,3 +448,8 @@ export function GUILD_WIDGET(guildId: Snowflake, options: GetWidget = { get: 'se
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/** @link https://discord.com/developers/docs/resources/guild#get-guild-voice-regions */
|
||||
export function GUILD_VOICE_REGIONS(guildId: string): string {
|
||||
return `/guilds/${guildId}/regions`;
|
||||
}
|
@ -30,6 +30,7 @@ import Invite from './Invite.ts';
|
||||
import Webhook from './Webhook.ts';
|
||||
import User from './User.ts';
|
||||
import ThreadMember from './ThreadMember.ts';
|
||||
import Permissions, { PermissionResolvable } from "./Permissions.ts";
|
||||
|
||||
/**
|
||||
* Abstract class that represents the base for creating a new channel.
|
||||
@ -89,6 +90,43 @@ export abstract class BaseChannel implements Model {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a category channel.
|
||||
*/
|
||||
export class CategoryChannel extends BaseChannel {
|
||||
constructor(session: Session, data: DiscordChannel) {
|
||||
super(session, data);
|
||||
this.id = data.id;
|
||||
this.name = data.name ? data.name : '';
|
||||
this.nsfw = data.nsfw ? data.nsfw : false;
|
||||
this.guildId = data.guild_id ? data.guild_id : undefined;
|
||||
this.type = ChannelTypes.GuildCategory;
|
||||
this.position = data.position ? data.position : undefined;
|
||||
this.parentId = data.parent_id ? data.parent_id : undefined;
|
||||
|
||||
this.permissionOverwrites = [] as PermissionsOverwrites[];
|
||||
// TODO: improve this and test
|
||||
if (data.permission_overwrites && data.permission_overwrites.length > 0) {
|
||||
data.permission_overwrites.forEach(v => {
|
||||
this.permissionOverwrites.push({
|
||||
id: v.id,
|
||||
type: v.type,
|
||||
allow: new Permissions(parseInt(v.allow as string) as PermissionResolvable),
|
||||
deny: new Permissions(parseInt(v.deny as string) as PermissionResolvable),
|
||||
} as PermissionsOverwrites);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
id: Snowflake;
|
||||
parentId?: string;
|
||||
name: string;
|
||||
permissionOverwrites: PermissionsOverwrites[];
|
||||
nsfw: boolean;
|
||||
guildId?: Snowflake;
|
||||
position?: number;
|
||||
}
|
||||
|
||||
/** TextChannel */
|
||||
/**
|
||||
* @link https://discord.com/developers/docs/resources/channel#create-channel-invite-json-params
|
||||
@ -816,7 +854,8 @@ export type Channel =
|
||||
| DMChannel
|
||||
| NewsChannel
|
||||
| ThreadChannel
|
||||
| StageChannel;
|
||||
| StageChannel
|
||||
| CategoryChannel;
|
||||
|
||||
export type ChannelInGuild =
|
||||
| GuildTextChannel
|
||||
@ -868,6 +907,8 @@ export class ChannelFactory {
|
||||
return new VoiceChannel(session, channel, channel.guild_id!);
|
||||
case ChannelTypes.GuildStageVoice:
|
||||
return new StageChannel(session, channel, channel.guild_id!);
|
||||
case ChannelTypes.GuildCategory:
|
||||
return new CategoryChannel(session, channel);
|
||||
default:
|
||||
if (textBasedChannels.includes(channel.type)) {
|
||||
return new TextChannel(session, channel);
|
||||
|
@ -10,6 +10,7 @@ import type {
|
||||
DiscordMemberWithUser,
|
||||
DiscordOverwrite,
|
||||
DiscordRole,
|
||||
DiscordVoiceRegion,
|
||||
ExplicitContentFilterLevels,
|
||||
GuildNsfwLevel,
|
||||
MakeRequired,
|
||||
@ -994,6 +995,19 @@ export class Guild extends BaseGuild implements Model {
|
||||
|
||||
return new Guild(this.session, guild);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetchVoiceRegions gets the voice regions available for the guild.
|
||||
* @see {@link DiscordVoiceRegion}
|
||||
* @returns Promise that resolves to an array of voice regions.
|
||||
*/
|
||||
async fetchVoiceRegions(): Promise<DiscordVoiceRegion[]> {
|
||||
return await this.session.rest.runMethod<DiscordVoiceRegion[]>(
|
||||
this.session.rest,
|
||||
'GET',
|
||||
Routes.GUILD_VOICE_REGIONS(this.id),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default Guild;
|
||||
|
Loading…
x
Reference in New Issue
Block a user