mirror of
https://github.com/janderedev/automod.git
synced 2024-12-22 10:45:27 +00:00
*h*
This commit is contained in:
parent
ca132071d9
commit
e78120afea
|
@ -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;
|
||||
|
|
|
@ -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' }
|
||||
}
|
||||
|
|
|
@ -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<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 }
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue