소스 검색

Check permissions

The author is checked the ability to manage messages before it can do
pin and save commands.
master
부모
커밋
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);


불러오는 중...
취소
저장