ModActions: make the text that tells how the user was notified more descriptive

This commit is contained in:
Dragory 2019-03-07 22:09:14 +02:00
parent a9cb6fe5d3
commit 18f16f6bad

View file

@ -35,18 +35,17 @@ interface IIgnoredEvent {
userId: string; userId: string;
} }
enum MessageResult { enum MessageResultStatus {
Ignored = 1, Ignored = 1,
Failed, Failed,
DirectMessaged, DirectMessaged,
ChannelMessaged, ChannelMessaged,
} }
const MessageResultText = { interface IMessageResult {
[MessageResult.Failed]: "failed to message user", status: MessageResultStatus;
[MessageResult.DirectMessaged]: "user messaged in DMs", text?: string;
[MessageResult.ChannelMessaged]: "user messaged with a ping", }
};
interface IModActionsPluginConfig { interface IModActionsPluginConfig {
dm_on_warn: boolean; dm_on_warn: boolean;
@ -399,7 +398,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
config.message_on_warn, config.message_on_warn,
); );
if (userMessageResult === MessageResult.Failed) { if (userMessageResult.status === MessageResultStatus.Failed) {
const failedMsg = await msg.channel.createMessage("Failed to message the user. Log the warning anyway?"); const failedMsg = await msg.channel.createMessage("Failed to message the user. Log the warning anyway?");
const reply = await waitForReaction(this.bot, failedMsg, ["✅", "❌"], msg.author.id); const reply = await waitForReaction(this.bot, failedMsg, ["✅", "❌"], msg.author.id);
failedMsg.delete(); failedMsg.delete();
@ -416,8 +415,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
ppId: mod.id !== msg.author.id ? msg.author.id : null, ppId: mod.id !== msg.author.id ? msg.author.id : null,
}); });
let messageResultText = MessageResultText[userMessageResult]; const messageResultText = userMessageResult.text ? ` (${userMessageResult.text})` : "";
if (messageResultText) messageResultText = ` (${messageResultText})`;
msg.channel.createMessage( msg.channel.createMessage(
successMessage( successMessage(
@ -455,7 +453,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
mod = args.mod; mod = args.mod;
} }
let userMessageResult: MessageResult = MessageResult.Ignored; let userMessageResult: IMessageResult = { status: MessageResultStatus.Ignored };
// Convert mute time from e.g. "2h30m" to milliseconds // Convert mute time from e.g. "2h30m" to milliseconds
const muteTime = args.time ? convertDelayStringToMS(args.time) : null; const muteTime = args.time ? convertDelayStringToMS(args.time) : null;
@ -540,8 +538,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
})`; })`;
} }
const messageResultText = MessageResultText[userMessageResult]; if (userMessageResult.text) response += ` (${userMessageResult.text})`;
if (messageResultText) response += ` (${messageResultText})`;
msg.channel.createMessage(successMessage(response)); msg.channel.createMessage(successMessage(response));
// Log the action // Log the action
@ -675,7 +672,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
const reason = this.formatReasonWithAttachments(args.reason, msg.attachments); const reason = this.formatReasonWithAttachments(args.reason, msg.attachments);
// Attempt to message the user *before* kicking them, as doing it after may not be possible // Attempt to message the user *before* kicking them, as doing it after may not be possible
let userMessageResult: MessageResult = MessageResult.Ignored; let userMessageResult: IMessageResult = { status: MessageResultStatus.Ignored };
if (args.reason) { if (args.reason) {
const kickMessage = formatTemplateString(config.kick_message, { const kickMessage = formatTemplateString(config.kick_message, {
guildName: this.guild.name, guildName: this.guild.name,
@ -708,8 +705,8 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
let response = `Kicked **${args.member.user.username}#${args.member.user.discriminator}** (Case #${ let response = `Kicked **${args.member.user.username}#${args.member.user.discriminator}** (Case #${
createdCase.case_number createdCase.case_number
})`; })`;
const messageResultText = MessageResultText[userMessageResult];
if (messageResultText) response += ` (${messageResultText})`; if (userMessageResult.text) response += ` (${userMessageResult.text})`;
msg.channel.createMessage(successMessage(response)); msg.channel.createMessage(successMessage(response));
// Log the action // Log the action
@ -745,7 +742,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
const reason = this.formatReasonWithAttachments(args.reason, msg.attachments); const reason = this.formatReasonWithAttachments(args.reason, msg.attachments);
// Attempt to message the user *before* banning them, as doing it after may not be possible // Attempt to message the user *before* banning them, as doing it after may not be possible
let userMessageResult: MessageResult = MessageResult.Ignored; let userMessageResult: IMessageResult = { status: MessageResultStatus.Ignored };
if (reason) { if (reason) {
const banMessage = formatTemplateString(config.ban_message, { const banMessage = formatTemplateString(config.ban_message, {
guildName: this.guild.name, guildName: this.guild.name,
@ -778,8 +775,8 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
let response = `Banned **${args.member.user.username}#${args.member.user.discriminator}** (Case #${ let response = `Banned **${args.member.user.username}#${args.member.user.discriminator}** (Case #${
createdCase.case_number createdCase.case_number
})`; })`;
const messageResultText = MessageResultText[userMessageResult];
if (messageResultText) response += ` (${messageResultText})`; if (userMessageResult.text) response += ` (${userMessageResult.text})`;
msg.channel.createMessage(successMessage(response)); msg.channel.createMessage(successMessage(response));
// Log the action // Log the action
@ -1239,16 +1236,19 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
str: string, str: string,
useDM: boolean, useDM: boolean,
useChannel: boolean, useChannel: boolean,
): Promise<MessageResult> { ): Promise<IMessageResult> {
if (!useDM && !useChannel) { if (!useDM && !useChannel) {
return MessageResult.Ignored; return { status: MessageResultStatus.Ignored };
} }
if (useDM) { if (useDM) {
try { try {
const dmChannel = await this.bot.getDMChannel(user.id); const dmChannel = await this.bot.getDMChannel(user.id);
await dmChannel.createMessage(str); await dmChannel.createMessage(str);
return MessageResult.DirectMessaged; return {
status: MessageResultStatus.DirectMessaged,
text: "user notified with a direct message",
};
} catch (e) {} // tslint:disable-line } catch (e) {} // tslint:disable-line
} }
@ -1258,10 +1258,16 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig, IM
try { try {
const channel = this.guild.channels.get(messageChannel) as TextChannel; const channel = this.guild.channels.get(messageChannel) as TextChannel;
await channel.createMessage(`<@!${user.id}> ${str}`); await channel.createMessage(`<@!${user.id}> ${str}`);
return MessageResult.ChannelMessaged; return {
status: MessageResultStatus.ChannelMessaged,
text: `user notified in <#${channel.id}>`,
};
} catch (e) {} // tslint:disable-line } catch (e) {} // tslint:disable-line
} }
return MessageResult.Failed; return {
status: MessageResultStatus.Failed,
text: "failed to message user",
};
} }
} }