Skip to content

Commit

Permalink
better log uploading:tm:
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed May 2, 2024
1 parent 310e759 commit 7fc2702
Showing 1 changed file with 58 additions and 3 deletions.
61 changes: 58 additions & 3 deletions src/handlers/log.handler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { EmbedBuilder, Events, inlineCode } from 'discord.js';
import {
ActionRow, ActionRowBuilder,

Check failure on line 2 in src/handlers/log.handler.ts

View workflow job for this annotation

GitHub Actions / lint

'ActionRow' is defined but never used
ActionRowData,

Check failure on line 3 in src/handlers/log.handler.ts

View workflow job for this annotation

GitHub Actions / lint

'ActionRowData' is defined but never used
ButtonBuilder,
ButtonStyle,
EmbedBuilder,
Events,
inlineCode,
MessageActionRowComponentData, MessagePayload, MessageReplyOptions,

Check failure on line 9 in src/handlers/log.handler.ts

View workflow job for this annotation

GitHub Actions / lint

'MessageActionRowComponentData' is defined but never used
} from 'discord.js';

// log providers
import logProviders from '../logProviders/_logProviders';
import logAnalyzers from '../logIssueAnalyzers/_logIssueAnalyzers';

import { Handler } from '..';
import { Log } from '../logs/Log';
import { MessageActionRowComponentBuilder } from '@discordjs/builders';

Check failure on line 18 in src/handlers/log.handler.ts

View workflow job for this annotation

GitHub Actions / lint

'MessageActionRowComponentBuilder' is defined but never used

export interface LogProvider {
hostnames: string[];
Expand Down Expand Up @@ -160,6 +170,42 @@ export const logHandler: Handler = (client) => {
inline: true,
});

let responseData = {
"success": false,
"id": "error",
"url": "https://mclo.gs/error",
"raw": "https://api.mclo.gs/1/raw/error"
};

let actionRowData

if (attachment) {
const formData: FormData = new FormData();
formData.append("content", log)
const data: RequestInit = {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: formData
}
await fetch("https://api.mclo.gs/1/log", data)
.then(res => res.json())
.then(data => responseData = data);

if (responseData.success) {
const logLink = new ButtonBuilder()
.setURL(responseData.url)
.setStyle(ButtonStyle.Link);
const rawLogLink = new ButtonBuilder()
.setURL(responseData.raw)
.setStyle(ButtonStyle.Link);

actionRowData = new ActionRowBuilder<ButtonBuilder>()
.addComponents(logLink, rawLogLink)
}
}

const logInfoEmbed = new EmbedBuilder()
.setTitle('Log File')
.setDescription('__Environment info__')
Expand All @@ -168,8 +214,16 @@ export const logHandler: Handler = (client) => {

const issues = await findIssues(parsedLog);

const messageData: MessagePayload | MessageReplyOptions = {
embeds: [logInfoEmbed]
}

if (responseData.success) {
messageData.components?.push(actionRowData!)
}

if (!issues.length) {
await message.reply({ embeds: [logInfoEmbed] });
await message.reply(messageData);
return;
}

Expand All @@ -183,7 +237,8 @@ export const logHandler: Handler = (client) => {
.setFields(...issues)
.setColor('Red');

await message.reply({ embeds: [logInfoEmbed, issuesEmbed] });
messageData.embeds?.push(issuesEmbed)
await message.reply(messageData);
return;
} catch (error) {
console.error('Unhandled exception on MessageCreate', error);
Expand Down

0 comments on commit 7fc2702

Please sign in to comment.