mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Merge branch 'mute-update-message' of git://github.com/roflmaoqwerty/ZeppelinBot into roflmaoqwerty-mute-update-message
This commit is contained in:
commit
8245386f42
1 changed files with 35 additions and 25 deletions
|
@ -33,10 +33,13 @@ const ConfigSchema = t.type({
|
|||
move_to_voice_channel: tNullable(t.string),
|
||||
|
||||
dm_on_mute: t.boolean,
|
||||
dm_on_update: t.boolean,
|
||||
message_on_mute: t.boolean,
|
||||
message_on_update: t.boolean,
|
||||
message_channel: tNullable(t.string),
|
||||
mute_message: tNullable(t.string),
|
||||
timed_mute_message: tNullable(t.string),
|
||||
update_mute_message: tNullable(t.string),
|
||||
|
||||
can_view_list: t.boolean,
|
||||
can_cleanup: t.boolean,
|
||||
|
@ -82,10 +85,13 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
move_to_voice_channel: null,
|
||||
|
||||
dm_on_mute: false,
|
||||
dm_on_update: false,
|
||||
message_on_mute: false,
|
||||
message_on_update: false,
|
||||
message_channel: null,
|
||||
mute_message: "You have been muted on the {guildName} server. Reason given: {reason}",
|
||||
timed_mute_message: "You have been muted on the {guildName} server for {time}. Reason given: {reason}",
|
||||
update_mute_message: "Your mute on the {guildName} server has been updated to {time}.",
|
||||
|
||||
can_view_list: false,
|
||||
can_cleanup: false,
|
||||
|
@ -135,7 +141,7 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
const muteRole = this.getConfig().mute_role;
|
||||
if (!muteRole) return;
|
||||
|
||||
const timeUntilUnmute = muteTime && humanizeDuration(muteTime);
|
||||
const timeUntilUnmute = muteTime ? muteTime && humanizeDuration(muteTime) : "indefinite";
|
||||
|
||||
// No mod specified -> mark Zeppelin as the mod
|
||||
if (!caseArgs.modId) {
|
||||
|
@ -144,6 +150,7 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
|
||||
const user = await this.resolveUser(userId);
|
||||
const member = await this.getMember(user.id, true); // Grab the fresh member so we don't have stale role info
|
||||
const config = this.getMatchingConfig({ member, userId });
|
||||
|
||||
if (member) {
|
||||
// Apply mute role if it's missing
|
||||
|
@ -169,32 +176,35 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
await this.mutes.updateExpiryTime(user.id, muteTime);
|
||||
} else {
|
||||
await this.mutes.addMute(user.id, muteTime);
|
||||
|
||||
// If it's a new mute, attempt to message the user
|
||||
const config = this.getMatchingConfig({ member, userId });
|
||||
const template = muteTime ? config.timed_mute_message : config.mute_message;
|
||||
|
||||
const muteMessage =
|
||||
template &&
|
||||
(await renderTemplate(template, {
|
||||
guildName: this.guild.name,
|
||||
reason,
|
||||
time: timeUntilUnmute,
|
||||
}));
|
||||
|
||||
if (reason && muteMessage) {
|
||||
if (user instanceof User) {
|
||||
notifyResult = await notifyUser(this.bot, this.guild, user, muteMessage, {
|
||||
useDM: config.dm_on_mute,
|
||||
useChannel: config.message_on_mute,
|
||||
channelId: config.message_channel,
|
||||
});
|
||||
} else {
|
||||
notifyResult = { status: NotifyUserStatus.Failed };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const template = existingMute
|
||||
? config.update_mute_message
|
||||
: muteTime
|
||||
? config.timed_mute_message
|
||||
: config.mute_message;
|
||||
|
||||
const muteMessage =
|
||||
template &&
|
||||
(await renderTemplate(template, {
|
||||
guildName: this.guild.name,
|
||||
reason: reason || reason === "" ? "None" : reason,
|
||||
time: timeUntilUnmute,
|
||||
}));
|
||||
|
||||
if (muteMessage) {
|
||||
const useDm = existingMute ? config.dm_on_update : config.dm_on_mute;
|
||||
const useChannel = existingMute ? config.message_on_update : config.message_on_mute;
|
||||
if (user instanceof User) {
|
||||
notifyResult = await notifyUser(this.bot, this.guild, user, muteMessage, {
|
||||
useDM: useDm,
|
||||
useChannel,
|
||||
channelId: config.message_channel,
|
||||
});
|
||||
} else {
|
||||
notifyResult = { status: NotifyUserStatus.Failed };
|
||||
}
|
||||
}
|
||||
// Create/update a case
|
||||
const casesPlugin = this.getPlugin<CasesPlugin>("cases");
|
||||
let theCase;
|
||||
|
|
Loading…
Add table
Reference in a new issue