Skip to content

Commit

Permalink
DM user before issuing ban
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Aug 9, 2023
1 parent 702c68f commit 3c4b3c9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/components/moderation/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ export default class Ban extends ModerationComponent {
removed: null,
expunged: null,
};
await this.notify_user(command, user, "banned", moderation);
await this.register_new_moderation(moderation);
await this.notify(command, user, "banned", moderation);
await this.reply_with_success(command, user, "banned");
} catch (e) {
await this.reply_with_error(command, "Error banning");
critical_error(e);
Expand Down Expand Up @@ -143,7 +144,7 @@ export default class Ban extends ModerationComponent {
} else {
await this.remove_moderation(res.value);
this.sleep_list.remove(res.value._id);
await this.notify(command, user, "unbanned", res.value, true);
await this.reply_with_success(command, user, "unbanned");
}
} catch (e) {
await this.reply_with_error(command, "Error unbanning");
Expand Down
2 changes: 1 addition & 1 deletion src/components/moderation/kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class Kick extends ModerationComponent {
expunged: null,
};
await this.register_new_moderation(moderation);
await this.notify(command, user, "kicked", moderation);
await this.reply_and_notify(command, user, "kicked", moderation);
} catch (e) {
await this.reply_with_error(command, "Error kicking");
critical_error(e);
Expand Down
28 changes: 21 additions & 7 deletions src/components/moderation/moderation-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,23 @@ export abstract class ModerationComponent extends BotComponent {
}
}

async notify(
command: TextBasedCommand,
user: Discord.User,
action: string,
moderation: Omit<moderation_entry, "case">,
is_removal = false,
) {
async reply_with_success(command: TextBasedCommand, user: Discord.User, action: string) {
await command.reply({
embeds: [
new Discord.EmbedBuilder()
.setColor(colors.color)
.setDescription(`<:success:1138616548630745088> ***${user.displayName} was ${action}***`),
],
});
}

async notify_user(
command: TextBasedCommand,
user: Discord.User,
action: string,
moderation: Omit<moderation_entry, "case">,
is_removal = false,
) {
const duration = moderation.duration ? time_to_human(moderation.duration) : "Permanent";
try {
await (
Expand All @@ -288,4 +291,15 @@ export abstract class ModerationComponent extends BotComponent {
critical_error(e);
}
}

async reply_and_notify(
command: TextBasedCommand,
user: Discord.User,
action: string,
moderation: Omit<moderation_entry, "case">,
is_removal = false,
) {
await this.reply_with_success(command, user, action);
await this.notify_user(command, user, action, moderation, is_removal);
}
}
4 changes: 2 additions & 2 deletions src/components/moderation/mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default class Mute extends ModerationComponent {
expunged: null,
};
await this.register_new_moderation(moderation);
await this.notify(command, user, "muted", moderation);
await this.reply_and_notify(command, user, "muted", moderation);
} catch (e) {
await this.reply_with_error(command, "Error applying mute");
critical_error(e);
Expand Down Expand Up @@ -135,7 +135,7 @@ export default class Mute extends ModerationComponent {
} else {
await this.remove_moderation(res.value);
this.sleep_list.remove(res.value._id);
await this.notify(command, user, "unmuted", res.value, true);
await this.reply_and_notify(command, user, "unmuted", res.value, true);
}
} catch (e) {
await this.reply_with_error(command, "Error unmuting");
Expand Down

0 comments on commit 3c4b3c9

Please sign in to comment.