From 0fe7496e9081595a850d6590b41888a04f1b7731 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 22 May 2022 17:47:22 +0200 Subject: [PATCH] use embeds for mod logs --- bot/src/bot/modules/mod_logs.ts | 16 +--------------- bot/src/bot/util.ts | 34 +++++++++++---------------------- bot/src/struct/LogConfig.ts | 6 ++---- bot/src/struct/LogMessage.ts | 2 +- 4 files changed, 15 insertions(+), 43 deletions(-) diff --git a/bot/src/bot/modules/mod_logs.ts b/bot/src/bot/modules/mod_logs.ts index 0789e66..0abe445 100644 --- a/bot/src/bot/modules/mod_logs.ts +++ b/bot/src/bot/modules/mod_logs.ts @@ -42,9 +42,6 @@ client.on('packet', async (packet) => { discord: { 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: { 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` + (extraText ?? ''), color: embedColor, - 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 ?? ''), - } - } + overrides: {}, }); } } catch(e) { diff --git a/bot/src/bot/util.ts b/bot/src/bot/util.ts index a13c5a9..b5be848 100644 --- a/bot/src/bot/util.ts +++ b/bot/src/bot/util.ts @@ -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); let message = ''; + let embed: SendableEmbed|undefined = undefined; switch(config.revolt.type) { - case 'RVEMBED': - case 'DYNAMIC': - c = { ...c, ...content.overrides?.revoltRvembed }; - let url = `https://rvembed.janderedev.xyz/embed`; - let args = []; + case 'EMBED': + c = { ...c, ...content.overrides?.revoltEmbed }; + embed = { + title: c.title, + description: c.description, + colour: c.color, + } - let description = (c.description ?? ''); if (c.fields?.length) { for (const field of c.fields) { - description += `\n${field.title}\n` + - `${field.content}`; + embed.description += `\n#### ${field.title}\n${field.content}`; } } + break; - 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; - } default: // QUOTEBLOCK, PLAIN or unspecified // please disregard this mess @@ -271,6 +258,7 @@ async function sendLogMessage(config: LogConfig, content: LogMessage) { channel.sendMessage({ content: message, + embeds: embed ? [ embed ] : undefined, attachments: content.attachments ? await Promise.all(content.attachments?.map(a => uploadFile(a.content, a.name))) : undefined diff --git a/bot/src/struct/LogConfig.ts b/bot/src/struct/LogConfig.ts index 69fafef..8cb46e5 100644 --- a/bot/src/struct/LogConfig.ts +++ b/bot/src/struct/LogConfig.ts @@ -2,11 +2,9 @@ export default class LogConfig { revolt?: { channel?: string, - // RVEMBED uses https://rvembed.janderedev.xyz to send a discord style embed, which doesn't - // work properly with longer messages. + // EMBED uses Revolt's embeds. // PLAIN is like QUOTEBLOCK but without the quotes. - // DYNAMIC uses RVEMBED if the message is short enough, otherwise defaults to QUOTEBLOCK. - type?: 'QUOTEBLOCK'|'PLAIN'|'RVEMBED'|'DYNAMIC'; + type?: 'EMBED'|'QUOTEBLOCK'|'PLAIN'; } discord?: { webhookUrl?: string, diff --git a/bot/src/struct/LogMessage.ts b/bot/src/struct/LogMessage.ts index b203228..0ae6784 100644 --- a/bot/src/struct/LogMessage.ts +++ b/bot/src/struct/LogMessage.ts @@ -11,7 +11,7 @@ export default class LogMessage { attachments?: { name: string, content: Buffer }[]; overrides?: { // These take priority over `revolt` - revoltRvembed?: Override, + revoltEmbed?: Override, revoltQuoteblock?: Override, revolt?: Override,