mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 12:21:00 -05:00
MP fixes
This commit is contained in:
parent
193b0f35ee
commit
b78edc9a5f
31
src/commands/mp-maintenance.ts
Normal file
31
src/commands/mp-maintenance.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import Discord from 'discord.js';
|
||||||
|
import TClient from '../client.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
|
||||||
|
if (client.config.mainServer.id === interaction.guildId) {
|
||||||
|
if (!interaction.member.roles.cache.has(client.config.mainServer.roles.mpmanager) && !interaction.member.roles.cache.has(client.config.mainServer.roles.bottech) && !interaction.member.roles.cache.has(client.config.mainServer.roles.admin)) return client.youNeedRole(interaction, 'mpmanager');
|
||||||
|
}
|
||||||
|
const maintenanceMessage = interaction.options.getString('message');
|
||||||
|
const activePlayersChannel = '739084625862852715';
|
||||||
|
const channel = (client.channels.cache.get(activePlayersChannel) as Discord.TextChannel);
|
||||||
|
const embed = new client.embed().setColor(client.config.embedColor).setAuthor({name: interaction.member.displayName, iconURL: interaction.member.displayAvatarURL({size:1024})}).setTimestamp();
|
||||||
|
console.log(channel.permissionsFor(interaction.guildId).has('SendMessages'));
|
||||||
|
if (channel.permissionsFor(interaction.guildId).has('SendMessages')) {
|
||||||
|
channel.permissionOverwrites.edit(interaction.guildId, {SendMessages: false}, {type: 0, reason: `Locked by ${interaction.member.displayName}`});
|
||||||
|
channel.send({embeds: [embed.setTitle('🔒 Channel locked').setDescription(`**Reason:**\n${maintenanceMessage}`)]});
|
||||||
|
interaction.reply({content: `<#${activePlayersChannel}> has been locked!`, ephemeral: true});
|
||||||
|
} else if (!channel.permissionsFor(interaction.guildId).has('SendMessages')) {
|
||||||
|
channel.permissionOverwrites.edit(interaction.guildId, {SendMessages: true}, {type: 0, reason: `Unlocked by ${interaction.member.displayName}`});
|
||||||
|
channel.send({embeds: [embed.setTitle('🔓 Channel unlocked').setDescription(`**Reason:**\n${maintenanceMessage}`)]});
|
||||||
|
interaction.reply({content: `<#${activePlayersChannel}> has been unlocked!`, ephemeral: true});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data: new Discord.SlashCommandBuilder()
|
||||||
|
.setName('mp-maintenance') // Just a workaround because I am too fucking tired of issues with it, so it gets to be in dedicated file for now. (Also sorry for the swear word, I am just stressed right now.)
|
||||||
|
.setDescription('Toggle maintenance mode for #mp-active-players')
|
||||||
|
.addStringOption(x=>x
|
||||||
|
.setName('message')
|
||||||
|
.setDescription('The message to display in the channel')
|
||||||
|
.setRequired(true))
|
||||||
|
}
|
@ -4,6 +4,7 @@ import path from 'node:path';
|
|||||||
import canvas from 'canvas';
|
import canvas from 'canvas';
|
||||||
import FormatPlayer from '../helpers/FormatPlayer.js';
|
import FormatPlayer from '../helpers/FormatPlayer.js';
|
||||||
import MessageTool from '../helpers/MessageTool.js';
|
import MessageTool from '../helpers/MessageTool.js';
|
||||||
|
import LogPrefix from '../helpers/LogPrefix.js';
|
||||||
import {readFileSync} from 'node:fs';
|
import {readFileSync} from 'node:fs';
|
||||||
import {FSData} from '../typings/interfaces';
|
import {FSData} from '../typings/interfaces';
|
||||||
|
|
||||||
@ -186,7 +187,7 @@ export default {
|
|||||||
'Please see <#543494084363288637> for additional information.'
|
'Please see <#543494084363288637> for additional information.'
|
||||||
))]});
|
))]});
|
||||||
},
|
},
|
||||||
/* url: async()=>{
|
url: async()=>{
|
||||||
if (client.config.mainServer.id == interaction.guildId) {
|
if (client.config.mainServer.id == interaction.guildId) {
|
||||||
if (!interaction.member.roles.cache.has(client.config.mainServer.roles.mpmanager) && !interaction.member.roles.cache.has(client.config.mainServer.roles.bottech) && !interaction.member.roles.cache.has(client.config.mainServer.roles.admin)) return client.youNeedRole(interaction, 'mpmanager');
|
if (!interaction.member.roles.cache.has(client.config.mainServer.roles.mpmanager) && !interaction.member.roles.cache.has(client.config.mainServer.roles.bottech) && !interaction.member.roles.cache.has(client.config.mainServer.roles.admin)) return client.youNeedRole(interaction, 'mpmanager');
|
||||||
}
|
}
|
||||||
@ -194,59 +195,26 @@ export default {
|
|||||||
if (!address){
|
if (!address){
|
||||||
try {
|
try {
|
||||||
const Url = await client.MPServer._content.findById(interaction.guildId);
|
const Url = await client.MPServer._content.findById(interaction.guildId);
|
||||||
if (interaction.options.getString('server').includes('mainServer')) {
|
if (Url[serverSelector].ip && Url[serverSelector].code) return interaction.reply(Url[serverSelector].ip+'/feed/dedicated-server-stats.json?code='+Url[serverSelector].code)
|
||||||
if (Url.mainServer.ip && Url.mainServer.code) return interaction.reply(Url.mainServer.ip+'/feed/dedicated-server-stats.json?code='+Url.mainServer.code)
|
|
||||||
} else {
|
|
||||||
if (Url.secondServer.ip && Url.secondServer.code) return interaction.reply(Url.secondServer.ip+'/feed/dedicated-server-stats.json?code='+Url.secondServer.code)
|
|
||||||
}
|
|
||||||
} catch(err){
|
} catch(err){
|
||||||
console.log(`MPDB :: ${err}`);
|
console.log(client.logTime(), `${LogPrefix('MPDB')} ${err}`);
|
||||||
interaction.reply(`\`\`\`${err}\`\`\``)
|
interaction.reply(`\`\`\`${err}\`\`\``)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!address.match(/dedicated-server-stats/)) return interaction.reply('The URL does not match `dedicated-server-stats.xml`');
|
if (!address.match(/dedicated-server-stats/)) return interaction.reply('The URL does not match `dedicated-server-stats.xml`');
|
||||||
const newURL = address.replace('xml','json').split('/feed/dedicated-server-stats.json?code=');
|
const newURL = address.replace('xml','json').split('/feed/dedicated-server-stats.json?code=');
|
||||||
try {
|
try {
|
||||||
if (interaction.options.getString('server').includes('mainServer')) {
|
console.log(client.logTime(), `${LogPrefix('MPDB')} ${serverSelector}\'s URL for ${interaction.guild.name} has been updated by ${interaction.member.displayName} (${interaction.member.id})`);
|
||||||
console.log(`MPDB :: Main Server\'s URL for ${interaction.guild.name} has been modified by ${interaction.member.displayName} (${interaction.member.id})`);
|
const affected = await client.MPServer._content.findByIdAndUpdate({_id: interaction.guildId}, {$set: {[serverSelector]: {ip: newURL[0], code: newURL[1]}}})
|
||||||
await client.MPServer._content.create({_id: interaction.guildId, mainServer: { ip: newURL[0], code: newURL[1] }, secondServer: { ip: 'unknown', code: 'unknown' }})
|
if (affected) return interaction.reply('URL successfully updated.')
|
||||||
.then(()=>interaction.reply('This guild is not found in database, therefore I have created it for you.'))
|
} catch (err) {
|
||||||
.catch((err:Error)=>interaction.reply(`I ran into a brick wall while creating the server data:\n${err.message}`))
|
console.log(client.logTime(), `${LogPrefix('MPDB')} ${serverSelector}\'s URL for ${interaction.guild.name} has been created by ${interaction.member.displayName} (${interaction.member.id})`);
|
||||||
} else {
|
await client.MPServer._content.create({_id: interaction.guildId, [serverSelector]: { ip: newURL[0], code: newURL[1] }})
|
||||||
console.log(`MPDB :: Second Server\'s URL for ${interaction.guild.name} has been modified by ${interaction.member.displayName} (${interaction.member.id})`)
|
.then(()=>interaction.reply('This server doesn\'t have any data in the database, therefore I have created it for you.'))
|
||||||
await client.MPServer._content.findOneAndUpdate({_id: interaction.guildId},{$set: {secondServer: {ip: newURL[0], code: newURL[1]}}})
|
.catch((err:Error)=>interaction.reply(`I got hit by a flying brick while trying to populate the server data:\n\`\`\`${err.message}\`\`\``))
|
||||||
.then(()=>interaction.reply('URL for second server successfully updated.'))
|
|
||||||
.catch((err:Error)=>interaction.reply(`I got hit by a flying fish while updating the server data:\n${err.message}`))
|
|
||||||
}
|
|
||||||
} catch(err) {
|
|
||||||
if (interaction.options.getString('server').includes('mainServer')) {
|
|
||||||
const affected = await client.MPServer._content.findByIdAndUpdate({_id: interaction.guildId}, {$set: {mainServer:{ip: newURL[0], code: newURL[1]}}})
|
|
||||||
if (affected) return interaction.reply('URL for Main Server successfully updated.')
|
|
||||||
} else {
|
|
||||||
const affected = await client.MPServer._content.findByIdAndUpdate({_id: interaction.guildId}, {$set: {secondServer:{ip: newURL[0], code: newURL[1]}}})
|
|
||||||
if (affected) return interaction.reply('URL for Second Server successfully updated.')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
maintenance: ()=>{
|
|
||||||
if (client.config.mainServer.id === interaction.guildId) {
|
|
||||||
if (!interaction.member.roles.cache.has(client.config.mainServer.roles.mpmanager) && !interaction.member.roles.cache.has(client.config.mainServer.roles.bottech) && !interaction.member.roles.cache.has(client.config.mainServer.roles.admin)) return client.youNeedRole(interaction, 'mpmanager');
|
|
||||||
}
|
|
||||||
const maintenanceMessage = interaction.options.getString('message');
|
|
||||||
const activePlayersChannel = '739084625862852715';
|
|
||||||
const channel = (client.channels.cache.get(activePlayersChannel) as Discord.TextChannel);
|
|
||||||
console.log(channel.permissionsFor(interaction.guildId).has('SendMessages'));
|
|
||||||
if (channel.permissionOverwrites.cache.get(interaction.guildId).deny.has('SendMessages')) {
|
|
||||||
channel.permissionOverwrites.edit(interaction.guildId, {SendMessages: true}, {type: 0, reason: `Unlocked by ${interaction.member.displayName}`});
|
|
||||||
channel.send({embeds: [new client.embed().setColor(client.config.embedColor).setAuthor({name: interaction.member.displayName, iconURL: interaction.member.displayAvatarURL({size:1024})}).setTitle('🔓 Channel unlocked').setDescription(`**Reason:**\n${maintenanceMessage}`).setTimestamp()]});
|
|
||||||
interaction.reply({content: `<#${activePlayersChannel}> has been unlocked!`, ephemeral: true});
|
|
||||||
} else if (channel.permissionOverwrites.cache.get(interaction.guildId).allow.has('SendMessages')) {
|
|
||||||
channel.permissionOverwrites.edit(interaction.guildId, {SendMessages: false}, {type: 0, reason: `Locked by ${interaction.member.displayName}`});
|
|
||||||
channel.send({embeds: [new client.embed().setColor(client.config.embedColor).setAuthor({name: interaction.member.displayName, iconURL: interaction.member.displayAvatarURL({size:1024})}).setTitle('🔒 Channel locked').setDescription(`**Reason:**\n${maintenanceMessage}`).setTimestamp()]});
|
|
||||||
interaction.reply({content: `<#${activePlayersChannel}> has been locked!`, ephemeral: true});
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
})[interaction.options.getSubcommand()]();
|
})[interaction.options.getSubcommand()]();
|
||||||
},
|
},
|
||||||
data: new Discord.SlashCommandBuilder()
|
data: new Discord.SlashCommandBuilder()
|
||||||
@ -259,7 +227,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])))
|
||||||
.addSubcommand(x=>x
|
.addSubcommand(x=>x
|
||||||
.setName('players')
|
.setName('players')
|
||||||
.setDescription('Display players on server')
|
.setDescription('Display players on server')
|
||||||
@ -267,19 +235,19 @@ export default {
|
|||||||
.setName('server')
|
.setName('server')
|
||||||
.setDescription('The server to display players for')
|
.setDescription('The server to display players for')
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.setChoices(serverChoices[0])))
|
.setChoices(serverChoices[0], serverChoices[1])))
|
||||||
/* .addSubcommand(x=>x
|
.addSubcommand(x=>x
|
||||||
.setName('url')
|
.setName('url')
|
||||||
.setDescription('View or update the server URL')
|
.setDescription('View or update the server URL')
|
||||||
.addStringOption(x=>x
|
.addStringOption(x=>x
|
||||||
.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')
|
||||||
.setRequired(false))) */
|
.setRequired(false)))
|
||||||
.addSubcommand(x=>x
|
.addSubcommand(x=>x
|
||||||
.setName('info')
|
.setName('info')
|
||||||
.setDescription('Display server information')
|
.setDescription('Display server information')
|
||||||
@ -287,12 +255,5 @@ export default {
|
|||||||
.setName('server')
|
.setName('server')
|
||||||
.setDescription('The server to display information for')
|
.setDescription('The server to display information for')
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.setChoices(serverChoices[0])))
|
.setChoices(serverChoices[0], serverChoices[1])))
|
||||||
/* .addSubcommand(x=>x
|
|
||||||
.setName('maintenance')
|
|
||||||
.setDescription('Toggle maintenance mode for #mp-active-players')
|
|
||||||
.addStringOption(x=>x
|
|
||||||
.setName('message')
|
|
||||||
.setDescription('The message to display in the channel')
|
|
||||||
.setRequired(true))) */
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user