Moved general purpose functions to IzzComLib

This commit is contained in:
Izwzyzx 2024-10-16 18:55:09 -05:00
parent 193f7f2bf8
commit be2d5661d4
3 changed files with 15 additions and 94 deletions

View File

@ -5,6 +5,7 @@ import haxe.MainLoop;
import haxe.Json; import haxe.Json;
import sys.io.File; import sys.io.File;
import sys.FileSystem; import sys.FileSystem;
import izzcomlib.IzzComLib.*;
using StringTools; using StringTools;
class Onequestionmark { class Onequestionmark {
@ -335,82 +336,7 @@ class Onequestionmark {
} }
} }
// Time-related functions // MOTD system
public static function timestamp() {
return '${StringTools.lpad(Std.string(Date.now().getHours()), "0", 2)}:${StringTools.lpad(Std.string(Date.now().getMinutes()), "0", 2)}';
}
public static function datestamp() {
return '${StringTools.lpad(Std.string(Date.now().getMonth()+1), "0", 2)}-${StringTools.lpad(Std.string(Date.now().getDate()), "0", 2)}';
}
// Clean print day of week
public static function checkDay() {
var day = "";
switch (Date.now().getDay()+1) {
case 1:
day = "sun";
case 2:
day = "mon";
case 3:
day = "tues";
case 4:
day = "wed";
case 5:
day = "thurs";
case 6:
day = "fri";
case 7:
day = "sat";
}
return day;
}
// Clean print month
public static function checkMonth() {
var month = "";
switch (Date.now().getMonth()+1) {
case 1:
month = "jan";
case 2:
month = "feb";
case 3:
month = "mar";
case 4:
month = "apr";
case 5:
month = "may";
case 6:
month = "jun";
case 7:
month = "jul";
case 8:
month = "aug";
case 9:
month = "sep";
case 10:
month = "oct";
case 11:
month = "nov";
case 12:
month = "dec";
}
return month;
}
//Get current day of month, padded
public static function checkDate() {
return StringTools.lpad(Std.string(Date.now().getDate()), "0", 2);
}
public static function monthdate() {
return '${checkMonth()}${checkDate()}';
}
public static function weekdate() {
return '${checkDay()}${checkDate()}';
}
public static function motd() { public static function motd() {
if (settings.motd.date != datestamp()) { if (settings.motd.date != datestamp()) {
settings.motd.date = datestamp(); settings.motd.date = datestamp();
@ -425,20 +351,20 @@ class Onequestionmark {
var day:Array<String> = []; var day:Array<String> = [];
// Check for exact date // Check for exact date
if (motdDB.exists('${monthdate()}-${Date.now().getFullYear()}')) { if (motdDB.exists('${datestamp()}')) {
day = motdDB.get('${monthdate()}-${Date.now().getFullYear()}'); day = motdDB.get('${datestamp()}');
} }
// Else, check for special date // Else, check for special date
else if (motdDB.exists(monthdate())) { else if (motdDB.exists('${printMonth().toLowerCase().substr(0,3)}${printDate()}')) {
day = motdDB.get(monthdate()); day = motdDB.get('${printMonth().toLowerCase().substr(0,3)}${printDate()}');
} }
// Else, check for special day/date combo // Else, check for special day/date combo
else if (motdDB.exists(weekdate())) { else if (motdDB.exists('${printDay().toLowerCase().substr(0,3)}${printDate()}')) {
day = motdDB.get(weekdate()); day = motdDB.get('${printDay().toLowerCase().substr(0,3)}${printDate()}');
} }
// Otherwise, post daily meme // Otherwise, post daily meme
else if (motdDB.exists(checkDay())) { else if (motdDB.exists(printDay().toLowerCase().substr(0,3))) {
day = motdDB.get(checkDay()); day = motdDB.get(printDay().toLowerCase().substr(0,3));
} }
if (day.length > 0) {msg = day[randInt(0, day.length-1)];} if (day.length > 0) {msg = day[randInt(0, day.length-1)];}
@ -476,12 +402,6 @@ class Onequestionmark {
File.saveContent("echobox-db.json", Json.stringify(echoboxDB, "\t")); File.saveContent("echobox-db.json", Json.stringify(echoboxDB, "\t"));
} }
// General functions
public static function randInt(x, y) {
// Return a random integer between x and y, both inclusive
return Std.random((y+1)-x)+x;
}
public static function shutdown() { public static function shutdown() {
saveSettings(); saveSettings();
saveEchoboxDB(); saveEchoboxDB();

View File

@ -1,5 +1,6 @@
-m Onequestionmark -m Onequestionmark
-L hxdiscord -L hxdiscord
-L IzzComLib
# hxdiscord uses deprecated functions # hxdiscord uses deprecated functions
-D no-deprecation-warnings -D no-deprecation-warnings
--neko export/onequestionmark.n --neko export/onequestionmark.n

View File

@ -6,13 +6,13 @@
"mon": [ "mon": [
"Monday Event" "Monday Event"
], ],
"tues": [ "tue": [
"Tuesday Event" "Tuesday Event"
], ],
"wed": [ "wed": [
"Wednesday Event" "Wednesday Event"
], ],
"thurs": [ "thu": [
"Thursday Event" "Thursday Event"
], ],
"fri": [ "fri": [
@ -27,8 +27,8 @@
"jan01": [ "jan01": [
"Example event to be triggered on January 1st." "Example event to be triggered on January 1st."
], ],
"jan01-2000": [ "2000-01-01": [
"Example event to be triggered specifically on January 1st, 2000.", "Example event to be triggered specifically on January 1st, 2000. (YYYY-MM-DD)",
"Entries that are more specific take precedence over less-specific entries." "Entries that are more specific take precedence over less-specific entries."
] ]
} }