Added timestamps to console output

This commit is contained in:
Izwzyzx 2023-02-26 17:53:53 -06:00
parent d70f4ab2ce
commit 21616aeaaf

View File

@ -4,6 +4,7 @@ import hxdiscord.endpoints.Endpoints;
import haxe.Json;
import sys.io.File;
import sys.FileSystem;
using StringTools;
class Onequestionmark {
static var Bot:DiscordClient;
@ -12,13 +13,13 @@ class Onequestionmark {
static function main() {
// Init
Sys.println("onequestionmark-chat startup\r\n");
Sys.println('[${timestamp()}] Starting onequestionmark-chat');
if (FileSystem.exists("settings.json")) {
Sys.println("Found settings.json, loading.\r\n");
Sys.println('[${timestamp()}] Found settings.json, loading');
settings = Json.parse(File.getContent("settings.json"));
} else {
Sys.println("Did not find settings.json, exiting.");
Sys.println('[${timestamp()}] Did not find settings.json, exiting');
Sys.exit(0);
}
@ -29,7 +30,7 @@ class Onequestionmark {
}
public static function onReady() {
Sys.println("onequestionmark is online.");
Sys.println('[${timestamp()}] Bot is online');
//Endpoints.sendMessage(settings.devchannel, {content:"onequestionmark-chat alpha test is now running"}, null, false);
}
@ -57,7 +58,7 @@ class Onequestionmark {
case "quit":
if (m.author.id == settings.botowner) {
m.reply({content:"Shutdown command received from botowner, exiting."}, false);
Sys.println("Shutdown command received from botowner, exiting.");
Sys.println('[${timestamp()}] Shutdown command received from botowner, exiting');
shutdown();
}
case "devmode":
@ -105,6 +106,10 @@ class Onequestionmark {
}
}
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 saveSettings() {
File.saveContent("settings.json", Json.stringify(settings, "\t"));
}