From 12a6fbf7dcc27b54fc08f125674f87485f3a4cee Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Thu, 12 Jan 2023 16:38:23 +1100 Subject: [PATCH] Merge the command to /mp --- src/commands/fsurl.ts | 53 ------------------------------------------- src/commands/mp.ts | 46 ++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 54 deletions(-) delete mode 100644 src/commands/fsurl.ts diff --git a/src/commands/fsurl.ts b/src/commands/fsurl.ts deleted file mode 100644 index 4532cf6..0000000 --- a/src/commands/fsurl.ts +++ /dev/null @@ -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')) -} \ No newline at end of file diff --git a/src/commands/mp.ts b/src/commands/mp.ts index 854c865..6c9900a 100644 --- a/src/commands/mp.ts +++ b/src/commands/mp.ts @@ -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,7 +307,13 @@ export default { .addSubcommand((opt)=>opt .setName('info') .setDescription('Provides you with server information such as filters and so on')) - /* .addSubcommand((opt)=>opt + .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')) */ } \ No newline at end of file