浏览代码

Refactor logger.warning into logger.warn

ghorsington 4 年之前
父节点
当前提交
6ebd5f59bf
共有 4 个文件被更改,包括 18 次插入15 次删除
  1. 1 1
      bot/src/main.ts
  2. 2 2
      bot/src/plugins/greet.ts
  3. 9 7
      bot/src/plugins/violation.ts
  4. 6 5
      shared/src/db/entity/Violation.ts

+ 1 - 1
bot/src/main.ts

@@ -25,7 +25,7 @@ client.bot.on("message", async m => {
         return;
 
     if (m.channel.type != "text") {
-        logger.warning("User %s (%s#%s) tried to execute command in DMs. Message: %s.", m.author.id, m.author.username, m.author.discriminator, m.content);
+        logger.warn("User %s (%s#%s) tried to execute command in DMs. Message: %s.", m.author.id, m.author.username, m.author.discriminator, m.content);
         await m.reply("DM commands are disabled, sorry!");
         return;
     }

+ 2 - 2
bot/src/plugins/greet.ts

@@ -42,12 +42,12 @@ export class GreetPlugin {
 
         const greetingChannel = client.bot.channels.resolve(guildGreeting.greetingChannelId);
         if (!greetingChannel) {
-            logger.warning("No channel %s in guild %s, can't greet!", guildGreeting.greetingChannelId, guildGreeting.guildId);
+            logger.warn("No channel %s in guild %s, can't greet!", guildGreeting.greetingChannelId, guildGreeting.guildId);
             return undefined;
         }
 
         if (!(greetingChannel instanceof TextChannel)) {
-            logger.warning("Channel %s is of not a text channel (got type: %s)", greetingChannel.id, greetingChannel.type);
+            logger.warn("Channel %s is of not a text channel (got type: %s)", greetingChannel.id, greetingChannel.type);
             return undefined;
         }
 

+ 9 - 7
bot/src/plugins/violation.ts

@@ -6,7 +6,7 @@ import { client } from "src/client";
 import humanizeDuration from "humanize-duration";
 import { getRepository, ObjectType, FindConditions, DeepPartial } from "typeorm";
 import { GuildViolationSettings } from "@shared/db/entity/GuildViolationSettings";
-import { Mute, TimedViolation } from "@shared/db/entity/Violation";
+import { Mute, Violation } from "@shared/db/entity/Violation";
 import { scheduleJob, Job, rescheduleJob } from "node-schedule";
 import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
 
@@ -23,6 +23,8 @@ interface ViolationInfo {
     noAnnounce: boolean;
 }
 
+type TimedViolation = Violation & { endsAt: Date };
+
 @Plugin
 export class ViolationPlugin {
     jobs: Record<number, Job> = {};
@@ -60,7 +62,7 @@ export class ViolationPlugin {
             const muteRoleResolve = await tryDo(member.guild.roles.fetch(muteRoleId));
 
             if (!muteRoleResolve.ok || !muteRoleResolve.result) {
-                logger.warning("mute: couldn't find mute role id %s (removed from server?)", muteRoleId);
+                logger.warn("mute: couldn't find mute role id %s (removed from server?)", muteRoleId);
                 return;
             }
             const muteRole = muteRoleResolve.result;
@@ -86,7 +88,7 @@ export class ViolationPlugin {
         });
 
         if (existingViolation) {
-            logger.warning("%s: trying to reapply on user %s#%s (%s)", command, info.member.user.id, info.member.user.discriminator, info.member.id);
+            logger.warn("%s: trying to reapply on user %s#%s (%s)", command, info.member.user.id, info.member.user.discriminator, info.member.id);
             await violationRepo.update({ id: existingViolation.id } as unknown as FindConditions<T>, { endsAt: info.endDate } as unknown as QueryDeepPartialEntity<T>);
             const job = this.jobs[existingViolation.id];
             rescheduleJob(job, info.endDate);
@@ -116,7 +118,7 @@ export class ViolationPlugin {
             });
 
             if (!violation) {
-                logger.warning("un-%s: no violation found for user ID %s in guild %s", command, userId, guildId);
+                logger.warn("un-%s: no violation found for user ID %s in guild %s", command, userId, guildId);
                 return;
             }
 
@@ -125,13 +127,13 @@ export class ViolationPlugin {
 
             const guild = client.bot.guilds.resolve(guildId);
             if (!guild) {
-                logger.warning("un-%s: couldn't find guild %s", command, guildId);
+                logger.warn("un-%s: couldn't find guild %s", command, guildId);
                 return;
             }
 
             const userResolve = await tryDo(guild.members.fetch(userId));
             if (!userResolve.ok || !userResolve.result) {
-                logger.warning("un-%s: couldn't find user %s (possibly left the server?)", command, userId);
+                logger.warn("un-%s: couldn't find user %s (possibly left the server?)", command, userId);
                 return;
             }
             const user = userResolve.result;
@@ -221,7 +223,7 @@ export class ViolationPlugin {
 
     private async sendViolationMessage(message: Message, info: ViolationInfo, title: string) {
         let announceChannel: TextChannel | null = null;
-        if (info.noAnnounce && message.channel.type == "text") {
+        if ((info.noAnnounce || info.dryRun) && message.channel.type == "text") {
             announceChannel = message.channel;
         }
         else if (info.settings.violationInfoChannelId) {

+ 6 - 5
shared/src/db/entity/Violation.ts

@@ -19,16 +19,17 @@ export abstract class Violation {
     valid: boolean;
 }
 
-export abstract class TimedViolation extends Violation {
+@ChildEntity()
+export class Mute extends Violation {
     @Column()
     endsAt: Date;
 }
 
 @ChildEntity()
-export class Mute extends TimedViolation {}
-
-@ChildEntity()
-export class Ban extends TimedViolation {}
+export class Ban extends Violation {
+    @Column()
+    endsAt: Date;
+}
 
 @ChildEntity()
 export class Kick extends Violation {}