refactor/only free armbands for related commands
This commit is contained in:
1 file changed
+19
-14
+19
-14
@@ -93,23 +93,28 @@ class DayzRBot extends Client {
|
||||
);
|
||||
}
|
||||
|
||||
for (const [factionID, data] of Object.entries(GuildDB.factionArmbands)) {
|
||||
const guild = this.guilds.cache.get(GuildDB.serverID);
|
||||
const role = guild.roles.cache.find(role => role.id == factionID);
|
||||
if (!role) {
|
||||
let query = {
|
||||
$pull: { 'server.usedArmbands': data.armband },
|
||||
$unset: { [`server.factionArmbands.${factionID}`]: "" },
|
||||
};
|
||||
this.dbo.collection("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, query, (err, res) => {
|
||||
if (err) return this.sendInternalError(interaction, err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const command = interaction.data.name.toLowerCase();
|
||||
const args = interaction.data.options;
|
||||
|
||||
// Free unused armbands for any command required
|
||||
if (['armbands', 'claim', 'factions'].includes(command)) {
|
||||
for (const [factionID, data] of Object.entries(GuildDB.factionArmbands)) {
|
||||
const guild = client.guilds.cache.get(GuildDB.serverID);
|
||||
const role = guild.roles.cache.find(role => role.id == factionID);
|
||||
if (!role) {
|
||||
let query = {
|
||||
$pull: { 'server.usedArmbands': data.armband },
|
||||
$unset: { [`server.factionArmbands.${factionID}`]: "" },
|
||||
};
|
||||
await client.dbo.collection("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, query, (err, res) => {
|
||||
if (err) return client.sendInternalError(interaction, err);
|
||||
});
|
||||
} else {
|
||||
newFactionArmbands[`${factionID}`] = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.log(`Interaction [${interaction.guild_id}] - ${command}`);
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(this.config.Token);
|
||||
|
||||
Reference in new issue
Block a user