From 2286c9af3f7c90ed555d255680d037b9e6574b6d Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Fri, 19 Mar 2021 16:48:11 +0530 Subject: [PATCH] required changes --- src/managers/channels.ts | 33 +++++++++++++++++++-------------- src/structures/textChannel.ts | 6 +++++- src/types/channel.ts | 22 ++++++++++++++++------ 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/managers/channels.ts b/src/managers/channels.ts index b5fd232..266b420 100644 --- a/src/managers/channels.ts +++ b/src/managers/channels.ts @@ -6,8 +6,7 @@ import { TextChannel } from '../structures/textChannel.ts' import { ChannelPayload, GuildChannelPayload, - MessageOptions, - MessageReference + MessageOptions } from '../types/channel.ts' import { CHANNEL } from '../types/endpoint.ts' import getChannelByType from '../utils/getChannelByType.ts' @@ -80,8 +79,7 @@ export class ChannelsManager extends BaseManager { async sendMessage( channel: string | TextChannel, content?: string | AllMessageOptions, - option?: AllMessageOptions, - reply?: Message + option?: AllMessageOptions ): Promise { const channelID = typeof channel === 'string' ? channel : channel.id @@ -104,16 +102,23 @@ export class ChannelsManager extends BaseManager { file: option?.file, files: option?.files, tts: option?.tts, - allowed_mentions: option?.allowedMentions - } - - if (reply !== undefined) { - const reference: MessageReference = { - message_id: reply.id, - channel_id: reply.channel.id, - guild_id: reply.guild?.id - } - payload.message_reference = reference + allowed_mentions: option?.allowedMentions, + message_reference: + option?.reply === undefined + ? undefined + : typeof option.reply === 'string' + ? { + message_id: option.reply + } + : typeof option.reply === 'object' + ? option.reply instanceof Message + ? { + message_id: option.reply.id, + channel_id: option.reply.channel.id, + guild_id: option.reply.guild?.id + } + : option.reply + : undefined } const resp = await this.client.rest.api.channels[channelID].messages.post( diff --git a/src/structures/textChannel.ts b/src/structures/textChannel.ts index 8291740..0520520 100644 --- a/src/structures/textChannel.ts +++ b/src/structures/textChannel.ts @@ -59,7 +59,11 @@ export class TextChannel extends Channel { option?: AllMessageOptions, reply?: Message ): Promise { - return this.client.channels.sendMessage(this, content, option, reply) + return this.client.channels.sendMessage( + this, + content, + Object.assign(option ?? {}, { reply }) + ) } /** diff --git a/src/types/channel.ts b/src/types/channel.ts index e1d44e0..7d06156 100644 --- a/src/types/channel.ts +++ b/src/types/channel.ts @@ -1,5 +1,5 @@ import { Embed } from '../structures/embed.ts' -import { MessageAttachment } from '../structures/message.ts' +import type { Message, MessageAttachment } from '../structures/message.ts' import { EmojiPayload } from './emoji.ts' import { MemberPayload } from './guild.ts' import { UserPayload } from './user.ts' @@ -156,16 +156,26 @@ export interface MessagePayload { stickers?: MessageStickerPayload[] } +export enum AllowedMentionType { + Roles = 'roles', + Users = 'users', + Everyone = 'everyone' +} + +export interface AllowedMentionsPayload { + parse?: AllowedMentionType[] + users?: string[] + roles?: string[] + replied_user?: boolean +} + export interface MessageOptions { tts?: boolean embed?: Embed file?: MessageAttachment files?: MessageAttachment[] - allowedMentions?: { - parse?: 'everyone' | 'users' | 'roles' - roles?: string[] - users?: string[] - } + allowedMentions?: AllowedMentionsPayload + reply?: Message | MessageReference | string } export interface ChannelMention {