This commit is contained in:
JandereDev 2021-10-14 14:02:13 +02:00
parent ca132071d9
commit e78120afea
Signed by: Lea
GPG key ID: 5D5E18ACB990F57A
4 changed files with 41 additions and 11 deletions

View file

@ -4,6 +4,7 @@ import { isModerator, NO_MANAGER_MSG, parseUser, storeInfraction } from "../util
import Infraction from "../../struct/antispam/Infraction"; import Infraction from "../../struct/antispam/Infraction";
import { ulid } from "ulid"; import { ulid } from "ulid";
import InfractionType from "../../struct/antispam/InfractionType"; import InfractionType from "../../struct/antispam/InfractionType";
import { logModAction } from "../modules/mod_logs";
export default { export default {
name: 'warn', name: 'warn',
@ -34,10 +35,13 @@ export default {
let { userWarnCount } = await storeInfraction(infraction); let { userWarnCount } = await storeInfraction(infraction);
await message.reply(`## User warned.\n` await Promise.all([
message.reply(`## User warned.\n`
+ `This is ${userWarnCount == 1 ? '**the first warn**' : `warn number **${userWarnCount}**`}` + `This is ${userWarnCount == 1 ? '**the first warn**' : `warn number **${userWarnCount}**`}`
+ ` for ${user.username ?? 'this user'}.\n` + ` for ${user.username ?? 'this user'}.\n`
+ `**Infraction ID:** \`${infraction._id}\`\n` + `**Infraction ID:** \`${infraction._id}\`\n`
+ `**Reason:** \`${infraction.reason}\``); + `**Reason:** \`${infraction.reason}\``),
logModAction('warn', message.member!, user, reason, `This is warn number **${userWarnCount}** for this user.`),
]);
} }
} as Command; } as Command;

View file

@ -9,6 +9,7 @@ import RelativeTime from 'dayjs/plugin/relativeTime';
import Xlsx from 'xlsx'; import Xlsx from 'xlsx';
import FormData from 'form-data'; import FormData from 'form-data';
import axios from "axios"; import axios from "axios";
import { fetchUsername } from "../modules/mod_logs";
Day.extend(RelativeTime); Day.extend(RelativeTime);
@ -122,10 +123,3 @@ export default {
} }
} }
} as Command; } as Command;
let fetchUsername = async (id: string) => {
try {
let u = await client.users.fetch(id);
return `@${u.username}`;
} catch(e) { return 'Unknown user' }
}

View file

@ -1,3 +1,5 @@
import { Member } from "revolt.js/dist/maps/Members";
import { User } from "revolt.js/dist/maps/Users";
import { client } from "../.."; import { client } from "../..";
import ServerConfig from "../../struct/ServerConfig"; import ServerConfig from "../../struct/ServerConfig";
import logger from "../logger"; import logger from "../logger";
@ -111,3 +113,34 @@ client.on('packet', async (packet) => {
} }
} }
}); });
async function logModAction(type: 'warn'|'kick'|'ban', mod: Member, target: User, reason: string|null, extraText?: string|null): Promise<void> {
try {
let config: ServerConfig = await client.db.get('servers').findOne({ id: mod.server?._id }) ?? {};
let logChannelID = config.logs?.modAction;
if (!logChannelID) return;
let logChannel = client.channels.get(logChannelID);
let aType = type == 'ban' ? 'banned' : type + 'ed';
let msg = `User ${aType}\n`
+ `\`@${mod.user?.username}\` **${aType}** \`@`
+ `${target.username}\`${type == 'warn' ? '.' : ` from ${mod.server?.name}.`}\n`
+ `**Reason**: \`${reason ? reason : 'No reason provided.'}\`\n`
+ (extraText ?? '');
logChannel?.sendMessage(msg)
.catch(() => logger.warn('Failed to send log message'));
} catch(e) {
console.error(e);
}
}
let fetchUsername = async (id: string) => {
try {
let u = await client.users.fetch(id);
return `@${u.username}`;
} catch(e) { return 'Unknown user' }
}
export { fetchUsername, logModAction }

View file

@ -13,10 +13,9 @@ class ServerConfig {
managers: boolean | undefined, managers: boolean | undefined,
} | undefined; } | undefined;
logs: { logs: {
infractions: string | undefined, // User warned
automod: string | undefined, // automod rule triggered automod: string | undefined, // automod rule triggered
messageUpdate: string | undefined, // Message edited or deleted messageUpdate: string | undefined, // Message edited or deleted
modAction: string | undefined, // User kicked, banned, or roles updated modAction: string | undefined, // User warned, kicked or banned
userUpdate: string | undefined, // Username/nickname/avatar changes userUpdate: string | undefined, // Username/nickname/avatar changes
} | undefined; } | undefined;
} }