Skip to content

Commit

Permalink
Add DT. Push other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
reiichi001 committed Jul 6, 2024
1 parent 93a317c commit d239b01
Show file tree
Hide file tree
Showing 5 changed files with 3,047 additions and 3,106 deletions.
33 changes: 21 additions & 12 deletions events/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
const {
MessageEmbed,
} = require('discord.js');
const got = require('got');
// const got = require('got');


const { createHash } = require('crypto');
const {
createHash,
} = require('crypto');
const URLSafeBase64 = require('urlsafe-base64');

const logger = require("../modules/Logger");
Expand All @@ -18,7 +20,9 @@ const {
checkTheMessage,
} = require("../modules/checkTheMessage");

const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3");
const {
S3Client, PutObjectCommand,
} = require("@aws-sdk/client-s3");

// The MESSAGE event runs anytime a message is received
// Note that due to the binding of client to every event, every event
Expand Down Expand Up @@ -279,14 +283,15 @@ module.exports = async (client, message) => {
});


// We upload these to S3 because Discord killed Franz's proxy
// We upload these to S3 because Discord killed Franz's proxy
const objGuildID = message.guild?.id ?? "directmessage";
const response = await fetch(attachment.attachment);
const buffer = Buffer.from(await response.arrayBuffer());
const bucketName = "dalamud-support";

const origKeyName = `${objGuildID}/${message.author.id}-${attachment.name}`
let safeKeyName = `${createHash('sha1').update(origKeyName).digest('hex')}`;
const origKeyName = `${objGuildID}/${message.author.id}-${attachment.name}`;
let safeKeyName = `${createHash('sha1').update(origKeyName)
.digest('hex')}`;
safeKeyName = URLSafeBase64.encode(new Buffer.from(safeKeyName, 'hex'));
const keyName = `tspacks/${safeKeyName}.tspack`;
const objectTags = `io.franzbot.tspack/source_user_id=${message.author.id}&io.franzbot.tspack/source_guild_id=${objGuildID}`;
Expand All @@ -296,15 +301,15 @@ module.exports = async (client, message) => {
credentials: {
accessKeyId: client.config.AWS_KEY,
secretAccessKey: client.config.AWS_KEYSECRET,
}
},
});

await s3Client.send(
new PutObjectCommand({
Bucket: bucketName,
Key: keyName,
Body: buffer,
Tagging: objectTags
Tagging: objectTags,
})
);

Expand Down Expand Up @@ -377,8 +382,8 @@ module.exports = async (client, message) => {
// const dalamudLogParser = require("../modules/parse/dalamudLog");

try {
const response = await got(attachment.attachment);

const response = await fetch(attachment.attachment);
let logdata;
// const parseResults = dalamudLogParser.parse(client, response?.body);

/*
Expand All @@ -390,9 +395,12 @@ module.exports = async (client, message) => {
*/
let foundCustomRepoPluginInstalled = false;
let anyCustomRepoPluginsLoaded = false;
if (response.ok) {
logdata = await response.text();
// logger.debug(logdata);
}

const logdata = response?.body;
const logdresults = logdata.match(/TROUBLESHOOTING:(.*)/gu);
const logdresults = logdata?.match(/TROUBLESHOOTING:(.*)/gu);
if (logdresults?.length > 0) {
let data = logdresults[logdresults.length - 1];
data = data.slice(16);
Expand Down Expand Up @@ -874,6 +882,7 @@ module.exports = async (client, message) => {
.addField("Stormblood", data.ObservedEx2Version === "2012.01.01.0000.0000" ? "not installed" : data.ObservedEx2Version ?? "error", true)
.addField("Shadowbringers", data.ObservedEx3Version === "2012.01.01.0000.0000" ? "not installed" : data.ObservedEx3Version ?? "error", true)
.addField("Endwalker", data.ObservedEx4Version === "2012.01.01.0000.0000" ? "not installed" : data.ObservedEx4Version ?? "error", true)
.addField("Dawntrail", data.ObservedEx5Version === "2012.01.01.0000.0000" ? "not installed" : data.ObservedEx5Version ?? "error", true)
.addField("BCK files match", data.BckMatch ? "yes" : "no", true);

switch (data.IndexIntegrity) {
Expand Down
19 changes: 9 additions & 10 deletions modules/hydrate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const logger = require("../modules/Logger");
const got = require('got');

exports.hydrate = async (client, channel) => {
const API = "https://api.giphy.com/v1/gifs/random";
Expand All @@ -11,15 +10,15 @@ exports.hydrate = async (client, channel) => {
console.log(URL);

try {
let {
body,
} = await got(URL);
// logger.debug(body);
body = JSON.parse(body);
const randImageURL = body?.data?.images?.original?.url
?? "https://media4.giphy.com/media/2IHOdLz7YncZ79XaN7/giphy.gif";
// logger.debug(randImageURL);
channel.send(randImageURL);
const fetchRes = await fetch(URL);
if (fetchRes.ok) {
const body = await fetchRes.json();
logger.debug(body);
const randImageURL = body?.data?.images?.original?.url
?? "https://media4.giphy.com/media/2IHOdLz7YncZ79XaN7/giphy.gif";
// logger.debug(randImageURL);
channel.send(randImageURL);
}
}
catch (error) {
logger.error(error);
Expand Down
1 change: 1 addition & 0 deletions modules/slowmode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const JSONdb = require('simple-json-db');
const allowedRoles = [
"Admin",
"Administrator",
"intern",
"Officer",
"Operator",
"moderator",
Expand Down
Loading

0 comments on commit d239b01

Please sign in to comment.