mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 12:21:00 -05:00
After few trial and errors, I finally got it!!
This commit is contained in:
parent
4a6060e966
commit
96444a4c02
@ -1,68 +1,44 @@
|
|||||||
|
interface TServer {
|
||||||
|
ip: string
|
||||||
|
code: string
|
||||||
|
}
|
||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
import TClient from './client';
|
import TClient from './client';
|
||||||
import {writeFileSync, readFileSync} from 'node:fs';
|
import {writeFileSync, readFileSync} from 'node:fs';
|
||||||
import {FSPlayer, FSData, FSCareerSavegame} from './typings/interfaces';
|
import {FSPlayer, FSData, FSCareerSavegame} from './typings/interfaces';
|
||||||
|
|
||||||
export default async(client:TClient, Channel:string, Message:string, ServerName:string)=>{
|
export default async(client:TClient, Channel:string, Message:string, Server:TServer)=>{
|
||||||
if (!client.config.botSwitches.mpstats) return;
|
if (!client.config.botSwitches.mpstats) return;
|
||||||
|
let MPLoopPrefix = '[MPLoop] ';
|
||||||
|
let noContentImage = 'https://cdn.discordapp.com/attachments/1118960531135541318/1140906691236479036/68efx1.png';
|
||||||
const msg = await (client.channels.resolve(Channel) as Discord.TextChannel).messages.fetch(Message);
|
const msg = await (client.channels.resolve(Channel) as Discord.TextChannel).messages.fetch(Message);
|
||||||
const database = await client.MPServer._content.findById(client.config.mainServer.id);
|
|
||||||
const servers = {
|
|
||||||
main: {
|
|
||||||
dss: database.mainServer.ip+'/feed/dedicated-server-stats.json?code='+database.mainServer.code,
|
|
||||||
csg: database.mainServer.ip+'/feed/dedicated-server-savegame.html?code='+database.mainServer.code+'&file=careerSavegame'
|
|
||||||
},
|
|
||||||
second: {
|
|
||||||
dss: database.secondServer.ip+'/feed/dedicated-server-stats.json?code='+database.secondServer.code,
|
|
||||||
csg: database.secondServer.ip+'/feed/dedicated-server-savegame.html?code='+database.secondServer.code+'&file=careerSavegame'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// Log bot uptime for the sake of debugging.
|
// Log bot uptime for the sake of debugging.
|
||||||
(client.channels.resolve('1091300529696673792') as Discord.TextChannel).send(client.formatTime(client.uptime, 2, {longNames: true, commas: true}));
|
(client.channels.resolve('1091300529696673792') as Discord.TextChannel).send(client.formatTime(client.uptime, 2, {longNames: true, commas: true}));
|
||||||
|
|
||||||
const HITALL = async()=>{
|
const HITALL = async()=>{
|
||||||
/* const hitDSS = await Promise.all([
|
let sessionInit = {signal: AbortSignal.timeout(7500),headers:{'User-Agent':`Daggerbot - HITALL/fetch`}};
|
||||||
client.axios.get(servers.main.dss,{timeout:7500,maxContentLength:Infinity,headers:{'User-Agent':`Daggerbot - HITALL/axios ${client.axios.VERSION}`}}),
|
|
||||||
client.axios.get(servers.second.dss,{timeout:7500,maxContentLength:Infinity,headers:{'User-Agent':`Daggerbot - HITALL/axios ${client.axios.VERSION}`}})
|
|
||||||
]).catch(e=>{throw new Error('hitDSS failed to make a request', {cause: e.cause})}); */
|
|
||||||
const hitCSG = await Promise.all([
|
|
||||||
client.axios.get(servers.main.csg,{timeout:7500,maxContentLength:Infinity,headers:{'User-Agent':`Daggerbot - HITALL/axios ${client.axios.VERSION}`}}),
|
|
||||||
client.axios.get(servers.second.csg,{timeout:7500,maxContentLength:Infinity,headers:{'User-Agent':`Daggerbot - HITALL/axios ${client.axios.VERSION}`}})
|
|
||||||
]).catch(e=>{throw new Error('hitCSG failed to make a request', {cause: e.cause})});
|
|
||||||
try {
|
try {
|
||||||
const APIData = {
|
const hitDSS = await fetch(Server.ip+'/feed/dedicated-server-stats.json?code='+Server.code, sessionInit).then(r=>r.json() as Promise<FSData>);
|
||||||
'Daggerwin': {
|
const hitCSG = await fetch(Server.ip+'/feed/dedicated-server-savegame.html?code='+Server.code+'&file=careerSavegame', sessionInit).then(async r=>{
|
||||||
//dss: hitDSS[0].data as FSData,
|
if (r.status === 204) return msg.edit({embeds: [new client.embed().setImage(noContentImage)]});
|
||||||
csg: (client.xjs.xml2js(hitCSG[0].data,{compact:true}) as any).careerSavegame as FSCareerSavegame
|
else return (client.xjs.xml2js(await r.text(), {compact: true}) as any).careerSavegame as FSCareerSavegame
|
||||||
},
|
}).catch(()=>console.log(client.logTime(), `${MPLoopPrefix}CSG failed for ${Server.ip.replace(/^(https?)(\:\/\/)/, '')}`));
|
||||||
'SecondServer': {
|
|
||||||
//dss: hitDSS[1].data as FSData,
|
if (!hitDSS ?? !hitCSG){
|
||||||
csg: (client.xjs.xml2js(hitCSG[1].data,{compact:true}) as any).careerSavegame as FSCareerSavegame
|
if (hitDSS && !hitDSS.slots) return new Error(`${MPLoopPrefix}DSS failed for unknown slots table`);
|
||||||
|
return msg.edit({embeds: [new client.embed().setColor(client.config.embedColorRed).setTitle('Host did not respond back in time')]});
|
||||||
}
|
}
|
||||||
} as const;
|
|
||||||
console.log(APIData['Daggerwin'].csg)
|
|
||||||
console.log(APIData['SecondServer'].csg)
|
|
||||||
//console.log((APIData.Daggerwin.dss as FSData).server.name)
|
|
||||||
//console.log((APIData.Daggerwin.csg as FSCareerSavegame).statistics.money)
|
|
||||||
msg.edit({content: [
|
msg.edit({content: [
|
||||||
ServerName,
|
Server.ip.replace(/^(https?)(\:\/\/)/, ''),
|
||||||
(APIData[ServerName].csg as FSCareerSavegame).settings.savegameName._text
|
hitDSS.server.name.length > 0 ? hitDSS.server.name : 'Offline'
|
||||||
].join('\n')})
|
].join('\n'), embeds: []})
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
msg.edit({content: err.message})
|
throw new Error(`${MPLoopPrefix}Failed to make a promise request.`, {cause: err.cause})
|
||||||
throw new Error('HITALL failed to make a promise request', {cause: err.cause});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HITALL();
|
HITALL();
|
||||||
|
|
||||||
/* await Promise.all([
|
|
||||||
client.axios.get(servers.main.dss,{timeout:7500,maxContentLength:Infinity,headers:{'User-Agent':`Daggerbot/axios ${client.axios.VERSION}`}}),
|
|
||||||
client.axios.get(servers.main.csg,{timeout:7500,maxContentLength:Infinity,headers:{'User-Agent':`Daggerbot/axios ${client.axios.VERSION}`}}),
|
|
||||||
client.axios.get(servers.second.dss,{timeout:7500,maxContentLength:Infinity,headers:{'User-Agent':`Daggerbot/axios ${client.axios.VERSION}`}}),
|
|
||||||
client.axios.get(servers.second.csg,{timeout:7500,maxContentLength:Infinity,headers:{'User-Agent':`Daggerbot/axios ${client.axios.VERSION}`}})
|
|
||||||
]).then(x=>x.map(x=>x.data)).catch(()=>{throw new Error('[MPLOOP] Failed to make a promise request.')});
|
|
||||||
msg.edit({content: ServerName, embeds: []}) */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* export default async(client:TClient,Channel:string,Message:string,ServerName:string)=>{
|
/* export default async(client:TClient,Channel:string,Message:string,ServerName:string)=>{
|
||||||
|
@ -12,11 +12,11 @@
|
|||||||
"929807948748832798", "468835415093411861", "1058183358267543552", "549114074273677314"
|
"929807948748832798", "468835415093411861", "1058183358267543552", "549114074273677314"
|
||||||
],
|
],
|
||||||
"MPStatsLocation": {
|
"MPStatsLocation": {
|
||||||
"main": {
|
"mainServer": {
|
||||||
"channel": "543494084363288637",
|
"channel": "543494084363288637",
|
||||||
"message": "1023699243183112192"
|
"message": "1023699243183112192"
|
||||||
},
|
},
|
||||||
"second": {
|
"secondServer": {
|
||||||
"channel": "",
|
"channel": "",
|
||||||
"message": ""
|
"message": ""
|
||||||
}
|
}
|
||||||
|
@ -68,10 +68,9 @@ if (client.config.botSwitches.music){
|
|||||||
|
|
||||||
// YouTube Upload notification and Daggerwin MP loop
|
// YouTube Upload notification and Daggerwin MP loop
|
||||||
setInterval(async()=>{
|
setInterval(async()=>{
|
||||||
console.log(client.logTime(), 'MPLoop Interval')
|
const serverlake = (await client.MPServer._content.findById(client.config.mainServer.id));
|
||||||
MPLoop(client, client.config.MPStatsLocation.main.channel, client.config.MPStatsLocation.main.message, 'Daggerwin')
|
for await (const [locName, locArea] of Object.entries(client.config.MPStatsLocation)) await MPLoop(client, locArea.channel, locArea.message, serverlake[locName])
|
||||||
MPLoop(client, client.config.MPStatsLocation.second.channel, client.config.MPStatsLocation.second.message, 'SecondServer')
|
}, 10000);
|
||||||
}, 30000);
|
|
||||||
setInterval(async()=>{
|
setInterval(async()=>{
|
||||||
client.YTLoop('UCQ8k8yTDLITldfWYKDs3xFg', 'Daggerwin', '528967918772551702'); // 528967918772551702 = #videos-and-streams
|
client.YTLoop('UCQ8k8yTDLITldfWYKDs3xFg', 'Daggerwin', '528967918772551702'); // 528967918772551702 = #videos-and-streams
|
||||||
client.YTLoop('UCguI73--UraJpso4NizXNzA', 'Machinery Restorer', '767444045520961567') // 767444045520961567 = #machinery-restorer
|
client.YTLoop('UCguI73--UraJpso4NizXNzA', 'Machinery Restorer', '767444045520961567') // 767444045520961567 = #machinery-restorer
|
||||||
|
Loading…
Reference in New Issue
Block a user