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

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