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