7.0.3 refactor config command to use switch statement

This commit is contained in:
SowinskiBraeden committed 2023-06-13 14:06:33 -07:00
1 parent e62bacacd3
commit 6cbd545232
2 files changed
+23 -21

No files matched your search

+22 -20
View File
@@ -307,7 +307,8 @@ module.exports = {
if (GuildDB.hasBotAdmin && interaction.member.roles.filter(e => GuildDB.botAdminRoles.indexOf(e) !== -1).length > 0) canUseCommand = true;
if (!canUseCommand) return interaction.send({ content: 'You don\'t have the permissions to use this command.' });
if (args[0].name == 'allowed_channels') {
switch(args[0].name) {
case 'allowed_channels':
const channelid = args[0].options[0].options[0].value;
if (args[0].options[0].name == 'add') {
@@ -355,12 +356,10 @@ module.exports = {
return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
} else client.error('exception?');
} else if (args[0].name == 'bot_admin_role') {
}
case 'bot_admin_role':
if (args[0].options[0].value == 'add') {
const roleId = args[0].options[1].value;
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$push: {"server.botAdminRoles": roleId}}, function(err, res) {
@@ -402,7 +401,7 @@ module.exports = {
return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
}
} else if (args[0].name == 'admin_role') {
case 'admin_role':
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.adminRole": args[0].options[0].value}}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
@@ -413,8 +412,7 @@ module.exports = {
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].name == 'exclude') {
case 'exclude':
if (args[0].options[0].value == 'add') {
client.dbo.collection('guilds').updateOne({'server.serverID': GuildDB.serverID}, {$push: {'server.excludedRoles': args[0].options[1].value}}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
@@ -438,7 +436,7 @@ module.exports = {
return interaction.send({ embeds: [success] });
}
} else if (args[0].name == 'reset') {
case 'reset':
const prompt = new EmbedBuilder()
.setTitle(`Woah!? Hold on.`)
.setDescruotion('Are you sure you wish to remove all your configurations for this guild?')
@@ -458,7 +456,7 @@ module.exports = {
return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
} else if (args[0].name == 'view') {
case 'view':
const channelsInfo = GuildDB.customChannelStatus ? '\n╚➤ \`/channels\` to view' : '';
const channelColor = GuildDB.customChannelStatus ? '+ ' : '- ';
let botAdminRoles = '';
@@ -480,7 +478,8 @@ module.exports = {
);
return interaction.send({ embeds: [settingsEmbed] });
} else if (args[0].name == 'killfeed_channel') {
case 'killfeed_channel':
const channel = args[0].options[0].value;
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.killfeedChannel": channel}}, function(err, res) {
@@ -493,7 +492,7 @@ module.exports = {
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].name == 'admin_logs_channel') {
case 'admin_logs_channel':
const channel = args[0].options[0].value;
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.connectionLogsChannel": channel}}, function(err, res) {
@@ -506,7 +505,7 @@ module.exports = {
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].name == 'welcome_channel') {
case 'welcome_channel':
const channel = args[0].options[0].value;
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.welcomeChannel": channel}}, function(err, res) {
@@ -519,7 +518,7 @@ module.exports = {
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].name == 'active_players_channel') {
case 'active_players_channel':
const channel = args[0].options[0].value;
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.activePlayersChannel": channel}}, function(err, res) {
@@ -532,7 +531,7 @@ module.exports = {
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].name == 'linked_gt_role') {
case 'linked_gt_role':
const role = args[0].options[0].value;
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.linkedGamertagRole": role}}, function(err, res) {
@@ -545,7 +544,7 @@ module.exports = {
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].name == 'member_role') {
case 'member_role':
const role = args[0].options[0].value;
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set: {"server.memberRole": role}}, function(err, res) {
@@ -558,7 +557,7 @@ module.exports = {
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].name == 'starting_balance') {
case 'starting_balance':
client.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID}, {$set: {"server.startingBalance":args[0].options[0].value}}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
@@ -569,7 +568,7 @@ module.exports = {
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].name == 'income_role') {
case 'income_role':
if (args[0].options[0].name== 'set') {
const roleId = args[0].options[0].options[0].value
@@ -640,8 +639,8 @@ module.exports = {
return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
}
}
} else if (args[0].name == 'income_limiter') {
case 'income_limiter':
client.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID}, {$set: {"server.incomeLimiter":args[0].options[0].value}}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
@@ -652,7 +651,7 @@ module.exports = {
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].name == 'uav-price') {
case 'uav-price':
client.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID}, {$set: {"server.uavPrice":args[0].options[0].value}}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
@@ -662,6 +661,9 @@ module.exports = {
.setDescription(`Successfully set $${args[0].options[0].value.toFixed(2)} as UAV price`);
return interaction.send({ embeds: [successEmbed] });
default:
return client.sendInternalError(interaction, 'There was an error parsing the config command');
}
},
},
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "dayz-armbands",
"version": "7.0.2",
"version": "7.0.3",
"description": "A General Purpose Discord Bot for DayZ Servers.",
"main": "index.js",
"nodemonConfig": {