Преглед на файлове

Check permissions

The author is checked the ability to manage messages before it can do
pin and save commands.
master
TheoryOfNekomata преди 3 години
родител
ревизия
fdd5b4f3fe
променени са 3 файла, в които са добавени 27 реда и са изтрити 3 реда
  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 Целия файл

@@ -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 Целия файл

@@ -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 Целия файл

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


Зареждане…
Отказ
Запис