1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 16:30:58 -05:00

Merge the command to /mp

This commit is contained in:
AnxietyisReal 2023-01-12 16:38:23 +11:00
parent 87bc8c6b89
commit 12a6fbf7dc
2 changed files with 45 additions and 54 deletions

View File

@ -1,53 +0,0 @@
import Discord,{SlashCommandBuilder} from 'discord.js';
import { TClient } from 'src/client';
import MPDB from '../models/MPServer';
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
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');
MPDB.sync();
const newServerId = interaction.guildId
const address = interaction.options.getString('address')
if (!address) {
try {
const Url = await MPDB.findOne({where: {serverId: newServerId}})
if (Url.ip && Url.code){return interaction.reply(`${Url.get('ip')}` + '/feed/dedicated-server-stats.json?code=' + `${Url.get('code')}`)}
} catch(err) {
console.log(`MPDB | Error: ${err}`)
interaction.reply('**Database error:**\nTry inserting an URL first.')
}
} else {
const verifyURL = address.match(/feed/)
if (!verifyURL) return interaction.reply('That URL is not a valid `dedicated-server-stats.xml`')
const convertURL = address
const newURL = convertURL.replace('xml','json').split('/feed/dedicated-server-stats.json?code=')
try {
console.log(`MPDB | URL for ${interaction.guild.name} has been updated by ${interaction.member.displayName} (${interaction.member.id})`)
const Url = await MPDB.create({
serverId: newServerId,
ip: newURL[0],
code: newURL[1],
timesUpdated: 0
});
return interaction.reply(`Successfully set the URL to ${Url.ip}`)
} catch(err) {
if (err.name == 'SequelizeUniqueConstraintError'){
const AffectedRows = await MPDB.update({ip: newURL[0], code: newURL[1]},{where:{serverId: newServerId}});
await MPDB.increment('timesUpdated', {where: {serverId: newServerId}});
if (AffectedRows){return interaction.reply(`Successfully updated the URL to ${newURL[0]}`)}
} else {
console.log(err)
interaction.reply(`\`MPDB\` has caught an error, notify <@&${client.config.mainServer.roles.bottech}>`)
}
}
}
},
data: new SlashCommandBuilder()
.setName('url')
.setDescription('View the URL for this server\'s FSMP server or update the URL')
.addStringOption((opt)=>opt
.setName('address')
.setDescription('Insert a \'dedicated-server-stats\' url'))
}

View File

@ -244,6 +244,44 @@ export default {
}
interaction.reply({embeds: [embed2]})
break;
case 'url':
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');
MPDB.sync();
const address = interaction.options.getString('address');
if (!address){
try {
const Url = await MPDB.findOne({where:{serverId: interaction.guildId}})
if (Url.ip && Url.code){return interaction.reply(`${Url.get('ip')}` + '/feed/dedicated-server-stats.json?code=' + `${Url.get('code')}`)}
} catch(err){
console.log(`MPDB | ${err}`)
interaction.reply('**Database error:**\nTry inserting an URL first.')
}
}else{
const verifyURL = address.match(/dedicated-server-stats/)
if (!verifyURL) 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=')
try{
console.log(`MPDB | URL for ${interaction.guild.name} has been updated by ${interaction.member.displayName} (${interaction.member.id})`);
const Url = await MPDB.create({
serverId: interaction.guildId,
ip: newURL[0],
code: newURL[1],
timesUpdated: 0
});
return interaction.reply(`Successfully set the URL to ${Url.ip}`)
} catch(err){
if (err.name == 'SequelizeUniqueConstraintError'){
const AffectedRows = await MPDB.update({ip: newURL[0], code: newURL[1]},{where:{serverId: interaction.guildId}});
await MPDB.increment('timesUpdated',{where:{serverId: interaction.guildId}});
if (AffectedRows) return interaction.reply(`Successfully updated the URL to ${newURL[0]}`)
}else{
console.log(err)
interaction.reply(`\`MPDB\` has caught an error, notify <@&${client.config.mainServer.roles.bottech}>`)
}
}
}
break;
/* case 'series':
const embed3 = new client.embed().setColor(client.config.embedColor).setTitle('How to join the Daggerwin MP series')
.setDescription([
@ -269,6 +307,12 @@ export default {
.addSubcommand((opt)=>opt
.setName('info')
.setDescription('Provides you with server information such as filters and so on'))
.addSubcommand((opt)=>opt
.setName('url')
.setDescription('View the URL for this server\'s FSMP server or update the URL')
.addStringOption((opt)=>opt
.setName('address')
.setDescription('Insert a \'dedicated-server-stats\' URL')))
/* .addSubcommand((opt)=>opt
.setName('series')
.setDescription('Step-by-step on joining Daggerwin\'s MP series')) */