From 484e995140cb511cd453f0cc414b289f0d033bc4 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 6 Apr 2021 10:23:18 +0200 Subject: [PATCH] fix(structures/channel): add ChannelStruct (#738) * fix it * Update channel.ts --- src/structures/channel.ts | 69 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/src/structures/channel.ts b/src/structures/channel.ts index 8663fcdf7..34ace27b2 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -7,10 +7,16 @@ import { editChannelOverwrite } from "../helpers/channels/edit_channel_overwrite import { sendMessage } from "../helpers/messages/send_message.ts"; import { disconnectMember } from "../helpers/mod.ts"; import { Channel, DiscordChannel } from "../types/channels/channel.ts"; +import { ModifyChannel } from "../types/channels/modify_channel.ts"; +import { DiscordOverwrite, Overwrite } from "../types/channels/overwrite.ts"; +import { CreateMessage } from "../types/messages/create_message.ts"; +import { PermissionStrings } from "../types/permissions/permission_strings.ts"; +import { VoiceState } from "../types/voice/voice_state.ts"; import { Collection } from "../util/collection.ts"; import { createNewProp, snakeKeysToCamelCase } from "../util/utils.ts"; +import { MessageStruct } from "./message.ts"; -const baseChannel: Partial = { +const baseChannel: Partial = { get guild() { return cache.guilds.get(this.guildId!); }, @@ -61,8 +67,8 @@ const baseChannel: Partial = { }, }; -// deno-lint-ignore require-await /** Create a structure object */ +// deno-lint-ignore require-await export async function createChannelStruct( data: DiscordChannel, guildId?: string, @@ -90,4 +96,61 @@ export async function createChannelStruct( return channel; } -export type ChannelStruct = Channel & typeof baseChannel; +export interface ChannelStruct extends Channel { + // GETTERS + + /** + * Gets the guild object for this channel. + * + * ⚠️ ADVANCED: If you use the custom cache, these will not work for you. Getters can not be async and custom cache requires async. + */ + guild?: GuildStruct; + /** + * Gets the messages from cache that were sent in this channel + * + * ⚠️ ADVANCED: If you use the custom cache, these will not work for you. Getters can not be async and custom cache requires async. + */ + messages: Collection; + /** The mention of the channel */ + mention: string; + /** + * Gets the voice states for this channel + * + * ⚠️ ADVANCED: If you use the custom cache, these will not work for you. Getters can not be async and custom cache requires async. + */ + voiceStates?: Collection; + /** + * Gets the connected members for this channel undefined if member is not cached + * + * ⚠️ ADVANCED: If you use the custom cache, these will not work for you. Getters can not be async and custom cache requires async. + */ + connectedMembers?: Collection; + + // METHODS + + /** Send a message to the channel. Requires SEND_MESSAGES permission. */ + send(content: string | CreateMessage): ReturnType; + /** Disconnect a member from a voice channel. Requires MOVE_MEMBERS permission. */ + disconnect(memberID: string): ReturnType; + /** Delete the channel */ + delete(): ReturnType; + /** Edit a channel Overwrite */ + editOverwrite( + overwriteID: string, + options: Omit, + ): ReturnType; + /** Delete a channel Overwrite */ + deleteOverwrite( + overwriteID: string, + ): ReturnType; + /** Checks if a channel overwrite for a user id or a role id has permission in this channel */ + hasPermission( + overwrites: DiscordOverwrite[], + permissions: PermissionStrings[], + ): ReturnType; + /** Edit the channel */ + edit( + options: ModifyChannel, + reason?: string, + ): ReturnType; +}