From 62f13c5f9de078fc5a3f8578a46ff988a08f8287 Mon Sep 17 00:00:00 2001 From: Izwzyzx <184772711+Izwzyzx@users.noreply.github.com> Date: Mon, 27 Feb 2023 20:28:19 -0600 Subject: [PATCH] Added MOTD function --- Onequestionmark.hx | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/Onequestionmark.hx b/Onequestionmark.hx index ec280d3..b6fdad8 100644 --- a/Onequestionmark.hx +++ b/Onequestionmark.hx @@ -1,6 +1,7 @@ import hxdiscord.DiscordClient; import hxdiscord.types.*; import hxdiscord.endpoints.Endpoints; +import haxe.MainLoop; import haxe.Json; import sys.io.File; import sys.FileSystem; @@ -30,6 +31,8 @@ class Onequestionmark { Bot.onReady = onReady; Bot.onMessageCreate = onMessageCreate; botInfo = Endpoints.getCurrentUser(); + + MainLoop.add(motd); } public static function onReady() { @@ -110,10 +113,56 @@ 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)}'; + } + + 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 = 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() { File.saveContent("settings.json", Json.stringify(settings, "\t")); }