3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

warn cmd: add logging; add verification if messaging fails. action log: do not auto-post automatic actions if set so in config

This commit is contained in:
Dragory 2018-07-09 02:51:34 +03:00
parent 74f643487c
commit 82daf87fbf

View file

@ -1,4 +1,4 @@
import { Plugin, decorators as d } from "knub"; import { Plugin, decorators as d, waitForReaction } from "knub";
import { import {
Guild, Guild,
GuildAuditLogEntry, GuildAuditLogEntry,
@ -9,11 +9,18 @@ import {
} from "eris"; } from "eris";
import * as moment from "moment-timezone"; import * as moment from "moment-timezone";
import { GuildModActions } from "../data/GuildModActions"; import { GuildModActions } from "../data/GuildModActions";
import { convertDelayStringToMS, errorMessage, successMessage } from "../utils"; import {
convertDelayStringToMS,
errorMessage,
stripObjectToScalars,
successMessage
} from "../utils";
import { GuildMutes } from "../data/GuildMutes"; import { GuildMutes } from "../data/GuildMutes";
import Timer = NodeJS.Timer; import Timer = NodeJS.Timer;
import ModAction from "../models/ModAction"; import ModAction from "../models/ModAction";
import { ModActionType } from "../data/ModActionType"; import { ModActionType } from "../data/ModActionType";
import { GuildServerLogs } from "../data/GuildServerLogs";
import { LogType } from "../data/LogType";
const sleep = (ms: number): Promise<void> => { const sleep = (ms: number): Promise<void> => {
return new Promise(resolve => { return new Promise(resolve => {
@ -24,11 +31,14 @@ const sleep = (ms: number): Promise<void> => {
export class ModActionsPlugin extends Plugin { export class ModActionsPlugin extends Plugin {
protected modActions: GuildModActions; protected modActions: GuildModActions;
protected mutes: GuildMutes; protected mutes: GuildMutes;
protected serverLogs: GuildServerLogs;
protected muteClearIntervalId: Timer; protected muteClearIntervalId: Timer;
async onLoad() { async onLoad() {
this.modActions = new GuildModActions(this.guildId); this.modActions = new GuildModActions(this.guildId);
this.mutes = new GuildMutes(this.guildId); this.mutes = new GuildMutes(this.guildId);
this.serverLogs = new GuildServerLogs(this.guildId);
// Check for expired mutes every 5s // Check for expired mutes every 5s
this.clearExpiredMutes(); this.clearExpiredMutes();
@ -114,7 +124,8 @@ export class ModActionsPlugin extends Plugin {
modId, modId,
ModActionType.Ban, ModActionType.Ban,
auditLogId, auditLogId,
relevantAuditLogEntry.reason relevantAuditLogEntry.reason,
true
); );
} else { } else {
await this.createModAction(user.id, null, ModActionType.Ban); await this.createModAction(user.id, null, ModActionType.Ban);
@ -140,7 +151,9 @@ export class ModActionsPlugin extends Plugin {
user.id, user.id,
modId, modId,
ModActionType.Unban, ModActionType.Unban,
auditLogId auditLogId,
null,
true
); );
} else { } else {
await this.createModAction(user.id, null, ModActionType.Unban); await this.createModAction(user.id, null, ModActionType.Unban);
@ -212,17 +225,34 @@ export class ModActionsPlugin extends Plugin {
.replace("{guildName}", this.guild.name) .replace("{guildName}", this.guild.name)
.replace("{reason}", args.reason); .replace("{reason}", args.reason);
if (this.configValue("dm_on_warn")) { let failedToMessage = false;
const dmChannel = await this.bot.getDMChannel(args.member.id);
await dmChannel.createMessage(warnMessage); try {
if (this.configValue("dm_on_warn")) {
const dmChannel = await this.bot.getDMChannel(args.member.id);
await dmChannel.createMessage(warnMessage);
}
if (this.configValue("message_on_warn")) {
const channel = this.guild.channels.get(
this.configValue("message_channel")
) as TextChannel;
if (channel) {
await channel.createMessage(`<@!${args.member.id}> ${warnMessage}`);
}
}
} catch (e) {
failedToMessage = true;
} }
if (this.configValue("message_on_warn")) { if (failedToMessage) {
const channel = this.guild.channels.get( const failedMsg = await msg.channel.createMessage(
this.configValue("message_channel") "Failed to message the user. Log the warning anyway?"
) as TextChannel; );
if (channel) { const reply = await waitForReaction(this.bot, failedMsg, ["✅", "❌"]);
await channel.createMessage(`<@!${args.member.id}> ${warnMessage}`); failedMsg.delete();
if (!reply || reply.name === "❌") {
return;
} }
} }
@ -235,6 +265,11 @@ export class ModActionsPlugin extends Plugin {
); );
msg.channel.createMessage(successMessage("Member warned")); msg.channel.createMessage(successMessage("Member warned"));
this.serverLogs.log(LogType.MEMBER_WARN, {
mod: stripObjectToScalars(msg.member, ["user"]),
member: stripObjectToScalars(args.member, ["user"])
});
} }
@d.command("mute", "<member:Member> [time:string] [reason:string$]") @d.command("mute", "<member:Member> [time:string] [reason:string$]")
@ -468,7 +503,8 @@ export class ModActionsPlugin extends Plugin {
modId: string, modId: string,
actionType: ModActionType, actionType: ModActionType,
auditLogId: string = null, auditLogId: string = null,
reason: string = null reason: string = null,
automatic = false
): Promise<number> { ): Promise<number> {
const user = this.bot.users.get(userId); const user = this.bot.users.get(userId);
const userName = user const userName = user
@ -493,7 +529,10 @@ export class ModActionsPlugin extends Plugin {
await this.createModActionNote(createdId, modId, reason); await this.createModActionNote(createdId, modId, reason);
} }
if (this.configValue("action_log_channel")) { if (
this.configValue("action_log_channel") &&
(!automatic || this.configValue("log_automatic_actions"))
) {
try { try {
await this.postModActionToActionLog(createdId); await this.postModActionToActionLog(createdId);
} catch (e) {} // tslint:disable-line } catch (e) {} // tslint:disable-line