|
@@ -96,7 +96,7 @@ export class ViolationPlugin {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
modify: (member: GuildMember | PartialGuildMember, settings: GuildViolationSettings, violation: DeepPartial<Mute>): DeepPartial<Mute> => {
|
|
modify: (member: GuildMember | PartialGuildMember, settings: GuildViolationSettings, violation: DeepPartial<Mute>): DeepPartial<Mute> => {
|
|
- const originalRoles = member.roles.cache.keyArray().filter(r => r != settings.muteRoleId);
|
|
|
|
|
|
+ const originalRoles = [...member.roles.cache.keys()].filter(r => r != settings.muteRoleId);
|
|
violation.previousRoles = originalRoles;
|
|
violation.previousRoles = originalRoles;
|
|
return violation;
|
|
return violation;
|
|
}
|
|
}
|
|
@@ -214,30 +214,30 @@ export class ViolationPlugin {
|
|
|
|
|
|
private async removeTimedViolation<T extends TimedViolation>(type: ObjectType<T>, message: Message, command = "violation") {
|
|
private async removeTimedViolation<T extends TimedViolation>(type: ObjectType<T>, message: Message, command = "violation") {
|
|
if (!message.guild) {
|
|
if (!message.guild) {
|
|
- await message.reply("cannot do in DMs!");
|
|
|
|
|
|
+ await message.reply({ content: "cannot do in DMs!", failIfNotExists: false });
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
const settingsRepo = getRepository(GuildViolationSettings);
|
|
const settingsRepo = getRepository(GuildViolationSettings);
|
|
const settings = await settingsRepo.findOne(message.guild.id);
|
|
const settings = await settingsRepo.findOne(message.guild.id);
|
|
if (!settings) {
|
|
if (!settings) {
|
|
- message.reply("this guild doesn't have violation settings set up!");
|
|
|
|
|
|
+ message.reply({ content: "this guild doesn't have violation settings set up!", failIfNotExists: false });
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
const [, userId] = parseArgs(message.content);
|
|
const [, userId] = parseArgs(message.content);
|
|
if (!userId) {
|
|
if (!userId) {
|
|
- await message.reply("no user specified!");
|
|
|
|
|
|
+ await message.reply({ content: "no user specified!", failIfNotExists: false });
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
if (userId == message.author.id) {
|
|
if (userId == message.author.id) {
|
|
- await message.reply(`cannot ${command} yourself!`);
|
|
|
|
|
|
+ await message.reply({ content: `cannot ${command} yourself!`, failIfNotExists: false });
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
const user = await this.resolveUser(userId);
|
|
const user = await this.resolveUser(userId);
|
|
if (!user) {
|
|
if (!user) {
|
|
- await message.reply("couldn't find the given user!");
|
|
|
|
|
|
+ await message.reply({ content: "couldn't find the given user!", failIfNotExists: false });
|
|
logger.error("Tried to un-%s user %s but couldn't find them by id!", command, userId);
|
|
logger.error("Tried to un-%s user %s but couldn't find them by id!", command, userId);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -251,7 +251,7 @@ export class ViolationPlugin {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
if (!existingViolation) {
|
|
if (!existingViolation) {
|
|
- await message.reply(`user has no existing active ${command}s in the DB!`);
|
|
|
|
|
|
+ await message.reply({ content: `user has no existing active ${command}s in the DB!`, failIfNotExists: false });
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -260,7 +260,7 @@ export class ViolationPlugin {
|
|
|
|
|
|
const handler = this.getViolationHandler(type);
|
|
const handler = this.getViolationHandler(type);
|
|
await handler.stop(message.guild, user.id, settings, existingViolation);
|
|
await handler.stop(message.guild, user.id, settings, existingViolation);
|
|
- await message.reply(`removed ${command} on user!`);
|
|
|
|
|
|
+ await message.reply({ content: `removed ${command} on user!`, failIfNotExists: false });
|
|
}
|
|
}
|
|
|
|
|
|
private async applyTimedViolation<T extends TimedViolation>(type: ObjectType<T>, info: ViolationInfo, command = "violation", apply: StartViolationFunction, remove: StopViolationFunction, modify?: ModifyViolationFunction) {
|
|
private async applyTimedViolation<T extends TimedViolation>(type: ObjectType<T>, info: ViolationInfo, command = "violation", apply: StartViolationFunction, remove: StopViolationFunction, modify?: ModifyViolationFunction) {
|
|
@@ -355,14 +355,14 @@ export class ViolationPlugin {
|
|
|
|
|
|
private async parseCommand(message: Message, command = "violation"): Promise<Option<ViolationInfo>> {
|
|
private async parseCommand(message: Message, command = "violation"): Promise<Option<ViolationInfo>> {
|
|
if (!message.guild) {
|
|
if (!message.guild) {
|
|
- await message.reply("cannot do in DMs!");
|
|
|
|
|
|
+ await message.reply({ content: "cannot do in DMs!", failIfNotExists: false });
|
|
return { ok: false };
|
|
return { ok: false };
|
|
}
|
|
}
|
|
const violationSettingsRepo = getRepository(GuildViolationSettings);
|
|
const violationSettingsRepo = getRepository(GuildViolationSettings);
|
|
const settings = await violationSettingsRepo.findOne(message.guild.id);
|
|
const settings = await violationSettingsRepo.findOne(message.guild.id);
|
|
|
|
|
|
if (!settings) {
|
|
if (!settings) {
|
|
- await message.reply("sorry, this server doesn't have violation settings set up.");
|
|
|
|
|
|
+ await message.reply({ content: "sorry, this server doesn't have violation settings set up.", failIfNotExists: false });
|
|
logger.error(
|
|
logger.error(
|
|
"%s was called in guild %s (%s) on user %s which doesn't have config set up!",
|
|
"%s was called in guild %s (%s) on user %s which doesn't have config set up!",
|
|
command,
|
|
command,
|
|
@@ -378,37 +378,37 @@ export class ViolationPlugin {
|
|
const noAnnounce = directive.endsWith("!");
|
|
const noAnnounce = directive.endsWith("!");
|
|
|
|
|
|
if (!userId) {
|
|
if (!userId) {
|
|
- await message.reply("no user specified!");
|
|
|
|
|
|
+ await message.reply({ content: "no user specified!", failIfNotExists: false });
|
|
return { ok: false };
|
|
return { ok: false };
|
|
}
|
|
}
|
|
|
|
|
|
const user = await this.resolveUser(userId);
|
|
const user = await this.resolveUser(userId);
|
|
|
|
|
|
if (!user) {
|
|
if (!user) {
|
|
- await message.reply("couldn't find the given user!");
|
|
|
|
|
|
+ await message.reply({ content: "couldn't find the given user!", failIfNotExists: false });
|
|
logger.error("Tried to %s user %s but couldn't find them by id!", command, userId);
|
|
logger.error("Tried to %s user %s but couldn't find them by id!", command, userId);
|
|
return { ok: false };
|
|
return { ok: false };
|
|
}
|
|
}
|
|
|
|
|
|
if (user.id == message.author.id) {
|
|
if (user.id == message.author.id) {
|
|
- await message.reply(`cannot ${command} yourself!`);
|
|
|
|
|
|
+ await message.reply({ content: `cannot ${command} yourself!`, failIfNotExists: false });
|
|
return { ok: false };
|
|
return { ok: false };
|
|
}
|
|
}
|
|
|
|
|
|
if (user.id == client.botUser.id) {
|
|
if (user.id == client.botUser.id) {
|
|
- await message.reply(`cannot apply ${command} on me!`);
|
|
|
|
|
|
+ await message.reply({ content: `cannot apply ${command} on me!`, failIfNotExists: false });
|
|
return { ok: false };
|
|
return { ok: false };
|
|
}
|
|
}
|
|
|
|
|
|
const memberResolve = await tryDo(message.guild.members.fetch(user));
|
|
const memberResolve = await tryDo(message.guild.members.fetch(user));
|
|
if (!memberResolve.ok) {
|
|
if (!memberResolve.ok) {
|
|
- await message.reply("user is not member of the server anymore!");
|
|
|
|
|
|
+ await message.reply({ content: "user is not member of the server anymore!", failIfNotExists: false });
|
|
logger.error("Tried to %s user %s but they are not on the server anymore!", command, userId);
|
|
logger.error("Tried to %s user %s but they are not on the server anymore!", command, userId);
|
|
return { ok: false };
|
|
return { ok: false };
|
|
}
|
|
}
|
|
|
|
|
|
if (await isAuthorisedAsync(memberResolve.result)) {
|
|
if (await isAuthorisedAsync(memberResolve.result)) {
|
|
- await message.reply(`cannot apply ${command} on another moderator!`);
|
|
|
|
|
|
+ await message.reply({ content: `cannot apply ${command} on another moderator!`, failIfNotExists: false });
|
|
return { ok: false };
|
|
return { ok: false };
|
|
}
|
|
}
|
|
|
|
|
|
@@ -441,42 +441,46 @@ export class ViolationPlugin {
|
|
|
|
|
|
private async sendViolationMessage(message: Message, info: ViolationInfo, title: string) {
|
|
private async sendViolationMessage(message: Message, info: ViolationInfo, title: string) {
|
|
let announceChannel: TextChannel | null = null;
|
|
let announceChannel: TextChannel | null = null;
|
|
- if ((info.noAnnounce || info.dryRun) && message.channel.type == "text") {
|
|
|
|
|
|
+ if ((info.noAnnounce || info.dryRun) && message.channel.type == "GUILD_TEXT") {
|
|
announceChannel = message.channel;
|
|
announceChannel = message.channel;
|
|
}
|
|
}
|
|
else if (info.settings.violationInfoChannelId) {
|
|
else if (info.settings.violationInfoChannelId) {
|
|
const ch = info.guild.channels.resolve(info.settings.violationInfoChannelId);
|
|
const ch = info.guild.channels.resolve(info.settings.violationInfoChannelId);
|
|
- if (ch && ch.type == "text")
|
|
|
|
|
|
+ if (ch && ch.type == "GUILD_TEXT")
|
|
announceChannel = ch as TextChannel;
|
|
announceChannel = ch as TextChannel;
|
|
- else if (message.channel.type == "text") {
|
|
|
|
|
|
+ else if (message.channel.type == "GUILD_TEXT") {
|
|
announceChannel = message.channel;
|
|
announceChannel = message.channel;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- await announceChannel?.send(new MessageEmbed({
|
|
|
|
- title: `${info.dryRun ? "[DRY RUN] " : ""}${title}`,
|
|
|
|
- color: 4944347,
|
|
|
|
- timestamp: new Date(),
|
|
|
|
- footer: {
|
|
|
|
- text: client.botUser.username
|
|
|
|
- },
|
|
|
|
- author: {
|
|
|
|
- name: client.botUser.username,
|
|
|
|
- iconURL: client.botUser.avatarURL() ?? undefined
|
|
|
|
- },
|
|
|
|
- fields: [
|
|
|
|
- {
|
|
|
|
- name: "Username",
|
|
|
|
- value: info.member.toString()
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- name: "Duration",
|
|
|
|
- value: humanizeDuration(info.duration, { unitMeasures: UNIT_MEASURES })
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- name: "Reason",
|
|
|
|
- value: info.reason
|
|
|
|
- }
|
|
|
|
|
|
+ await announceChannel?.send({
|
|
|
|
+ embeds: [
|
|
|
|
+ new MessageEmbed({
|
|
|
|
+ title: `${info.dryRun ? "[DRY RUN] " : ""}${title}`,
|
|
|
|
+ color: 4944347,
|
|
|
|
+ timestamp: new Date(),
|
|
|
|
+ footer: {
|
|
|
|
+ text: client.botUser.username
|
|
|
|
+ },
|
|
|
|
+ author: {
|
|
|
|
+ name: client.botUser.username,
|
|
|
|
+ iconURL: client.botUser.avatarURL() ?? undefined
|
|
|
|
+ },
|
|
|
|
+ fields: [
|
|
|
|
+ {
|
|
|
|
+ name: "Username",
|
|
|
|
+ value: info.member.toString()
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ name: "Duration",
|
|
|
|
+ value: humanizeDuration(info.duration, { unitMeasures: UNIT_MEASURES })
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ name: "Reason",
|
|
|
|
+ value: info.reason
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ })
|
|
]
|
|
]
|
|
- }));
|
|
|
|
|
|
+ });
|
|
}
|
|
}
|
|
}
|
|
}
|