diff --git a/src/bot/commands/warn.ts b/src/bot/commands/warn.ts index 633ed85..05328de 100644 --- a/src/bot/commands/warn.ts +++ b/src/bot/commands/warn.ts @@ -4,6 +4,7 @@ import { isModerator, NO_MANAGER_MSG, parseUser, storeInfraction } from "../util import Infraction from "../../struct/antispam/Infraction"; import { ulid } from "ulid"; import InfractionType from "../../struct/antispam/InfractionType"; +import { logModAction } from "../modules/mod_logs"; export default { name: 'warn', @@ -34,10 +35,13 @@ export default { 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}**`}` + ` for ${user.username ?? 'this user'}.\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; diff --git a/src/bot/commands/warns.ts b/src/bot/commands/warns.ts index 09989bb..6edb94d 100644 --- a/src/bot/commands/warns.ts +++ b/src/bot/commands/warns.ts @@ -9,6 +9,7 @@ import RelativeTime from 'dayjs/plugin/relativeTime'; import Xlsx from 'xlsx'; import FormData from 'form-data'; import axios from "axios"; +import { fetchUsername } from "../modules/mod_logs"; Day.extend(RelativeTime); @@ -122,10 +123,3 @@ export default { } } } as Command; - -let fetchUsername = async (id: string) => { - try { - let u = await client.users.fetch(id); - return `@${u.username}`; - } catch(e) { return 'Unknown user' } -} diff --git a/src/bot/modules/mod_logs.ts b/src/bot/modules/mod_logs.ts index 0238d56..36c6fa4 100644 --- a/src/bot/modules/mod_logs.ts +++ b/src/bot/modules/mod_logs.ts @@ -1,3 +1,5 @@ +import { Member } from "revolt.js/dist/maps/Members"; +import { User } from "revolt.js/dist/maps/Users"; import { client } from "../.."; import ServerConfig from "../../struct/ServerConfig"; 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 { + 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 } diff --git a/src/struct/ServerConfig.ts b/src/struct/ServerConfig.ts index d05713f..568cdd5 100644 --- a/src/struct/ServerConfig.ts +++ b/src/struct/ServerConfig.ts @@ -13,10 +13,9 @@ class ServerConfig { managers: boolean | undefined, } | undefined; logs: { - infractions: string | undefined, // User warned automod: string | undefined, // automod rule triggered 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 } | undefined; }