diff --git a/commands/alarm.js b/commands/alarm.js index cf52ca4..3eea6f9 100644 --- a/commands/alarm.js +++ b/commands/alarm.js @@ -125,6 +125,19 @@ module.exports = { value: "enable", type: CommandOptions.SubCommand, }, + { + name: "mute", + description: "Toggle mute on this alarm", + value: "mute", + type: CommandOptions.SubCommand, + options: [{ + name: "toggle", + description: "Turn on or off role pings for this alarm", + value: false, + type: CommandOptions.Boolean, + required: true, + }] + }, { name: "set-rule", description: "Add a Rule to an Alarm", @@ -348,13 +361,11 @@ module.exports = { } else if (args[0].name == 'move-origin') { - if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to configure.')] }); - - let disable = args[0].name == 'disable' ? true : false; + if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to configure.')] }); let alarms = new StringSelectMenuBuilder() .setCustomId(`MoveOrigin-${args[0].options[0].value}-${args[0].options[1].value}-${interaction.member.user.id}`) - .setPlaceholder(`Select an Alarm to ${disable ? 'disable' : 'enable'}.`); + .setPlaceholder(`Select an Alarm to move.`); for (let i = 0; i < GuildDB.alarms.length; i++) { alarms.addOptions({ @@ -368,6 +379,25 @@ module.exports = { return interaction.send({ components: [opt], flags: (1 << 6) }); + } else if (args[0].name == 'mute') { + + if (GuildDB.alarms.length == 0) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Default).setDescription('**Notice:** No Existing Alarms to configure.')] }); + + let alarms = new StringSelectMenuBuilder() + .setCustomId(`MuteAlarm-${args[0].options[0].value ? 1 : 0}-${interaction.member.user.id}`) + .setPlaceholder(`Select an Alarm to mute.`); + + for (let i = 0; i < GuildDB.alarms.length; i++) { + alarms.addOptions({ + label: GuildDB.alarms[i].name, + description: `Mute the role pings of this Alarm`, + value: GuildDB.alarms[i].name, + }) + } + + const opt = new ActionRowBuilder().addComponents(alarms); + + return interaction.send({ components: [opt], flags: (1 << 6) }); } }, }, @@ -639,7 +669,37 @@ module.exports = { return interaction.update({ embeds: [successEmbed], components: [] }); } - } + }, + MuteAlarm: { + run: async(client, interaction, GuildDB) => { + if (!interaction.customId.endsWith(interaction.member.user.id)) { + return interaction.reply({ + content: "This menu is not for you", + flags: (1 << 6) + }) + } + + let alarm = GuildDB.alarms.find(alarm => alarm.name == interaction.values[0]); + let alarmIndex = GuildDB.alarms.indexOf(alarm); + let mute = parseInt(interaction.customId.split('-')[1]); + alarm.mute = mute; + GuildDB.alarms[alarmIndex] = alarm + + client.dbo.collection('guilds').updateOne({ 'server.serverID': GuildDB.serverID }, { + $set: { + 'server.alarms': GuildDB.alarms, + } + }, (err, res) => { + if (err) return client.sendInternalError(interaction, err); + }); + + let successEmbed = new EmbedBuilder() + .setColor(client.config.Colors.Green) + .setDescription(`**Success:** Successfully ${mute?'Muted':'Unmuted'} this alarm.`); + + return interaction.update({ embeds: [successEmbed], components: [] }); + } + } } } diff --git a/package.json b/package.json index 825e775..0be8741 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayzr-bot", - "version": "10.3.8", + "version": "10.4.0", "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", "main": "index.js", "nodemonConfig": { diff --git a/structures/DayzRBot.js b/structures/DayzRBot.js index 6f8a071..61a936e 100644 --- a/structures/DayzRBot.js +++ b/structures/DayzRBot.js @@ -158,10 +158,12 @@ class DayzRBot extends Client { if (lines[i].includes('killed by Zmb') || lines[i].includes('>) died.')) s = await UpdateLastDeathDate(this, s, lines[i]); // Updates users last death date for non PVP deaths. } + // Handle alarm pings for (const [channel_id, data] of Object.entries(this.alarmPingQueue)) { const channel = this.GetChannel(channel_id); for (const [role, embeds] of Object.entries(data)) { - channel.send({ content: `<@&${role}>`, embeds: embeds }); + if (role == '-no-role-ping-') channel.send({ embeds: embeds }); + else channel.send({ content: `<@&${role}>`, embeds: embeds }); } } diff --git a/util/AlarmsHandler.js b/util/AlarmsHandler.js index c6c8cc6..ccbf0d3 100644 --- a/util/AlarmsHandler.js +++ b/util/AlarmsHandler.js @@ -77,10 +77,11 @@ module.exports = { let unixTime = Math.floor(newDt.getTime()/1000); if (!client.alarmPingQueue[alarm.channel]) client.alarmPingQueue[alarm.channel] = {}; - if (!client.alarmPingQueue[alarm.channel][alarm.role]) client.alarmPingQueue[alarm.channel][alarm.role] = []; + let route = alarm.mute ? '-no-role-ping-' : alarm.role; + if (!client.alarmPingQueue[alarm.channel][route]) client.alarmPingQueue[alarm.channel][route] = []; if (alarm.rules.includes['ban_on_entry']) { - client.alarmPingQueue[alarm.channel][alarm.role].push( + client.alarmPingQueue[alarm.channel][route].push( new EmbedBuilder() .setColor(client.config.Colors.Default) .setDescription(`**Zone Ping - **\n**${data.player}** was located within **${distance} meters** of the Zone **${alarm.name}** __and has been banned.__`) @@ -91,7 +92,7 @@ module.exports = { return; } - client.alarmPingQueue[alarm.channel][alarm.role].push( + client.alarmPingQueue[alarm.channel][route].push( new EmbedBuilder() .setColor(client.config.Colors.Default) .setDescription(`**Zone Ping - **\n**${data.player}** was located within **${distance} meters** of the Zone **${alarm.name}**`)