Browse Source

Remove message after violation command; don't apply on moderators/bot

ghorsington 4 years ago
parent
commit
837232caa0
1 changed files with 13 additions and 1 deletions
  1. 13 1
      bot/src/plugins/violation.ts

+ 13 - 1
bot/src/plugins/violation.ts

@@ -1,5 +1,5 @@
 import { Plugin, ICommandData, Command, Event, BotEventData } from "src/model/plugin";
-import { parseArgs, tryDo, parseDuration, UNIT_MEASURES, Option } from "src/util";
+import { parseArgs, tryDo, parseDuration, UNIT_MEASURES, Option, isAuthorisedAsync } from "src/util";
 import { GuildMember, Guild, MessageEmbed, Message, TextChannel, PartialGuildMember, User } from "discord.js";
 import { logger } from "src/logging";
 import { client } from "src/client";
@@ -156,6 +156,7 @@ export class ViolationPlugin {
 
         await this.applyTimedViolation(Mute, info, "mute", handler.start, handler.stop);
         await this.sendViolationMessage(message, info, "User has been muted for server violation");
+        await tryDo(message.delete());
     }
 
     @Command({
@@ -169,6 +170,7 @@ export class ViolationPlugin {
     })
     async unmuteUser({ message }: ICommandData): Promise<void> {
         await this.removeTimedViolation(Mute, message, "mute");
+        await tryDo(message.delete());
     }
 
     private getViolationHandler(type: ObjectType<TimedViolation>): TimedViolationStopHandler {
@@ -355,6 +357,11 @@ export class ViolationPlugin {
             return { ok: false };
         }
 
+        if (user.id == client.botUser.id) {
+            await message.reply(`cannot apply ${command} on me!`);
+            return { ok: false };
+        }
+
         const memberResolve = await tryDo(message.guild.members.fetch(user));
         if (!memberResolve.ok) {
             await message.reply("user is not member of the server anymore!");
@@ -362,6 +369,11 @@ export class ViolationPlugin {
             return { ok: false };
         }
 
+        if (await isAuthorisedAsync(memberResolve.result)) {
+            await message.reply(`cannot apply ${command} on another moderator!`);
+            return { ok: false };
+        }
+
         let durationMs = parseDuration(duration);
         let reasonArray = rest;