1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 04:10:59 -05:00

Fix mp command and forgor to put guild ids back

This commit is contained in:
toast-ts 2023-01-02 21:15:49 +11:00
parent 2fb0da786d
commit 03985ffa46
2 changed files with 9 additions and 13 deletions

View File

@ -5,9 +5,8 @@ import MPDB from '../models/MPServer';
async function MPdata(client:TClient, interaction:Discord.ChatInputCommandInteraction, embed: EmbedBuilder) { async function MPdata(client:TClient, interaction:Discord.ChatInputCommandInteraction, embed: EmbedBuilder) {
let FSserver; let FSserver;
MPDB.sync(); MPDB.sync();
const newServerId = interaction.guildId; if (!await MPDB.findOne({where: {serverId: interaction.guildId}})) return interaction.reply('This server isn\'t linked.')
if (!await MPDB.findOne({where: {serverId: newServerId}})) return interaction.reply('This server isn\'t linked.') const ServerURL = await MPDB.findOne({where: { serverId: interaction.guildId }});
const ServerURL = await MPDB.findOne({where: { serverId: newServerId }});
if (!ServerURL) return interaction.reply(`No gameserver found, please contact <@&${client.config.mainServer.roles.mpmanager}> to add it.`) if (!ServerURL) return interaction.reply(`No gameserver found, please contact <@&${client.config.mainServer.roles.mpmanager}> to add it.`)
const DBURL = ServerURL.ip const DBURL = ServerURL.ip
const DBCode = ServerURL.code const DBCode = ServerURL.code
@ -16,17 +15,14 @@ async function MPdata(client:TClient, interaction:Discord.ChatInputCommandIntera
if (!verifyURL) return interaction.reply(`Invalid gameserver IP, please contact <@&${client.config.mainServer.roles.mpmanager}> to update it.`) if (!verifyURL) return interaction.reply(`Invalid gameserver IP, please contact <@&${client.config.mainServer.roles.mpmanager}> to update it.`)
// Fetch dss // Fetch dss
try { try { // v I am aware timeout has decreased from 2800 to 2588 to fit within Discord's interaction timeouts (3s) -Toast
FSserver = await client.axios.get(completedURL, {timeout: 2800}) // 2800 seems doable with database latency added to it. FSserver = await client.axios.get(completedURL, {timeout: 2588}) // Finally got around to fixing the command when it cannot ping the host.
} catch(err) { } catch(err) {
// Blame Nawdic & RedRover92 // Blame Nawdic & RedRover92
embed.setTitle('Host is not responding.'); embed.setTitle('Host is not responding.');
embed.setColor(client.config.embedColorRed); embed.setColor(client.config.embedColorRed);
interaction.reply({embeds: [embed]}).catch(err=>{
interaction.channel.send({content: `Interaction author: **${interaction.user.tag}** (\`${interaction.user.id}\`)`, embeds: [embed]})
})
console.log(`[${client.moment().format('DD/MM/YY HH:mm:ss')}] dag mp fail to fetch, host is not responding.`); console.log(`[${client.moment().format('DD/MM/YY HH:mm:ss')}] dag mp fail to fetch, host is not responding.`);
return; return interaction.reply('Server didn\'t respond in time.');
} }
return FSserver return FSserver
} }
@ -44,7 +40,7 @@ export default {
case 'status': case 'status':
const embed0 = new client.embed(); const embed0 = new client.embed();
const FSserver0 = await MPdata(client, interaction, embed0); const FSserver0 = await MPdata(client, interaction, embed0);
if (!FSserver0?.data) return console.log('FSserver0 failed'); if (!FSserver0?.data) return console.log('FSserver0 failed - status');
try { try {
if (FSserver0.data.server.name.length > 1){ if (FSserver0.data.server.name.length > 1){
embed0.setTitle('Status/Details').setColor(client.config.embedColor).addFields( embed0.setTitle('Status/Details').setColor(client.config.embedColor).addFields(
@ -218,7 +214,7 @@ export default {
const Image = new client.attachmentBuilder(img.toBuffer(),{name: 'FSStats.png'}) const Image = new client.attachmentBuilder(img.toBuffer(),{name: 'FSStats.png'})
embed1.setImage('attachment://FSStats.png') embed1.setImage('attachment://FSStats.png')
const FSserver1 = await MPdata(client, interaction, embed1) const FSserver1 = await MPdata(client, interaction, embed1)
if (!FSserver1?.data) return console.log('FSserver1 failed') if (!FSserver1?.data) return console.log('FSserver1 failed - players')
embed1.setTitle(FSserver1?.data.server.name.length == 0 ? 'Offline' : FSserver1?.data.server.name) embed1.setTitle(FSserver1?.data.server.name.length == 0 ? 'Offline' : FSserver1?.data.server.name)
.setDescription(`${FSserver1?.data.slots.used}/${FSserver1?.data.slots.capacity}`) .setDescription(`${FSserver1?.data.slots.used}/${FSserver1?.data.slots.capacity}`)
.setColor(FSserver1?.data.server.name.length == 0 ? client.config.embedColorRed : client.config.embedColor); .setColor(FSserver1?.data.server.name.length == 0 ? client.config.embedColorRed : client.config.embedColor);
@ -230,7 +226,7 @@ export default {
case 'info': case 'info':
const embed2 = new client.embed().setColor(client.config.embedColor) const embed2 = new client.embed().setColor(client.config.embedColor)
const FSserver2 = await MPdata(client, interaction, embed2) const FSserver2 = await MPdata(client, interaction, embed2)
if (!FSserver2?.data) return console.log('FSserver2 failed') if (!FSserver2?.data) return console.log('FSserver2 failed - info')
const DBURL = MPDB.findOne({where: {serverId: interaction.guildId}}) const DBURL = MPDB.findOne({where: {serverId: interaction.guildId}})
embed2.setDescription([ embed2.setDescription([
`**Server name**: \`Official Daggerwin Game Server\``, `**Server name**: \`Official Daggerwin Game Server\``,

View File

@ -14,7 +14,7 @@ client.on('ready', async()=>{
}, 60000); }, 60000);
// ['929807948748832798', '468835415093411861', '1058183358267543552', '549114074273677314'] - 0=Dev Server, 1=Main Server, 2=Throne, 3=Toast's test server // ['929807948748832798', '468835415093411861', '1058183358267543552', '549114074273677314'] - 0=Dev Server, 1=Main Server, 2=Throne, 3=Toast's test server
if (client.config.botSwitches.registerCommands){ if (client.config.botSwitches.registerCommands){
['929807948748832798'].forEach((guildId)=>(client.guilds.cache.get(guildId) as Discord.Guild).commands.set(client.registry).catch((e:Error)=>{ ['929807948748832798', '468835415093411861', '1058183358267543552', '549114074273677314'].forEach((guildId)=>(client.guilds.cache.get(guildId) as Discord.Guild).commands.set(client.registry).catch((e:Error)=>{
console.log(`Couldn't register slash commands for ${guildId} because`, e.stack); console.log(`Couldn't register slash commands for ${guildId} because`, e.stack);
(client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel).send(`Cannot register slash commands for **${client.guilds.cache.get(guildId).name}** (\`${guildId}\`):\n\`\`\`${e.message}\`\`\``) (client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel).send(`Cannot register slash commands for **${client.guilds.cache.get(guildId).name}** (\`${guildId}\`):\n\`\`\`${e.message}\`\`\``)
})); }));