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 sys.io.File;
import sys.FileSystem;
import izzcomlib.IzzComLib.*;
using StringTools;
class Onequestionmark {
@ -335,82 +336,7 @@ class Onequestionmark {
}
}
// Time-related functions
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()}';
}
// MOTD system
public static function motd() {
if (settings.motd.date != datestamp()) {
settings.motd.date = datestamp();
@ -425,20 +351,20 @@ class Onequestionmark {
var day:Array<String> = [];
// Check for exact date
if (motdDB.exists('${monthdate()}-${Date.now().getFullYear()}')) {
day = motdDB.get('${monthdate()}-${Date.now().getFullYear()}');
if (motdDB.exists('${datestamp()}')) {
day = motdDB.get('${datestamp()}');
}
// Else, check for special date
else if (motdDB.exists(monthdate())) {
day = motdDB.get(monthdate());
else if (motdDB.exists('${printMonth().toLowerCase().substr(0,3)}${printDate()}')) {
day = motdDB.get('${printMonth().toLowerCase().substr(0,3)}${printDate()}');
}
// Else, check for special day/date combo
else if (motdDB.exists(weekdate())) {
day = motdDB.get(weekdate());
else if (motdDB.exists('${printDay().toLowerCase().substr(0,3)}${printDate()}')) {
day = motdDB.get('${printDay().toLowerCase().substr(0,3)}${printDate()}');
}
// Otherwise, post daily meme
else if (motdDB.exists(checkDay())) {
day = motdDB.get(checkDay());
else if (motdDB.exists(printDay().toLowerCase().substr(0,3))) {
day = motdDB.get(printDay().toLowerCase().substr(0,3));
}
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"));
}
// 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() {
saveSettings();
saveEchoboxDB();

View File

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

View File

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