Added MOTD function

This commit is contained in:
Izwzyzx 2023-02-27 20:28:19 -06:00
parent 88d1a56647
commit 62f13c5f9d

View File

@ -1,6 +1,7 @@
import hxdiscord.DiscordClient; import hxdiscord.DiscordClient;
import hxdiscord.types.*; import hxdiscord.types.*;
import hxdiscord.endpoints.Endpoints; import hxdiscord.endpoints.Endpoints;
import haxe.MainLoop;
import haxe.Json; import haxe.Json;
import sys.io.File; import sys.io.File;
import sys.FileSystem; import sys.FileSystem;
@ -30,6 +31,8 @@ class Onequestionmark {
Bot.onReady = onReady; Bot.onReady = onReady;
Bot.onMessageCreate = onMessageCreate; Bot.onMessageCreate = onMessageCreate;
botInfo = Endpoints.getCurrentUser(); botInfo = Endpoints.getCurrentUser();
MainLoop.add(motd);
} }
public static function onReady() { public static function onReady() {
@ -110,10 +113,56 @@ class Onequestionmark {
} }
} }
// Time-related functions
public static function timestamp() { public static function timestamp() {
return '${StringTools.lpad(Std.string(Date.now().getHours()), "0", 2)}:${StringTools.lpad(Std.string(Date.now().getMinutes()), "0", 2)}'; 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)}';
}
public static function motd() {
if (settings.motd.date != datestamp()) {
settings.motd.date = datestamp();
settings.motd.posted = false;
}
if ((settings.motd.posted == false) && (Date.now().getHours() >= settings.motd.time)) {
settings.motd.posted = true;
var msg = "";
//events
switch (Date.now().getDay()) {
case 0: // Sunday
msg = "Sunday Event.";
case 1: // Monday
msg = "Monday Event.";
case 3: // Tuesday
msg = "Tuesday Event.";
case 4: // Wednesday
msg = "Wednesday Event.";
case 5: // Thursday
msg = "Thursday Event.";
case 6: // Friday
msg = "Friday Event.";
case 7: // Saturday
msg = "Saturday Event.";
}
var channels:Array<String> = settings.motd.channels; // Because it won't let me do this directly
for (i in channels) {
if (msg.length > 0) {Endpoints.sendMessage(i, {content:msg}, null, false);}
}
}
}
// 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 saveSettings() { public static function saveSettings() {
File.saveContent("settings.json", Json.stringify(settings, "\t")); File.saveContent("settings.json", Json.stringify(settings, "\t"));
} }