fixed mod logs

This commit is contained in:
JandereDev 2021-12-20 10:44:17 +01:00
parent 81b791af86
commit f9fff4d4f1
Signed by: Lea
GPG key ID: 5D5E18ACB990F57A

View file

@ -1,4 +1,5 @@
import { Member } from "@janderedev/revolt.js/dist/maps/Members"; import { Member } from "@janderedev/revolt.js/dist/maps/Members";
import { Server } from "@janderedev/revolt.js/dist/maps/Servers";
import { User } from "@janderedev/revolt.js/dist/maps/Users"; import { User } from "@janderedev/revolt.js/dist/maps/Users";
import { client } from "../.."; import { client } from "../..";
import ServerConfig from "../../struct/ServerConfig"; import ServerConfig from "../../struct/ServerConfig";
@ -114,9 +115,9 @@ client.on('packet', async (packet) => {
} }
}); });
async function logModAction(type: 'warn'|'kick'|'ban', mod: Member, target: User, reason: string|null, extraText?: string|null): Promise<void> { async function logModAction(type: 'warn'|'kick'|'ban', server: Server, mod: Member, target: User, reason: string|null, extraText?: string|null): Promise<void> {
try { try {
let config: ServerConfig = await client.db.get('servers').findOne({ id: mod.server?._id }) ?? {}; let config: ServerConfig = await client.db.get('servers').findOne({ id: server._id }) ?? {};
let logChannelID = config.logs?.modAction; let logChannelID = config.logs?.modAction;
if (!logChannelID) return; if (!logChannelID) return;
let logChannel = client.channels.get(logChannelID); let logChannel = client.channels.get(logChannelID);
@ -124,7 +125,7 @@ async function logModAction(type: 'warn'|'kick'|'ban', mod: Member, target: User
let aType = type == 'ban' ? 'banned' : type + 'ed'; let aType = type == 'ban' ? 'banned' : type + 'ed';
let msg = `User ${aType}\n` let msg = `User ${aType}\n`
+ `\`@${mod.user?.username}\` **${aType}** \`@` + `\`@${mod.user?.username}\` **${aType}** \`@`
+ `${target.username}\`${type == 'warn' ? '.' : ` from ${mod.server?.name}.`}\n` + `${target.username}\`${type == 'warn' ? '.' : ` from ${server.name}.`}\n`
+ `**Reason**: \`${reason ? reason : 'No reason provided.'}\`\n` + `**Reason**: \`${reason ? reason : 'No reason provided.'}\`\n`
+ (extraText ?? ''); + (extraText ?? '');
@ -138,7 +139,7 @@ async function logModAction(type: 'warn'|'kick'|'ban', mod: Member, target: User
let fetchUsername = async (id: string) => { let fetchUsername = async (id: string) => {
try { try {
let u = await client.users.fetch(id); let u = client.users.get(id) || await client.users.fetch(id);
return `@${u.username}`; return `@${u.username}`;
} catch(e) { return 'Unknown user' } } catch(e) { return 'Unknown user' }
} }