Fix the checking of conditions in order to execute commands.master
@@ -4,14 +4,11 @@ import messages from '../messages.json'; | |||||
import { transferPin } from '../utils/common'; | import { transferPin } from '../utils/common'; | ||||
const pin = async ( | const pin = async ( | ||||
message: Message, mainTextChannel: TextChannel, pinTextChannel: TextChannel, silent = false, | |||||
message: Message, | |||||
mainTextChannel: TextChannel, | |||||
pinTextChannel: TextChannel, | |||||
silent = false, | |||||
): Promise<void> => { | ): Promise<void> => { | ||||
const isReply = message.type === 'REPLY'; | |||||
if (!isReply) { | |||||
await message.reply(messages.NOTHING_TO_PIN); | |||||
return; | |||||
} | |||||
const authorMember = await message.guild?.members.fetch(message.author); | const authorMember = await message.guild?.members.fetch(message.author); | ||||
if (!authorMember) { | if (!authorMember) { | ||||
await message.reply(messages.INVALID_PERMISSIONS); | await message.reply(messages.INVALID_PERMISSIONS); | ||||
@@ -24,6 +21,12 @@ const pin = async ( | |||||
return; | return; | ||||
} | } | ||||
const isReply = message.type === 'REPLY'; | |||||
if (!isReply) { | |||||
await message.reply(messages.NOTHING_TO_PIN); | |||||
return; | |||||
} | |||||
const reply = await message.fetchReference(); | const reply = await message.fetchReference(); | ||||
await transferPin(reply, pinTextChannel, silent); | await transferPin(reply, pinTextChannel, silent); | ||||
await message.reply(messages.PIN_COMPLETE); | await message.reply(messages.PIN_COMPLETE); | ||||
@@ -4,7 +4,10 @@ import messages from '../messages.json'; | |||||
import { transferPin } from '../utils/common'; | import { transferPin } from '../utils/common'; | ||||
const save = async ( | const save = async ( | ||||
message: Message, mainTextChannel: TextChannel, pinTextChannel: TextChannel, silent = true, | |||||
message: Message, | |||||
mainTextChannel: TextChannel, | |||||
pinTextChannel: TextChannel, | |||||
silent = true, | |||||
): Promise<void> => { | ): Promise<void> => { | ||||
const authorMember = await message.guild?.members.fetch(message.author); | const authorMember = await message.guild?.members.fetch(message.author); | ||||
if (!authorMember) { | if (!authorMember) { | ||||
@@ -29,10 +29,10 @@ const listen = async (channelIDMap: Map<string, string>) => { | |||||
const mainTextChannel = mainChannel as TextChannel; | const mainTextChannel = mainChannel as TextChannel; | ||||
const pinTextChannel = pinChannel as TextChannel; | const pinTextChannel = pinChannel as TextChannel; | ||||
const clientUser = client.user; | |||||
if (!clientUser) { | |||||
if (!client.user) { | |||||
return; | return; | ||||
} | } | ||||
const clientUser = client.user; | |||||
if (message.type === 'CHANNEL_PINNED_MESSAGE') { | if (message.type === 'CHANNEL_PINNED_MESSAGE') { | ||||
const reply = await message.fetchReference(); | const reply = await message.fetchReference(); | ||||
@@ -47,11 +47,6 @@ const listen = async (channelIDMap: Map<string, string>) => { | |||||
return; | return; | ||||
} | } | ||||
const mentioned = message.mentions.users.has(clientUser.id); | |||||
if (!mentioned) { | |||||
return; | |||||
} | |||||
switch (message.content) { | switch (message.content) { | ||||
case getCommandPattern(clientUser, 'pin'): | case getCommandPattern(clientUser, 'pin'): | ||||
await pin(message, mainTextChannel, pinTextChannel); | await pin(message, mainTextChannel, pinTextChannel); | ||||
@@ -63,7 +58,12 @@ const listen = async (channelIDMap: Map<string, string>) => { | |||||
break; | break; | ||||
} | } | ||||
await message.reply(messages.UNKNOWN_COMMAND); | |||||
if ( | |||||
message.content.startsWith(`<@!${clientUser.id}>`) | |||||
|| message.content.startsWith(`<@${clientUser.id}>`) | |||||
) { | |||||
await message.reply(messages.UNKNOWN_COMMAND); | |||||
} | |||||
}); | }); | ||||
}); | }); | ||||
@@ -9,15 +9,7 @@ export const transferPin = async ( | |||||
: reply.author.toString()}: | : reply.author.toString()}: | ||||
${reply.content}`, | ${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()), | |||||
}); | }); | ||||
}; | }; | ||||