Ver código fonte

Check permissions

The author is checked the ability to manage messages before it can do
pin and save commands.
master
TheoryOfNekomata 3 anos atrás
pai
commit
fdd5b4f3fe
3 arquivos alterados com 27 adições e 3 exclusões
  1. +13
    -1
      src/commands/pin.ts
  2. +12
    -0
      src/commands/save.ts
  3. +2
    -2
      src/index.ts

+ 13
- 1
src/commands/pin.ts Ver arquivo

@@ -4,7 +4,7 @@ import messages from '../messages.json';
import { transferPin } from '../utils/common';

const pin = async (
message: Message, pinTextChannel: TextChannel, silent = false,
message: Message, mainTextChannel: TextChannel, pinTextChannel: TextChannel, silent = false,
): Promise<void> => {
const isReply = message.type === 'REPLY';
if (!isReply) {
@@ -12,6 +12,18 @@ const pin = async (
return;
}

const authorMember = await message.guild?.members.fetch(message.author);
if (!authorMember) {
await message.reply(messages.INVALID_PERMISSIONS);
return;
}

const authorCanPin = authorMember.permissionsIn(mainTextChannel).has('MANAGE_MESSAGES');
if (!authorCanPin) {
await message.reply(messages.INVALID_PERMISSIONS);
return;
}

const reply = await message.fetchReference();
await transferPin(reply, pinTextChannel, silent);
await message.reply(messages.PIN_COMPLETE);


+ 12
- 0
src/commands/save.ts Ver arquivo

@@ -6,6 +6,18 @@ import { transferPin } from '../utils/common';
const save = async (
message: Message, mainTextChannel: TextChannel, pinTextChannel: TextChannel, silent = true,
): Promise<void> => {
const authorMember = await message.guild?.members.fetch(message.author);
if (!authorMember) {
await message.reply(messages.INVALID_PERMISSIONS);
return;
}

const authorCanPin = authorMember.permissionsIn(mainTextChannel).has('MANAGE_MESSAGES');
if (!authorCanPin) {
await message.reply(messages.INVALID_PERMISSIONS);
return;
}

const pinnedMessages = await mainTextChannel.messages.fetchPinned();
const pinnedMessagesCollection = Array.from(pinnedMessages.values());
if (pinnedMessagesCollection.length <= 0) {


+ 2
- 2
src/index.ts Ver arquivo

@@ -38,7 +38,7 @@ const listen = async (channelIDMap: Map<string, string>) => {
const reply = await message.fetchReference();
await transferPin(reply, pinTextChannel, false);
await reply.unpin();
await mainTextChannel.send(`${message.author.toString()} ${messages.PIN_COMPLETE as string}`);
await mainTextChannel.send(`${message.author.toString()} ${messages.PIN_COMPLETE}`);
await message.delete();
return;
}
@@ -54,7 +54,7 @@ const listen = async (channelIDMap: Map<string, string>) => {

switch (message.content) {
case getCommandPattern(clientUser, 'pin'):
await pin(message, pinTextChannel);
await pin(message, mainTextChannel, pinTextChannel);
return;
case getCommandPattern(clientUser, 'save'):
await save(message, mainTextChannel, pinTextChannel);


Carregando…
Cancelar
Salvar