Added MOTD exclusion system

This commit is contained in:
Izwzyzx 2024-10-27 16:05:44 -05:00
parent 7162eb7d93
commit 729d6b41be
2 changed files with 38 additions and 12 deletions

View File

@ -1,6 +1,7 @@
# Changelog # Changelog
## Release Version 1.2 ## Release Version 1.2
- Added system to prevent MOTD from chosing the same daily result consecutively
- Added support for MOTDs matching only the date - Added support for MOTDs matching only the date
- General purpose functions have been split off into IzzComLib - General purpose functions have been split off into IzzComLib
- Improved fallbacks for file-reading commands - Improved fallbacks for file-reading commands

View File

@ -149,6 +149,11 @@ class Onequestionmark {
} }
case "motd": case "motd":
if (m.author.id == settings.botowner) { if (m.author.id == settings.botowner) {
if (args.length != 0) {
if (args[0] == "force") {
m.reply({content:'${getMotd(true)}'}, false);
}
} else {
if (!settings.motd.channels.contains(m.channel_id)) { if (!settings.motd.channels.contains(m.channel_id)) {
settings.motd.channels.push(m.channel_id); settings.motd.channels.push(m.channel_id);
m.reply({content:'MOTD has been enabled for <#${m.channel_id}>'}, false); m.reply({content:'MOTD has been enabled for <#${m.channel_id}>'}, false);
@ -158,6 +163,7 @@ class Onequestionmark {
} }
saveQueue.push("settings"); saveQueue.push("settings");
} }
}
// System for WIP commands that only work in testing server // System for WIP commands that only work in testing server
case "wipcommand": case "wipcommand":
if (m.guild_id == settings.devserver) { if (m.guild_id == settings.devserver) {
@ -355,8 +361,8 @@ class Onequestionmark {
if (now.getHours() >= settings.motd.time) { if (now.getHours() >= settings.motd.time) {
if (settings.motd.date != datestamp()) { if (settings.motd.date != datestamp()) {
settings.motd.date = datestamp(); settings.motd.date = datestamp();
saveQueue.push("settings");
postMotd(); postMotd();
saveQueue.push("settings");
} }
nextPost = DateTools.delta(nextPost, 86400000); // Add one day in milliseconds nextPost = DateTools.delta(nextPost, 86400000); // Add one day in milliseconds
} }
@ -366,15 +372,15 @@ class Onequestionmark {
Timer.delay(function(){ Timer.delay(function(){
settings.motd.date = datestamp(); settings.motd.date = datestamp();
saveQueue.push("settings");
postMotd(); postMotd();
saveQueue.push("settings");
// Start the looped MOTD timer // Start the looped MOTD timer
motdTimer = new Timer(86400000); motdTimer = new Timer(86400000);
motdTimer.run = function() { motdTimer.run = function() {
settings.motd.date = datestamp(); settings.motd.date = datestamp();
saveQueue.push("settings");
postMotd(); postMotd();
saveQueue.push("settings");
} }
}, delay); }, delay);
} }
@ -385,7 +391,7 @@ class Onequestionmark {
* May just move this code into the places it's needed instead of keeping this function. * May just move this code into the places it's needed instead of keeping this function.
*/ */
public static function postMotd() { public static function postMotd() {
var msg = getMotd(); var msg = getMotd(true);
var channels:Array<String> = settings.motd.channels; // Because it won't let me do this directly var channels:Array<String> = 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);}}} 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. * 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 msg = "";
var day:Array<String> = []; var day:Array<String> = [];
var special = true;
// Check for exact date // Check for exact date
if (motdDB.exists('${datestamp()}')) { if (motdDB.exists('${datestamp()}')) {
@ -418,9 +427,25 @@ class Onequestionmark {
// Otherwise, post daily meme // Otherwise, post daily meme
else if (motdDB.exists(printDay().substr(0,3))) { else if (motdDB.exists(printDay().substr(0,3))) {
day = motdDB.get(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<Int> = 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; return msg;
} }