From 9a3178d002d562c711a3987bf03a116899409835 Mon Sep 17 00:00:00 2001 From: Cesium Date: Wed, 25 Feb 2026 15:30:22 -0500 Subject: [PATCH] decide what notify level --- commands/bot/crimeNotify.js | 59 +++++++++++++++++++++++++++++++++++++ tasks/unavailableOC.js | 17 +++++++++-- 2 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 commands/bot/crimeNotify.js diff --git a/commands/bot/crimeNotify.js b/commands/bot/crimeNotify.js new file mode 100644 index 0000000..5d8249f --- /dev/null +++ b/commands/bot/crimeNotify.js @@ -0,0 +1,59 @@ +const { SlashCommandBuilder, MessageFlags } = require('discord.js'); +const config = require('../../config.json'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('crimenotify') + .setDescription('Options for crime level empty alerts') + .addSubcommand(subcommand => + subcommand.setName('set') + .setDescription('Decide if a specific crime level will trigger an alert when empty') + .addIntegerOption(option => + option.setName('level') + .setDescription('The crime level to set the alert for.') + .setRequired(true) + .setMinValue(1) + .setMaxValue(10)) + .addBooleanOption(option => + option.setName('notify') + .setDescription('Whether to notify when this crime level is empty.') + .setRequired(true)) + ) + .addSubcommand(subcommand => + subcommand.setName('list') + .setDescription('List all crime levels and whether they trigger an alert when empty.') + ), + async execute(interaction) { + const subcommand = interaction.options.getSubcommand(); + + if (subcommand === 'list') { + let message = 'Crime levels and whether they trigger an alert when empty:\n'; + if (config.crimeNotify) { + for (const level in config.crimeNotify) { + message += `Crime level ${level}/10 will ${config.crimeNotify[level] ? 'notify' : 'not notify'} when empty.\n`; + } + } else { + message += 'No alert overrides set.\n'; + } + await interaction.reply({ content: message, flags: MessageFlags.Ephemeral }); + } else if (subcommand === 'set') { + const level = interaction.options.getInteger('level'); + const notify = interaction.options.getBoolean('notify'); + + if (!config.crimeNotify) { + config.crimeNotify = {}; + } + config.crimeNotify[level] = notify; + + const fs = require('fs'); + const path = require('path'); + try { + fs.writeFileSync(path.join(__dirname, '../../config.json'), JSON.stringify(config, null, 2)); + } catch (error) { + console.error('Failed to save config.json:', error); + } + + await interaction.reply({ content: `Crime level ${level}/10 will ${notify ? 'notify' : 'not notify'} when empty.`, flags: MessageFlags.Ephemeral }); + } + }, +}; \ No newline at end of file diff --git a/tasks/unavailableOC.js b/tasks/unavailableOC.js index 488851a..3c4cdf7 100644 --- a/tasks/unavailableOC.js +++ b/tasks/unavailableOC.js @@ -47,16 +47,27 @@ module.exports = async (client, torn, config) => { } const data = { crimes: crimeList }; data.crimes.forEach(crime => { - crimes.difficulty[crime.difficulty - 1].count++ + if (crime.difficulty >= 1 && crime.difficulty <= factionMaxCrime) { + crimes.difficulty[crime.difficulty - 1].count++ + } }); let isSomethingZero = false; crimes.difficulty.forEach(difficulty => { console.debug(`unavailableOC: ${difficulty.name}: ${difficulty.count}`); if (difficulty.count === 0) { - isSomethingZero = true; + const level = parseInt(difficulty.name); + let shouldNotify = true; + if (config.crimeNotify && config.crimeNotify[level] === false) { + shouldNotify = false; + } + + if (shouldNotify) { + isSomethingZero = true; + } + embed.addFields({ name: `Difficulty ${difficulty.name}`, - value: `Nobody can sign up for ${difficulty.name} crimes!` + value: `Nobody can sign up for ${difficulty.name} crimes!${shouldNotify ? '' : ' (muted)'}` }) } else { embed.addFields({