mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 04:10:59 -05:00
Attempt to fix the 'RanIntoHumor' that's been broken under the radar.
This commit is contained in:
parent
dc0c4836b8
commit
92ac4b51de
@ -9,10 +9,14 @@ import {FSData} from 'src/interfaces';
|
|||||||
import {requestServerData, mpModuleDisabled, refreshTimerSecs, playtimeStat} from '../modules/MPModule.js';
|
import {requestServerData, mpModuleDisabled, refreshTimerSecs, playtimeStat} from '../modules/MPModule.js';
|
||||||
|
|
||||||
async function fetchData(client:TClient, interaction:Discord.ChatInputCommandInteraction, serverName:string):Promise<FSData|Discord.InteractionResponse> {
|
async function fetchData(client:TClient, interaction:Discord.ChatInputCommandInteraction, serverName:string):Promise<FSData|Discord.InteractionResponse> {
|
||||||
const db = await client.MPServer.findInCache();
|
try {
|
||||||
const data = await requestServerData(client, db.find(x=>x.serverName === serverName));
|
const db = await client.MPServer.findInCache();
|
||||||
if (!data) return interaction.reply('Ran into a '+RanIntoHumor+' while trying to retrieve server data, please try again later.');
|
const data = await requestServerData(client, db.find(x=>x.serverName === serverName));
|
||||||
return data.dss as FSData;
|
return data.dss as FSData;
|
||||||
|
} catch {
|
||||||
|
Logger.console('error', 'MPDB', 'Function failed - fetchData');
|
||||||
|
return interaction.reply('Ran into a '+RanIntoHumor()+' while trying to retrieve server data, please try again later.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const logPrefix = 'MPDB';
|
const logPrefix = 'MPDB';
|
||||||
@ -42,27 +46,30 @@ export default class MP {
|
|||||||
const canvas = await new CanvasBuilder().generateGraph(PDArr.slice(-120), 'players');
|
const canvas = await new CanvasBuilder().generateGraph(PDArr.slice(-120), 'players');
|
||||||
const players:string[] = [];
|
const players:string[] = [];
|
||||||
let embedColor:Discord.ColorResolvable;
|
let embedColor:Discord.ColorResolvable;
|
||||||
switch (true){
|
|
||||||
case DSS?.slots?.used === DSS?.slots.capacity:
|
|
||||||
embedColor = client.config.embedColorRed;
|
|
||||||
break;
|
|
||||||
case DSS?.slots?.used > 8:
|
|
||||||
embedColor = client.config.embedColorYellow;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
embedColor = client.config.embedColorGreen;
|
|
||||||
}
|
|
||||||
for (const player of DSS.slots.players.filter(x=>x.isUsed)) players.push(playtimeStat(player))
|
|
||||||
|
|
||||||
let attachmentName:string = 'MPModule.jpg';
|
try {
|
||||||
await interaction.reply({embeds:[new client.embed()
|
switch (true){
|
||||||
.setTitle(DSS.server?.name.length > 0 ? DSS.server.name : 'Offline')
|
case DSS?.slots?.used === DSS?.slots?.capacity:
|
||||||
.setColor(embedColor)
|
embedColor = client.config.embedColorRed;
|
||||||
.setDescription(DSS?.slots?.used < 1 ? '*Nobody is playing*' : players.join('\n\n'))
|
break;
|
||||||
.setImage(`attachment://${attachmentName}`)
|
case DSS?.slots?.used > 8:
|
||||||
.setAuthor({name: `${DSS.slots.used}/${DSS.slots.capacity}`})
|
embedColor = client.config.embedColorYellow;
|
||||||
.setFooter({text: `Current time: ${('0'+Math.floor((DSS?.server.dayTime/3600/1000))).slice(-2)}:${('0'+Math.floor((DSS?.server.dayTime/60/1000)%60)).slice(-2)}`})
|
break;
|
||||||
], files: [new client.attachment(canvas.toBuffer('image/jpeg'), {name: attachmentName})]})
|
default:
|
||||||
|
embedColor = client.config.embedColorGreen;
|
||||||
|
}
|
||||||
|
for (const player of DSS.slots.players.filter(x=>x.isUsed)) players.push(playtimeStat(player))
|
||||||
|
let attachmentName:string = 'MPModule.jpg';
|
||||||
|
|
||||||
|
await interaction.reply({embeds:[new client.embed()
|
||||||
|
.setTitle(DSS.server?.name.length > 0 ? DSS.server.name : 'Offline')
|
||||||
|
.setColor(embedColor)
|
||||||
|
.setDescription(DSS?.slots?.used < 1 ? '*Nobody is playing*' : players.join('\n\n'))
|
||||||
|
.setImage(`attachment://${attachmentName}`)
|
||||||
|
.setAuthor({name: `${DSS.slots?.used}/${DSS.slots?.capacity}`})
|
||||||
|
.setFooter({text: `Current time: ${('0'+Math.floor((DSS?.server.dayTime/3600/1000))).slice(-2)}:${('0'+Math.floor((DSS?.server.dayTime/60/1000)%60)).slice(-2)}`})
|
||||||
|
], files: [new client.attachment(canvas.toBuffer('image/jpeg'), {name: attachmentName})]});
|
||||||
|
} catch {}
|
||||||
},
|
},
|
||||||
details: async()=>{
|
details: async()=>{
|
||||||
const DSS = await fetchData(client, interaction, choiceSelector) as FSData;
|
const DSS = await fetchData(client, interaction, choiceSelector) as FSData;
|
||||||
@ -71,26 +78,25 @@ export default class MP {
|
|||||||
const server = db.find(x=>x.serverName === choiceSelector);
|
const server = db.find(x=>x.serverName === choiceSelector);
|
||||||
|
|
||||||
const dEmbed = new client.embed().setColor(client.config.embedColor).setAuthor({name: 'Crossplay server'}).setDescription(MessageTool.concatMessage(
|
const dEmbed = new client.embed().setColor(client.config.embedColor).setAuthor({name: 'Crossplay server'}).setDescription(MessageTool.concatMessage(
|
||||||
`**Name:** \`${DSS?.server.name.length > 0 ? DSS.server.name : '\u200b'}\``,
|
`**Name:** \`${DSS.server?.name.length > 0 ? DSS.server.name : '\u200b'}\``,
|
||||||
'**Password:** `mf4700`',
|
'**Password:** `mf4700`',
|
||||||
`**Map:** \`${DSS.server.mapName.length > 0 ? DSS.server.mapName : 'No map'}\``,
|
`**Map:** \`${DSS.server?.mapName.length > 0 ? DSS.server.mapName : 'No map'}\``,
|
||||||
`**Mods:** [Click here](http://${server.ip}/mods.html) **|** [Direct link](http://${server.ip}/all_mods_download?onlyActive=true)`,
|
`**Mods:** [Click here](http://${server.ip}/mods.html) **|** [Direct link](http://${server.ip}/all_mods_download?onlyActive=true)`,
|
||||||
'**Filters:** [Click here](https://discord.com/channels/468835415093411861/468835769092669461/926581585938120724)',
|
'**Filters:** [Click here](https://discord.com/channels/468835415093411861/468835769092669461/926581585938120724)',
|
||||||
`Please see <#${channels.serverInfo}> for more additional information and rules.`
|
`Please see <#${channels.serverInfo}> for more additional information and rules.`
|
||||||
));
|
));
|
||||||
if (DSS.server.name.length < 1) dEmbed.setFooter({text: 'Server is currently offline'});
|
if (DSS.server?.name.length < 1) dEmbed.setFooter({text: 'Server is currently offline'});
|
||||||
await interaction.reply({embeds: [dEmbed]})
|
DSS.server ? await interaction.reply({embeds: [dEmbed]}) : null;
|
||||||
},
|
},
|
||||||
status: async()=>{
|
status: async()=>{
|
||||||
const DSS = await fetchData(client, interaction, choiceSelector) as FSData;
|
const DSS = await fetchData(client, interaction, choiceSelector) as FSData;
|
||||||
if (!DSS) return console.log('Endpoint failed - status');
|
if (!DSS) return console.log('Endpoint failed - status');
|
||||||
if (DSS.server.name.length > 0) {
|
|
||||||
await interaction.reply({embeds: [new client.embed().setColor(client.config.embedColor).addFields(
|
DSS.server ? await interaction.reply({embeds: [new client.embed().setColor(client.config.embedColor).addFields(
|
||||||
{name: 'Name', value: `\`${DSS?.server.name}\``},
|
{name: 'Name', value: DSS.server?.name?.length < 1 ? '*`Offline`*' : `\`${DSS?.server?.name}\``},
|
||||||
{name: 'Players', value: `${DSS.slots.used}/${DSS.slots.capacity}`},
|
{name: 'Players', value: `${DSS?.slots.used}/${DSS?.slots.capacity}`},
|
||||||
{name: 'Map', value: DSS?.server.mapName}
|
{name: 'Map', value: DSS?.server.mapName}
|
||||||
).setFooter({text: `Version: ${DSS?.server.version} | Time: ${`${('0'+Math.floor((DSS?.server.dayTime/3600/1000))).slice(-2)}:${('0'+Math.floor((DSS?.server.dayTime/60/1000)%60)).slice(-2)}`}`})]})
|
).setFooter({text: `Version: ${DSS?.server?.version} | Time: ${`${('0'+Math.floor((DSS?.server.dayTime/3600/1000))).slice(-2)}:${('0'+Math.floor((DSS?.server.dayTime/60/1000)%60)).slice(-2)}`}`})]}) : null
|
||||||
} else return interaction.reply('Server is currently offline.')
|
|
||||||
},
|
},
|
||||||
pallets: async()=>{
|
pallets: async()=>{
|
||||||
const DSS = await fetchData(client, interaction, choiceSelector) as FSData;
|
const DSS = await fetchData(client, interaction, choiceSelector) as FSData;
|
||||||
|
Loading…
Reference in New Issue
Block a user