Bladeren bron

Check permissions

The author is checked the ability to manage messages before it can do
pin and save commands.
master
TheoryOfNekomata 3 jaren geleden
bovenliggende
commit
fdd5b4f3fe
3 gewijzigde bestanden met toevoegingen van 27 en 3 verwijderingen
  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 Bestand weergeven

@@ -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 Bestand weergeven

@@ -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 Bestand weergeven

@@ -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);


Laden…
Annuleren
Opslaan