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 { GuildModActions } from "../data/GuildModActions";
import { import {
convertDelayStringToMS, convertDelayStringToMS,
errorMessage, formatTemplateString, errorMessage,
formatTemplateString,
stripObjectToScalars, stripObjectToScalars,
successMessage successMessage
} from "../utils"; } from "../utils";
@ -315,25 +316,33 @@ 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(
guildName: this.guild.name, this.configValue("mute_message"),
reason: args.reason {
}); guildName: this.guild.name,
reason: args.reason
}
);
if (this.configValue("dm_on_mute")) { try {
const dmChannel = await this.bot.getDMChannel(args.member.id); if (this.configValue("dm_on_mute")) {
await dmChannel.createMessage(muteMessage); const dmChannel = await this.bot.getDMChannel(args.member.id);
} await dmChannel.createMessage(muteMessage);
}
if ( if (
this.configValue("message_on_mute") && this.configValue("message_on_mute") &&
this.configValue("message_channel")
) {
const channel = this.guild.channels.get(
this.configValue("message_channel") this.configValue("message_channel")
) as TextChannel; ) {
await channel.createMessage(`<@!${args.member.id}> ${muteMessage}`); const channel = this.guild.channels.get(
this.configValue("message_channel")
) as TextChannel;
await channel.createMessage(`<@!${args.member.id}> ${muteMessage}`);
}
} catch (e) {
messagingFailed = true;
} }
} }
@ -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)" : ""
}`
)
);
} }
} }