use embeds for mod logs
This commit is contained in:
parent
8e538df1d8
commit
0fe7496e90
4 changed files with 15 additions and 43 deletions
|
@ -42,9 +42,6 @@ client.on('packet', async (packet) => {
|
||||||
discord: {
|
discord: {
|
||||||
description: `Author: @${m?.author?.username || m?.author_id || "Unknown"} | Channel: ${channel?.name || channel?._id}`
|
description: `Author: @${m?.author?.username || m?.author_id || "Unknown"} | Channel: ${channel?.name || channel?._id}`
|
||||||
},
|
},
|
||||||
revoltRvembed: {
|
|
||||||
description: `Author: @${m?.author?.username || m?.author_id || "Unknown"} | Channel: ${channel?.name || channel?._id}`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,9 +85,6 @@ client.on('packet', async (packet) => {
|
||||||
discord: {
|
discord: {
|
||||||
description: `Author: @${message.author?.username || message.author_id} | Channel: ${message.channel?.name || message.channel_id}`
|
description: `Author: @${message.author?.username || message.author_id} | Channel: ${message.channel?.name || message.channel_id}`
|
||||||
},
|
},
|
||||||
revoltRvembed: {
|
|
||||||
description: `Author: @${message.author?.username || message.author_id} | Channel: ${message.channel?.name || message.channel_id}`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,15 +126,7 @@ async function logModAction(type: 'warn'|'kick'|'ban'|'votekick', server: Server
|
||||||
+ `**Warn ID**: \`${infractionID}\`\n`
|
+ `**Warn ID**: \`${infractionID}\`\n`
|
||||||
+ (extraText ?? ''),
|
+ (extraText ?? ''),
|
||||||
color: embedColor,
|
color: embedColor,
|
||||||
overrides: {
|
overrides: {},
|
||||||
revoltRvembed: {
|
|
||||||
description: `@${mod.user?.username} ${aType} `
|
|
||||||
+ `${await fetchUsername(target)}${type == 'warn' ? '.' : ` from ${server.name}.`}\n`
|
|
||||||
+ `Reason: ${reason ? reason : 'No reason provided.'}\n`
|
|
||||||
+ `Warn ID: ${infractionID}\n`
|
|
||||||
+ (extraText ?? ''),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|
|
@ -218,36 +218,23 @@ async function sendLogMessage(config: LogConfig, content: LogMessage) {
|
||||||
const channel = client.channels.get(config.revolt.channel) || await client.channels.fetch(config.revolt.channel);
|
const channel = client.channels.get(config.revolt.channel) || await client.channels.fetch(config.revolt.channel);
|
||||||
|
|
||||||
let message = '';
|
let message = '';
|
||||||
|
let embed: SendableEmbed|undefined = undefined;
|
||||||
switch(config.revolt.type) {
|
switch(config.revolt.type) {
|
||||||
case 'RVEMBED':
|
case 'EMBED':
|
||||||
case 'DYNAMIC':
|
c = { ...c, ...content.overrides?.revoltEmbed };
|
||||||
c = { ...c, ...content.overrides?.revoltRvembed };
|
embed = {
|
||||||
let url = `https://rvembed.janderedev.xyz/embed`;
|
title: c.title,
|
||||||
let args = [];
|
description: c.description,
|
||||||
|
colour: c.color,
|
||||||
|
}
|
||||||
|
|
||||||
let description = (c.description ?? '');
|
|
||||||
if (c.fields?.length) {
|
if (c.fields?.length) {
|
||||||
for (const field of c.fields) {
|
for (const field of c.fields) {
|
||||||
description += `\n${field.title}\n` +
|
embed.description += `\n#### ${field.title}\n${field.content}`;
|
||||||
`${field.content}`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
description = description.trim();
|
|
||||||
|
|
||||||
if (c.title) args.push(`title=${encodeURIComponent(c.title)}`);
|
|
||||||
if (description) args.push(`description=${encodeURIComponent(description)}`);
|
|
||||||
if (c.color) args.push(`color=${encodeURIComponent(c.color)}`);
|
|
||||||
if (c.image) {
|
|
||||||
args.push(`image=${encodeURIComponent(c.image.url)}`);
|
|
||||||
args.push(`image_large=true`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(config.revolt.type == 'DYNAMIC' && (description.length > 1000 || description.split('\n').length > 6))) {
|
|
||||||
for (const i in args) url += `${i == '0' ? '?' : '&'}${args[i]}`;
|
|
||||||
message = `[\u200b](${url})`;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default: // QUOTEBLOCK, PLAIN or unspecified
|
default: // QUOTEBLOCK, PLAIN or unspecified
|
||||||
|
|
||||||
// please disregard this mess
|
// please disregard this mess
|
||||||
|
@ -271,6 +258,7 @@ async function sendLogMessage(config: LogConfig, content: LogMessage) {
|
||||||
|
|
||||||
channel.sendMessage({
|
channel.sendMessage({
|
||||||
content: message,
|
content: message,
|
||||||
|
embeds: embed ? [ embed ] : undefined,
|
||||||
attachments: content.attachments ?
|
attachments: content.attachments ?
|
||||||
await Promise.all(content.attachments?.map(a => uploadFile(a.content, a.name))) :
|
await Promise.all(content.attachments?.map(a => uploadFile(a.content, a.name))) :
|
||||||
undefined
|
undefined
|
||||||
|
|
|
@ -2,11 +2,9 @@ export default class LogConfig {
|
||||||
revolt?: {
|
revolt?: {
|
||||||
channel?: string,
|
channel?: string,
|
||||||
|
|
||||||
// RVEMBED uses https://rvembed.janderedev.xyz to send a discord style embed, which doesn't
|
// EMBED uses Revolt's embeds.
|
||||||
// work properly with longer messages.
|
|
||||||
// PLAIN is like QUOTEBLOCK but without the quotes.
|
// PLAIN is like QUOTEBLOCK but without the quotes.
|
||||||
// DYNAMIC uses RVEMBED if the message is short enough, otherwise defaults to QUOTEBLOCK.
|
type?: 'EMBED'|'QUOTEBLOCK'|'PLAIN';
|
||||||
type?: 'QUOTEBLOCK'|'PLAIN'|'RVEMBED'|'DYNAMIC';
|
|
||||||
}
|
}
|
||||||
discord?: {
|
discord?: {
|
||||||
webhookUrl?: string,
|
webhookUrl?: string,
|
||||||
|
|
|
@ -11,7 +11,7 @@ export default class LogMessage {
|
||||||
attachments?: { name: string, content: Buffer }[];
|
attachments?: { name: string, content: Buffer }[];
|
||||||
overrides?: {
|
overrides?: {
|
||||||
// These take priority over `revolt`
|
// These take priority over `revolt`
|
||||||
revoltRvembed?: Override,
|
revoltEmbed?: Override,
|
||||||
revoltQuoteblock?: Override,
|
revoltQuoteblock?: Override,
|
||||||
|
|
||||||
revolt?: Override,
|
revolt?: Override,
|
||||||
|
|
Loading…
Reference in a new issue