From 729d6b41be3aee8ba010cdb634e36a2913032dfe Mon Sep 17 00:00:00 2001 From: Izwzyzx <184772711+Izwzyzx@users.noreply.github.com> Date: Sun, 27 Oct 2024 16:05:44 -0500 Subject: [PATCH] Added MOTD exclusion system --- CHANGELOG.md | 1 + Onequestionmark.hx | 49 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e83aa6..bbd1c92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Release Version 1.2 +- Added system to prevent MOTD from chosing the same daily result consecutively - Added support for MOTDs matching only the date - General purpose functions have been split off into IzzComLib - Improved fallbacks for file-reading commands diff --git a/Onequestionmark.hx b/Onequestionmark.hx index b0ab918..bed2635 100644 --- a/Onequestionmark.hx +++ b/Onequestionmark.hx @@ -149,14 +149,20 @@ class Onequestionmark { } case "motd": if (m.author.id == settings.botowner) { - if (!settings.motd.channels.contains(m.channel_id)) { - settings.motd.channels.push(m.channel_id); - m.reply({content:'MOTD has been enabled for <#${m.channel_id}>'}, false); + if (args.length != 0) { + if (args[0] == "force") { + m.reply({content:'${getMotd(true)}'}, false); + } } else { - settings.motd.channels.remove(m.channel_id); - m.reply({content:'MOTD has been disabled for <#${m.channel_id}>'}, false); + if (!settings.motd.channels.contains(m.channel_id)) { + settings.motd.channels.push(m.channel_id); + m.reply({content:'MOTD has been enabled for <#${m.channel_id}>'}, false); + } else { + settings.motd.channels.remove(m.channel_id); + m.reply({content:'MOTD has been disabled for <#${m.channel_id}>'}, false); + } + saveQueue.push("settings"); } - saveQueue.push("settings"); } // System for WIP commands that only work in testing server case "wipcommand": @@ -355,8 +361,8 @@ class Onequestionmark { if (now.getHours() >= settings.motd.time) { if (settings.motd.date != datestamp()) { settings.motd.date = datestamp(); - saveQueue.push("settings"); postMotd(); + saveQueue.push("settings"); } nextPost = DateTools.delta(nextPost, 86400000); // Add one day in milliseconds } @@ -366,15 +372,15 @@ class Onequestionmark { Timer.delay(function(){ settings.motd.date = datestamp(); - saveQueue.push("settings"); postMotd(); + saveQueue.push("settings"); // Start the looped MOTD timer motdTimer = new Timer(86400000); motdTimer.run = function() { settings.motd.date = datestamp(); - saveQueue.push("settings"); postMotd(); + saveQueue.push("settings"); } }, delay); } @@ -385,7 +391,7 @@ class Onequestionmark { * May just move this code into the places it's needed instead of keeping this function. */ public static function postMotd() { - var msg = getMotd(); + var msg = getMotd(true); var channels:Array = settings.motd.channels; // Because it won't let me do this directly if (channels.length > 0) {for (i in channels) {if (msg.length > 0) {Endpoints.sendMessage(i, {content:msg}, null, false);}}} @@ -394,10 +400,13 @@ class Onequestionmark { /** * This function checks the MOTD database to find the entry most relevant to the current date and returns the appropriate data. + * + * @param update Whether the result should be stored to exclude from the next run. */ - public static function getMotd() { + public static function getMotd(update:Bool = false) { var msg = ""; var day:Array = []; + var special = true; // Check for exact date if (motdDB.exists('${datestamp()}')) { @@ -418,9 +427,25 @@ class Onequestionmark { // Otherwise, post daily meme else if (motdDB.exists(printDay().substr(0,3))) { day = motdDB.get(printDay().substr(0,3)); + special = false; } - if (day.length > 0) {msg = day[randInt(0, day.length-1)];} + //if (day.length > 0) {msg = day[randInt(0, day.length-1)];} + if (day.length > 0) { + if (update && !special && (day.length > 2)) { + var today = Date.now().getDay(); + var previous:Array = settings.motd.previous; + + var choice = randIntExclude(0, day.length-1,[previous[today]]); + + previous[today] = choice; + settings.motd.previous = previous; + + msg = day[choice]; + } else { + msg = day[randInt(0, day.length-1)]; + } + } return msg; }