Show message if mute cmd failed to message the muted user

This commit is contained in:
Dragory 2018-07-09 03:00:10 +03:00
parent d938df75cd
commit 736b184646

View file

@ -11,7 +11,8 @@ import * as moment from "moment-timezone";
import { GuildModActions } from "../data/GuildModActions"; import { GuildModActions } from "../data/GuildModActions";
import { import {
convertDelayStringToMS, convertDelayStringToMS,
errorMessage, formatTemplateString, errorMessage,
formatTemplateString,
stripObjectToScalars, stripObjectToScalars,
successMessage successMessage
} from "../utils"; } from "../utils";
@ -315,12 +316,17 @@ export class ModActionsPlugin extends Plugin {
); );
// Message the user informing them of the mute // Message the user informing them of the mute
let messagingFailed = false;
if (args.reason) { if (args.reason) {
const muteMessage = formatTemplateString(this.configValue("mute_message"), { const muteMessage = formatTemplateString(
this.configValue("mute_message"),
{
guildName: this.guild.name, guildName: this.guild.name,
reason: args.reason reason: args.reason
}); }
);
try {
if (this.configValue("dm_on_mute")) { if (this.configValue("dm_on_mute")) {
const dmChannel = await this.bot.getDMChannel(args.member.id); const dmChannel = await this.bot.getDMChannel(args.member.id);
await dmChannel.createMessage(muteMessage); await dmChannel.createMessage(muteMessage);
@ -335,6 +341,9 @@ export class ModActionsPlugin extends Plugin {
) as TextChannel; ) as TextChannel;
await channel.createMessage(`<@!${args.member.id}> ${muteMessage}`); await channel.createMessage(`<@!${args.member.id}> ${muteMessage}`);
} }
} catch (e) {
messagingFailed = true;
}
} }
// Confirm the action to the moderator // Confirm the action to the moderator
@ -342,11 +351,22 @@ export class ModActionsPlugin extends Plugin {
const unmuteTime = moment() const unmuteTime = moment()
.add(muteTime, "ms") .add(muteTime, "ms")
.format("YYYY-MM-DD HH:mm:ss"); .format("YYYY-MM-DD HH:mm:ss");
msg.channel.createMessage( msg.channel.createMessage(
successMessage(`Member muted until ${unmuteTime}`) successMessage(
`Member muted until ${unmuteTime}${
messagingFailed ? " (failed to message user)" : ""
}`
)
); );
} else { } else {
msg.channel.createMessage(successMessage(`Member muted indefinitely`)); msg.channel.createMessage(
successMessage(
`Member muted indefinitely${
messagingFailed ? " (failed to message user)" : ""
}`
)
);
} }
} }