Added Echobox

This commit is contained in:
Izwzyzx 2023-09-03 00:00:11 -05:00
parent 382ae94168
commit 27dd8cadc9
2 changed files with 57 additions and 1 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@ export/
modules/
# ignore bot settings file
settings.json
settings.json
echobox-db.json

View File

@ -13,9 +13,11 @@ class Onequestionmark {
static var settings:Dynamic;
static var botInfo:Dynamic;
static var iceRegex:EReg = ~/\bicc?ed?\b/i;
static var hugDB:Array<String>;
static var motdDB:haxe.DynamicAccess<Dynamic> = {};
static var yesnoDB:Dynamic;
static var echoboxDB:haxe.DynamicAccess<Dynamic> = {};
static var saveTimer = Date.now().getMinutes();
static var saveQueue:Array<String> = [];
@ -58,6 +60,14 @@ class Onequestionmark {
yesnoDB = {"yes": [],"no": []}; // Fallback
}
if (FileSystem.exists("echobox-db.json")) {
Sys.println('[${timestamp()}] Found echobox-db.json, loading');
yesnoDB = 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
Bot = new DiscordClient(settings.token, [3276799], settings.debug);
Bot.onReady = onReady;
@ -161,6 +171,43 @@ class Onequestionmark {
case "no":
var no = yesnoDB.no;
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);
}
}
}
@ -294,6 +341,9 @@ class Onequestionmark {
case "settings":
saveSettings();
Sys.println('[${timestamp()}] Saved settings.json');
case "echobox":
saveEchoboxDB();
Sys.println('[${timestamp()}] Saved echobox-db.json');
}
}
@ -305,6 +355,10 @@ class Onequestionmark {
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
@ -313,6 +367,7 @@ class Onequestionmark {
public static function shutdown() {
saveSettings();
saveEchoboxDB();
Sys.exit(0);
}
}