diff --git a/src/commands/pin.ts b/src/commands/pin.ts index 7878cb1..72ab8cc 100644 --- a/src/commands/pin.ts +++ b/src/commands/pin.ts @@ -4,14 +4,11 @@ import messages from '../messages.json'; import { transferPin } from '../utils/common'; const pin = async ( - message: Message, mainTextChannel: TextChannel, pinTextChannel: TextChannel, silent = false, + message: Message, + mainTextChannel: TextChannel, + pinTextChannel: TextChannel, + silent = false, ): Promise => { - const isReply = message.type === 'REPLY'; - if (!isReply) { - await message.reply(messages.NOTHING_TO_PIN); - return; - } - const authorMember = await message.guild?.members.fetch(message.author); if (!authorMember) { await message.reply(messages.INVALID_PERMISSIONS); @@ -24,6 +21,12 @@ const pin = async ( return; } + const isReply = message.type === 'REPLY'; + if (!isReply) { + await message.reply(messages.NOTHING_TO_PIN); + return; + } + const reply = await message.fetchReference(); await transferPin(reply, pinTextChannel, silent); await message.reply(messages.PIN_COMPLETE); diff --git a/src/commands/save.ts b/src/commands/save.ts index c31ee60..c8315c0 100644 --- a/src/commands/save.ts +++ b/src/commands/save.ts @@ -4,7 +4,10 @@ import messages from '../messages.json'; import { transferPin } from '../utils/common'; const save = async ( - message: Message, mainTextChannel: TextChannel, pinTextChannel: TextChannel, silent = true, + message: Message, + mainTextChannel: TextChannel, + pinTextChannel: TextChannel, + silent = true, ): Promise => { const authorMember = await message.guild?.members.fetch(message.author); if (!authorMember) { diff --git a/src/index.ts b/src/index.ts index e94e69b..e0fecf4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,10 +29,10 @@ const listen = async (channelIDMap: Map) => { const mainTextChannel = mainChannel as TextChannel; const pinTextChannel = pinChannel as TextChannel; - const clientUser = client.user; - if (!clientUser) { + if (!client.user) { return; } + const clientUser = client.user; if (message.type === 'CHANNEL_PINNED_MESSAGE') { const reply = await message.fetchReference(); @@ -47,11 +47,6 @@ const listen = async (channelIDMap: Map) => { return; } - const mentioned = message.mentions.users.has(clientUser.id); - if (!mentioned) { - return; - } - switch (message.content) { case getCommandPattern(clientUser, 'pin'): await pin(message, mainTextChannel, pinTextChannel); @@ -63,7 +58,12 @@ const listen = async (channelIDMap: Map) => { break; } - await message.reply(messages.UNKNOWN_COMMAND); + if ( + message.content.startsWith(`<@!${clientUser.id}>`) + || message.content.startsWith(`<@${clientUser.id}>`) + ) { + await message.reply(messages.UNKNOWN_COMMAND); + } }); }); diff --git a/src/utils/common.ts b/src/utils/common.ts index 5b5b8ac..f8d00ce 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -9,15 +9,7 @@ export const transferPin = async ( : reply.author.toString()}: ${reply.content}`, - embeds: Array.from(reply.attachments.values()) - .map((a) => ({ - image: { - height: a.height as number, - url: a.url, - width: a.width as number, - proxy_url: a.proxyURL, - }, - })), + files: Array.from(reply.attachments.values()), }); };