Compare commits

5 Commits

Author SHA1 Message Date
2035710bf7 Fixed Echobox loading mistake 2023-09-03 00:14:46 -05:00
27dd8cadc9 Added Echobox 2023-09-03 00:00:11 -05:00
382ae94168 Added save queue system 2023-09-02 18:54:33 -05:00
d8cbaa4e16 Connection change in HxDiscord update #5e30606 2023-09-02 17:04:48 -05:00
ad064a7d2c Exact date support, @everyone, new aliases 2023-09-02 13:53:28 -05:00
2 changed files with 111 additions and 13 deletions

4
.gitignore vendored
View File

@@ -1,5 +1,7 @@
# ignore all files in export dir # ignore all files in export dir
export/ export/
modules/
# ignore bot settings file # ignore bot settings file
settings.json settings.json
echobox-db.json

View File

@@ -13,9 +13,15 @@ class Onequestionmark {
static var settings:Dynamic; static var settings:Dynamic;
static var botInfo:Dynamic; static var botInfo:Dynamic;
static var iceRegex:EReg = ~/\bicc?ed?\b/i; static var iceRegex:EReg = ~/\bicc?ed?\b/i;
static var hugDB:Array<String>; static var hugDB:Array<String>;
static var motdDB:haxe.DynamicAccess<Dynamic> = {}; static var motdDB:haxe.DynamicAccess<Dynamic> = {};
static var yesnoDB:Dynamic; static var yesnoDB:Dynamic;
static var echoboxDB:haxe.DynamicAccess<Dynamic> = {};
static var saveTimer = Date.now().getMinutes();
static var saveQueue:Array<String> = [];
static function main() { static function main() {
@@ -54,18 +60,29 @@ class Onequestionmark {
yesnoDB = {"yes": [],"no": []}; // Fallback yesnoDB = {"yes": [],"no": []}; // Fallback
} }
if (FileSystem.exists("echobox-db.json")) {
Sys.println('[${timestamp()}] Found echobox-db.json, loading');
echoboxDB = Json.parse(File.getContent("echobox-db.json"));
} else {
Sys.println('[${timestamp()}] Did not find echobox-db.json, generating');
File.saveContent("echobox-db.json", Json.stringify(echoboxDB, "\t"));
}
// Start the bot // Start the bot
Bot = new DiscordClient(settings.token, [3276799], settings.debug); Bot = new DiscordClient(settings.token, [3276799], settings.debug);
Bot.onReady = onReady; Bot.onReady = onReady;
Bot.onMessageCreate = onMessageCreate; Bot.onMessageCreate = onMessageCreate;
botInfo = Endpoints.getCurrentUser(); Bot.connect();
MainLoop.add(motd);
} }
public static function onReady() { public static function onReady() {
Sys.sleep(1);
Sys.println('[${timestamp()}] Bot is online'); Sys.println('[${timestamp()}] Bot is online');
//Endpoints.sendMessage(settings.devchannel, {content:"onequestionmark-chat alpha test is now running"}, null, false); //Endpoints.sendMessage(settings.devchannel, {content:"onequestionmark-chat alpha test is now running"}, null, false);
botInfo = Endpoints.getCurrentUser();
MainLoop.add(motd);
MainLoop.add(saveSystem);
} }
public static function onMessageCreate(m:Message) { public static function onMessageCreate(m:Message) {
@@ -91,7 +108,7 @@ class Onequestionmark {
// Commands that require authorization // Commands that require authorization
case "quit": case "quit":
if (m.author.id == settings.botowner) { if (m.author.id == settings.botowner) {
m.reply({content:"Shutdown command received from botowner, exiting."}, false); m.react('');
Sys.println('[${timestamp()}] Shutdown command received from botowner, exiting'); Sys.println('[${timestamp()}] Shutdown command received from botowner, exiting');
shutdown(); shutdown();
} }
@@ -114,7 +131,7 @@ class Onequestionmark {
settings.motd.channels.remove(m.channel_id); settings.motd.channels.remove(m.channel_id);
m.reply({content:'MOTD has been disabled for <#${m.channel_id}>'}, false); m.reply({content:'MOTD has been disabled for <#${m.channel_id}>'}, false);
} }
saveSettings(); saveQueue.push("settings");
} }
// System for WIP commands that only work in testing server // System for WIP commands that only work in testing server
case "wipcommand": case "wipcommand":
@@ -127,12 +144,25 @@ class Onequestionmark {
**onequestionmark bot commands**\n`?chk`: ack\n`?slap <target>`: The classic mIRC troutslap.\n`?hug <target (optional)>`: Posts randomized hug image.\n`?yes` and `?no`: Posts randomized yes/no.\n`?angery`\n`?subway`\n`?motd`: Enables MOTD for current channel (requires auth)\n`?devmode`: Toggles Dev Mode (requires auth)\n`?quit`: Shutdown command (requires auth)\n**Non-command bot functions:**\n*MOTD*: Bot will post a randomized *Meme of the Day* in enabled channels.\n*Icce*: Bot provides users with ice cuboids.\n*Meteor*: Bot reacts to falling rocks in the chat.'}, false); **onequestionmark bot commands**\n`?chk`: ack\n`?slap <target>`: The classic mIRC troutslap.\n`?hug <target (optional)>`: Posts randomized hug image.\n`?yes` and `?no`: Posts randomized yes/no.\n`?angery`\n`?subway`\n`?motd`: Enables MOTD for current channel (requires auth)\n`?devmode`: Toggles Dev Mode (requires auth)\n`?quit`: Shutdown command (requires auth)\n**Non-command bot functions:**\n*MOTD*: Bot will post a randomized *Meme of the Day* in enabled channels.\n*Icce*: Bot provides users with ice cuboids.\n*Meteor*: Bot reacts to falling rocks in the chat.'}, false);
case "chk": case "chk":
m.reply({content:'<@${m.author.id}>: ack'}, false); m.reply({content:'<@${m.author.id}>: ack'}, false);
case "mrkrabs":
m.reply({content:'<@${m.author.id}>: ack ack ack ack ack'}, false);
case "slap": case "slap":
if (msg.length != 0) {m.reply({content:'*onequestionmark slaps ${msg} around a bit with a large trout*'}, false);} if (msg.length != 0) {m.reply({content:'*onequestionmark slaps ${msg} around a bit with a large trout*'}, false);}
// Basic aliases
case "angery": case "angery":
m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1079518504413311108/angery.jpg"}, false); m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1079518504413311108/angery.jpg"}, false);
case "subway": case "subway":
m.reply({content:"https://www.youtube.com/watch?v=y3VRXVvr6XU"}, false); m.reply({content:"https://www.youtube.com/watch?v=y3VRXVvr6XU"}, false);
case "illuminati":
m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1147204253039984671/illuminati.gif"}, false);
case "cube":
m.reply({content:"https://cdn.discordapp.com/attachments/270113422232911883/502690458779123722/the_cube.jpg"}, false);
case "coolsville":
m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1147583765212835921/coolsville.gif"}, false);
case "tufac":
m.reply({content:"*Not Teh Face, but better,*\n*Tufac to the letter!*\n*Always two faces, never one,*\n*Tufac has you on the run!*"}, false);
case "communism":
m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1147590229960691742/communism.gif"}, false);
// Image database commands // Image database commands
case "hug": case "hug":
m.reply({content:'🫂 *hugs ${msg}*\n${hugDB[randInt(0, hugDB.length-1)]}'}, false); m.reply({content:'🫂 *hugs ${msg}*\n${hugDB[randInt(0, hugDB.length-1)]}'}, false);
@@ -142,12 +172,50 @@ class Onequestionmark {
case "no": case "no":
var no = yesnoDB.no; var no = yesnoDB.no;
m.reply({content:'${no[randInt(0, no.length-1)]}'}, false); m.reply({content:'${no[randInt(0, no.length-1)]}'}, false);
// Echobox
case "echobox":
// Create Echobox array for the server if missing
if (!echoboxDB.exists('server${m.guild_id}')) {
echoboxDB.set('server${m.guild_id}', []);
}
var echobox:Array<String> = echoboxDB.get('server${m.guild_id}');
var quote:String = "";
// Echobox response
if (!m.mention_everyone) {
if (echobox.length > 0) {
var ebchoice = randInt(0, echobox.length-1);
//m.reply({content:'**Echobox, quote #${ebchoice+1}:** ${echobox[ebchoice]}'}, false);
quote = '**Echobox, quote #${ebchoice+1}:** ${echobox[ebchoice]}';
} else {
//m.reply({content:'**Echobox:** There are no quotes in this server\'s Echobox yet.'}, false);
quote = '**Echobox:** There are no quotes in this server\'s Echobox yet.';
}
// Add quote to Echobox
if (msg.length != 0) {
if (!echobox.contains(msg)) {
echobox.push(msg);
echoboxDB.set('server${m.guild_id}', echobox);
saveQueue.push("echobox");
m.reply({content:quote}, false);
} else {
m.reply({content:'**Echobox:** This quote is already in the database.'}, false);
}
} else {
m.reply({content:quote}, false);
}
} else {
m.reply({content:'**Echobox:** You cannot add `@everyone` to the Echobox.'}, false);
}
} }
} }
// Non-command responses // Non-command responses
if ((msg.charAt(0) == ".") && (msg.length == 1)) {m.reply({content:"omg a meteor"}, true);} if ((msg.charAt(0) == ".") && (msg.length == 1)) {m.reply({content:"omg a meteor"}, true);}
if ((iceRegex.match(msg)) && (m.author.id != botInfo.id)) {m.reply({content:"Did some carbon-based lifeform just say **I C E**?"});} if ((iceRegex.match(msg)) && (m.author.id != botInfo.id)) {m.reply({content:"Did some carbon-based lifeform just say **I C E**?"});}
if ((m.mention_everyone == true) && (msg.charAt(0) != "?")) {m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1147598637241741343/at_everyone.jpg"}, true);}
} }
} }
@@ -235,13 +303,17 @@ class Onequestionmark {
if ((settings.motd.posted == false) && (Date.now().getHours() >= settings.motd.time)) { if ((settings.motd.posted == false) && (Date.now().getHours() >= settings.motd.time)) {
settings.motd.posted = true; settings.motd.posted = true;
saveSettings(); saveQueue.push("settings");
var msg = ""; var msg = "";
var day:Array<String> = []; var day:Array<String> = [];
// Check for special date // Check for exact date
if (motdDB.exists(monthdate())) { if (motdDB.exists('${monthdate()}-${Date.now().getFullYear()}')) {
day = motdDB.get('${monthdate()}-${Date.now().getFullYear()}');
}
// Else, check for special date
else if (motdDB.exists(monthdate())) {
day = motdDB.get(monthdate()); day = motdDB.get(monthdate());
} }
// Else, check for special day/date combo // Else, check for special day/date combo
@@ -261,18 +333,42 @@ class Onequestionmark {
} }
} }
// General functions // Filesystem operations
public static function randInt(x, y) { public static function saveSystem() {
// Return a random integer between x and y, both inclusive if (saveTimer != Date.now().getMinutes()) { // We only want to run this once a minute
return Std.random((y+1)-x)+x;
if (saveQueue.length > 0) { // See if there's anything in the queue
switch (saveQueue.shift()) {
case "settings":
saveSettings();
Sys.println('[${timestamp()}] Saved settings.json');
case "echobox":
saveEchoboxDB();
Sys.println('[${timestamp()}] Saved echobox-db.json');
}
}
saveTimer = Date.now().getMinutes(); // Update timer
}
} }
public static function saveSettings() { public static function saveSettings() {
File.saveContent("settings.json", Json.stringify(settings, "\t")); File.saveContent("settings.json", Json.stringify(settings, "\t"));
} }
public static function saveEchoboxDB() {
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();
Sys.exit(0); Sys.exit(0);
} }
} }