mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 04:10:59 -05:00
Cache improvements
This commit is contained in:
parent
a72f422139
commit
2c4de7dfb9
@ -20,7 +20,7 @@ export default {
|
|||||||
if (interaction.channelId === '468835769092669461' && !client.isStaff(interaction.member) && ['status', 'players'].includes(interaction.options.getSubcommand())) return interaction.reply('Please use <#739084625862852715> for `/mp status/players` commands to prevent clutter in this channel.').then(()=>setTimeout(()=>interaction.deleteReply(), 6000));
|
if (interaction.channelId === '468835769092669461' && !client.isStaff(interaction.member) && ['status', 'players'].includes(interaction.options.getSubcommand())) return interaction.reply('Please use <#739084625862852715> for `/mp status/players` commands to prevent clutter in this channel.').then(()=>setTimeout(()=>interaction.deleteReply(), 6000));
|
||||||
|
|
||||||
const database = await client.MPServer._content.findById(interaction.guildId);
|
const database = await client.MPServer._content.findById(interaction.guildId);
|
||||||
const endpoint = await fetch(database[serverSelector].ip+'/feed/dedicated-server-stats.json?code='+database[serverSelector].code, {signal: AbortSignal.timeout(7500),headers:{'User-Agent':`Daggerbot - MPdata/undici`}}).then(r=>r.json() as Promise<FSData>);
|
const endpoint = await fetch(database[serverSelector].ip+'/feed/dedicated-server-stats.json?code='+database[serverSelector].code, {signal: AbortSignal.timeout(7500),headers:{'User-Agent':'Daggerbot - MPdata/undici'}}).then(r=>r.json() as Promise<FSData>);
|
||||||
const embed = new client.embed();
|
const embed = new client.embed();
|
||||||
({
|
({
|
||||||
players: async()=>{
|
players: async()=>{
|
||||||
@ -243,7 +243,7 @@ export default {
|
|||||||
.setName('server')
|
.setName('server')
|
||||||
.setDescription('The server to update')
|
.setDescription('The server to update')
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.setChoices(serverChoices[0]))
|
.setChoices(serverChoices[0], serverChoices[1]))
|
||||||
.addStringOption(x=>x
|
.addStringOption(x=>x
|
||||||
.setName('address')
|
.setName('address')
|
||||||
.setDescription('The URL to the dedicated-server-stats.json file')
|
.setDescription('The URL to the dedicated-server-stats.json file')
|
||||||
|
@ -3,7 +3,7 @@ interface TServer {
|
|||||||
code: string
|
code: string
|
||||||
}
|
}
|
||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
import TClient from '../client';
|
import TClient from '../client.js';
|
||||||
import FormatPlayer from '../helpers/FormatPlayer.js';
|
import FormatPlayer from '../helpers/FormatPlayer.js';
|
||||||
import LogPrefix from '../helpers/LogPrefix.js';
|
import LogPrefix from '../helpers/LogPrefix.js';
|
||||||
import {writeFileSync, readFileSync} from 'node:fs';
|
import {writeFileSync, readFileSync} from 'node:fs';
|
||||||
@ -18,20 +18,22 @@ export default async(client:TClient, Channel:string, Message:string, Server:TSer
|
|||||||
const genericEmbed = new client.embed();
|
const genericEmbed = new client.embed();
|
||||||
|
|
||||||
const HITALL = async()=>{
|
const HITALL = async()=>{
|
||||||
let sessionInit = {signal: AbortSignal.timeout(8200),headers:{'User-Agent':`Daggerbot - HITALL/undici`}};
|
let sessionInit = {signal: AbortSignal.timeout(8200),headers:{'User-Agent':'Daggerbot - HITALL/undici'}};
|
||||||
try {
|
try {
|
||||||
const hitDSS = await fetch(Server.ip+'/feed/dedicated-server-stats.json?code='+Server.code, sessionInit).then(r=>r.json() as Promise<FSData>);
|
const hitDSS = await fetch(Server.ip+'/feed/dedicated-server-stats.json?code='+Server.code, sessionInit).then(r=>r.json() as Promise<FSData>);
|
||||||
const hitCSG = await fetch(Server.ip+'/feed/dedicated-server-savegame.html?code='+Server.code+'&file=careerSavegame', sessionInit).then(async r=>(client.xjs.xml2js(await r.text(), {compact: true}) as any).careerSavegame as FSCareerSavegame);
|
const hitCSG = await fetch(Server.ip+'/feed/dedicated-server-savegame.html?code='+Server.code+'&file=careerSavegame', sessionInit).then(async r=>(client.xjs.xml2js(await r.text(), {compact: true}) as any).careerSavegame as FSCareerSavegame);
|
||||||
|
|
||||||
if (!hitDSS ?? !hitCSG){
|
if (!hitDSS ?? !hitCSG){
|
||||||
if (hitDSS && !hitDSS.slots) return new Error(`${LogPrefix('MPLoop')} DSS failed with unknown slots table for ${client.MPServerCache[ServerName].name}`);
|
if (hitDSS && !hitDSS.slots) return console.log(`${LogPrefix('MPLoop')} DSS failed with unknown slots table for ${client.MPServerCache[ServerName].name}`);
|
||||||
if (hitDSS && !hitCSG) return msg.edit({content: 'No savegame found or autosave has ran.', embeds: [genericEmbed.setColor(client.config.embedColorOrange).setImage(noContentImage)]});
|
if (hitDSS && !hitCSG.slotSystem) return msg.edit({content: 'No savegame found or autosave has ran.', embeds: [genericEmbed.setColor(client.config.embedColorOrange).setImage(noContentImage)]});
|
||||||
else return msg.edit({embeds: [serverErrorEmbed]});
|
else return msg.edit({embeds: [serverErrorEmbed]});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Truncate unnecessary parts of the name for the serverLog embed
|
// Truncate unnecessary parts of the name for the MPServerCache
|
||||||
client.MPServerCache[ServerName].name = hitDSS.server.name === 'Official Daggerwin Game Server' ? 'Daggerwin' : hitDSS.server.name === 'undefined' ? 'undefined' : client.MPServerCache[ServerName].name;
|
// This is a mess, but it works.
|
||||||
//Second server name is unknown, will come back and update this later.
|
for (const filter of ['Official Daggerwin Game Server', 'Daggerwin Multifarm']) {
|
||||||
|
if (hitDSS.server.name.includes(filter)) client.MPServerCache[ServerName].name = ['Daggerwin', 'DagMF'][['Official Daggerwin Game Server', 'Daggerwin Multifarm'].indexOf(filter)];
|
||||||
|
}
|
||||||
|
|
||||||
//Timescale formatting
|
//Timescale formatting
|
||||||
function formatTimescale(number:number,digits:number,icon:string){
|
function formatTimescale(number:number,digits:number,icon:string){
|
||||||
@ -86,10 +88,10 @@ export default async(client:TClient, Channel:string, Message:string, Server:TSer
|
|||||||
msg.edit({content:'This embed updates every 35 seconds.',embeds:[serverDetails, playersEmbed]});
|
msg.edit({content:'This embed updates every 35 seconds.',embeds:[serverDetails, playersEmbed]});
|
||||||
}
|
}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
msg.edit({content: null, embeds: [new client.embed().setColor(client.config.embedColorRed).setTitle('Host did not respond back in time')]});
|
if (err.message === 'The operation was aborted due to timeout') return msg.edit({content: 'Connection timed out.', embeds: [serverErrorEmbed]});
|
||||||
console.log(client.logTime(), `Failed to make a request for ${ServerName}`)
|
msg.edit({content: null, embeds: [serverErrorEmbed]});
|
||||||
|
console.log(client.logTime(), `Failed to make a request for ${ServerName}:`, err.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HITALL();
|
HITALL();
|
||||||
// Hit dem servers in the head every 35 seconds.
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user