Added Echobox
This commit is contained in:
parent
382ae94168
commit
27dd8cadc9
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ modules/
|
|||||||
|
|
||||||
# ignore bot settings file
|
# ignore bot settings file
|
||||||
settings.json
|
settings.json
|
||||||
|
echobox-db.json
|
@ -13,9 +13,11 @@ 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 saveTimer = Date.now().getMinutes();
|
||||||
static var saveQueue:Array<String> = [];
|
static var saveQueue:Array<String> = [];
|
||||||
@ -58,6 +60,14 @@ class Onequestionmark {
|
|||||||
yesnoDB = {"yes": [],"no": []}; // Fallback
|
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
|
// 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;
|
||||||
@ -161,6 +171,43 @@ 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,6 +341,9 @@ class Onequestionmark {
|
|||||||
case "settings":
|
case "settings":
|
||||||
saveSettings();
|
saveSettings();
|
||||||
Sys.println('[${timestamp()}] Saved settings.json');
|
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"));
|
File.saveContent("settings.json", Json.stringify(settings, "\t"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function saveEchoboxDB() {
|
||||||
|
File.saveContent("echobox-db.json", Json.stringify(echoboxDB, "\t"));
|
||||||
|
}
|
||||||
|
|
||||||
// General functions
|
// General functions
|
||||||
public static function randInt(x, y) {
|
public static function randInt(x, y) {
|
||||||
// Return a random integer between x and y, both inclusive
|
// Return a random integer between x and y, both inclusive
|
||||||
@ -313,6 +367,7 @@ class Onequestionmark {
|
|||||||
|
|
||||||
public static function shutdown() {
|
public static function shutdown() {
|
||||||
saveSettings();
|
saveSettings();
|
||||||
|
saveEchoboxDB();
|
||||||
Sys.exit(0);
|
Sys.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user