Added MOTD exclusion system
This commit is contained in:
parent
7162eb7d93
commit
729d6b41be
@ -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
|
||||
|
@ -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<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);}}}
|
||||
@ -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<String> = [];
|
||||
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<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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user