fixed issue with kicks/bans being logged twice
This commit is contained in:
parent
2a10d081a0
commit
2931468cee
3 changed files with 38 additions and 30 deletions
|
@ -60,11 +60,6 @@ export default {
|
||||||
let reason = args.join(' ') || 'No reason provided';
|
let reason = args.join(' ') || 'No reason provided';
|
||||||
|
|
||||||
if (banDuration == 0) {
|
if (banDuration == 0) {
|
||||||
message.serverContext.banUser(targetUser._id, {
|
|
||||||
reason: reason + ` (by ${await fetchUsername(message.author_id)} ${message.author_id})`
|
|
||||||
})
|
|
||||||
.catch(e => message.reply(`Failed to ban user: \`${e}\``));
|
|
||||||
|
|
||||||
let infId = ulid();
|
let infId = ulid();
|
||||||
let { userWarnCount } = await storeInfraction({
|
let { userWarnCount } = await storeInfraction({
|
||||||
_id: infId,
|
_id: infId,
|
||||||
|
@ -77,14 +72,14 @@ export default {
|
||||||
actionType: 'ban',
|
actionType: 'ban',
|
||||||
} as Infraction);
|
} as Infraction);
|
||||||
|
|
||||||
message.reply(`### @${targetUser.username} has been banned.\n`
|
|
||||||
+ `Infraction ID: \`${infId}\` (**#${userWarnCount}** for this user)`);
|
|
||||||
} else {
|
|
||||||
message.serverContext.banUser(targetUser._id, {
|
message.serverContext.banUser(targetUser._id, {
|
||||||
reason: reason + ` (by ${await fetchUsername(message.author_id)} ${message.author_id}) (${durationStr})`
|
reason: reason + ` (by ${await fetchUsername(message.author_id)} ${message.author_id})`
|
||||||
})
|
})
|
||||||
.catch(e => message.reply(`Failed to ban user: \`${e}\``));
|
.catch(e => message.reply(`Failed to ban user: \`${e}\``));
|
||||||
|
|
||||||
|
message.reply(`### @${targetUser.username} has been banned.\n`
|
||||||
|
+ `Infraction ID: \`${infId}\` (**#${userWarnCount}** for this user)`);
|
||||||
|
} else {
|
||||||
let banUntil = Date.now() + banDuration;
|
let banUntil = Date.now() + banDuration;
|
||||||
let infId = ulid();
|
let infId = ulid();
|
||||||
let { userWarnCount } = await storeInfraction({
|
let { userWarnCount } = await storeInfraction({
|
||||||
|
@ -98,6 +93,11 @@ export default {
|
||||||
actionType: 'ban',
|
actionType: 'ban',
|
||||||
} as Infraction);
|
} as Infraction);
|
||||||
|
|
||||||
|
message.serverContext.banUser(targetUser._id, {
|
||||||
|
reason: reason + ` (by ${await fetchUsername(message.author_id)} ${message.author_id}) (${durationStr})`
|
||||||
|
})
|
||||||
|
.catch(e => message.reply(`Failed to ban user: \`${e}\``));
|
||||||
|
|
||||||
await storeTempBan({
|
await storeTempBan({
|
||||||
id: infId,
|
id: infId,
|
||||||
bannedUser: targetUser._id,
|
bannedUser: targetUser._id,
|
||||||
|
|
|
@ -40,12 +40,6 @@ export default {
|
||||||
return message.reply(`Failed to fetch member: \`${e}\``);
|
return message.reply(`Failed to fetch member: \`${e}\``);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
await targetMember.kick();
|
|
||||||
} catch(e) {
|
|
||||||
return message.reply(`Failed to kick user: \`${e}\``);
|
|
||||||
}
|
|
||||||
|
|
||||||
let infId = ulid();
|
let infId = ulid();
|
||||||
let { userWarnCount } = await storeInfraction({
|
let { userWarnCount } = await storeInfraction({
|
||||||
_id: infId,
|
_id: infId,
|
||||||
|
@ -58,6 +52,12 @@ export default {
|
||||||
actionType: 'kick',
|
actionType: 'kick',
|
||||||
} as Infraction);
|
} as Infraction);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await targetMember.kick();
|
||||||
|
} catch(e) {
|
||||||
|
return message.reply(`Failed to kick user: \`${e}\``);
|
||||||
|
}
|
||||||
|
|
||||||
message.reply(`### @${targetUser.username} has been ${Math.random() > 0.8 ? 'ejected' : 'kicked'}.\n`
|
message.reply(`### @${targetUser.username} has been ${Math.random() > 0.8 ? 'ejected' : 'kicked'}.\n`
|
||||||
+ `Infraction ID: \`${infId}\` (**#${userWarnCount}** for this user)`);
|
+ `Infraction ID: \`${infId}\` (**#${userWarnCount}** for this user)`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import InfractionType from "../../struct/antispam/InfractionType";
|
||||||
import { storeInfraction } from "../util";
|
import { storeInfraction } from "../util";
|
||||||
|
|
||||||
// Listen to system messages
|
// Listen to system messages
|
||||||
client.on('message', message => {
|
client.on('message', async message => {
|
||||||
if (typeof message.content != 'object') return;
|
if (typeof message.content != 'object') return;
|
||||||
|
|
||||||
let sysMsg = message.asSystemMessage;
|
let sysMsg = message.asSystemMessage;
|
||||||
|
@ -13,10 +13,17 @@ client.on('message', message => {
|
||||||
switch(sysMsg.type) {
|
switch(sysMsg.type) {
|
||||||
case 'user_kicked':
|
case 'user_kicked':
|
||||||
case 'user_banned':
|
case 'user_banned':
|
||||||
if (message.channel &&
|
try {
|
||||||
sysMsg.user &&
|
let recentEvents = await client.db.get('infractions').findOne({
|
||||||
sysMsg.by &&
|
date: { $gt: Date.now() - 30000 },
|
||||||
sysMsg.by._id != client.user?._id) return;
|
user: sysMsg.user?._id,
|
||||||
|
server: message.channel?.server_id,
|
||||||
|
actionType: sysMsg.type == 'user_kicked' ? 'kick' : 'ban',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!message.channel ||
|
||||||
|
!sysMsg.user ||
|
||||||
|
recentEvents) return;
|
||||||
|
|
||||||
storeInfraction({
|
storeInfraction({
|
||||||
_id: ulid(),
|
_id: ulid(),
|
||||||
|
@ -28,6 +35,7 @@ client.on('message', message => {
|
||||||
user: sysMsg.user!._id,
|
user: sysMsg.user!._id,
|
||||||
actionType: sysMsg.type == 'user_kicked' ? 'kick' : 'ban',
|
actionType: sysMsg.type == 'user_kicked' ? 'kick' : 'ban',
|
||||||
} as Infraction).catch(console.warn);
|
} as Infraction).catch(console.warn);
|
||||||
|
} catch(e) { console.error(e) }
|
||||||
break;
|
break;
|
||||||
case 'user_joined': break;
|
case 'user_joined': break;
|
||||||
case 'user_left' : break;
|
case 'user_left' : break;
|
||||||
|
|
Loading…
Reference in a new issue