From 4c4013612ebec320c1a8e9b2b3ae449827d3c3ab Mon Sep 17 00:00:00 2001 From: Izwzyzx <184772711+Izwzyzx@users.noreply.github.com> Date: Mon, 4 Sep 2023 18:44:46 -0500 Subject: [PATCH] Added command args and gaming commands --- Onequestionmark.hx | 73 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/Onequestionmark.hx b/Onequestionmark.hx index c9ec9d3..c69af91 100644 --- a/Onequestionmark.hx +++ b/Onequestionmark.hx @@ -89,10 +89,13 @@ class Onequestionmark { // DevMode check if ((!settings.devmode) || (m.guild_id == settings.devserver)) { var msg = m.content; + var sender:String; + if (m.getMember().nick == null) {sender = m.author.global_name;} else {sender = m.getMember().nick;} // Command processor if (msg.charAt(0) == "?") { var command = ""; + var args:Array = []; if (msg.indexOf(" ") != -1) { // Separate command from rest of message, if necessary @@ -104,6 +107,12 @@ class Onequestionmark { msg = ""; } + // Separate arguments from command + if (command.indexOf(".") != -1) { + args = command.substring(command.indexOf(".")+1).toLowerCase().split("."); + command = command.substring(0, command.indexOf(".")).toLowerCase(); + } + switch (command) { // Commands that require authorization case "quit": @@ -148,6 +157,66 @@ class Onequestionmark { m.reply({content:'<@${m.author.id}>: ack ack ack ack ack'}, false); case "slap": if (msg.length != 0) {m.reply({content:'*onequestionmark slaps ${msg} around a bit with a large trout*'}, 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); + // Gaming functions + case "coin": + if ((msg.length == 0) || (Std.parseInt(msg) == null) || (Std.parseInt(msg) == 1)) { + var coin = randInt(0,1); + if (coin == 1) { + m.reply({content:'${sender} flipped a coin and got heads.'}, false); + } else { + m.reply({content:'${sender} flipped a coin and got tails.'}, false); + } + } else { + if ((Std.parseInt(msg) > 1) && (Std.parseInt(msg) < 101)) { + var heads:Int = 0; + for (i in 1...(Std.parseInt(msg)+1)) { + heads += randInt(0,1); + } + //'Flipped ${heads} heads, ${Std.parseInt(msg)-heads} tails.' + m.reply({content:'${sender} flipped ${Std.parseInt(msg)} coins.\n**Heads:** ${heads}\n**Tails:** ${Std.parseInt(msg)-heads}'}, false); + } else { + m.reply({content:'Please enter a value between 1 and 100.'}, false); + } + } + case "dice": + var sides:Int = 6; + + // Set number of sides + if (args.length != 0) { + if (Std.parseInt(args[0]) != null) { + sides = Std.parseInt(args[0]); + } + } + + // Validate sides + if (sides == 1) { + m.reply({content:'${sender} rolled a ball or something, idk.'}, false); + } else if (sides == 2) { + m.reply({content:'${sender} tried to roll a 2-sided die (this is called a coin btw).'}, false); + } else if ((sides < 1) || (sides > 100)) { + m.reply({content:'Please enter a value between 1 and 100.'}, false); + } else { + // Roll a single die + if ((msg.length == 0) || (Std.parseInt(msg) == null) || (Std.parseInt(msg) == 1)) { + m.reply({content:'${sender} rolled a ${sides}-sided die and got ${randInt(1,sides)}.'}, false); + } else { + // Roll multiple dice + if ((Std.parseInt(msg) > 1) && (Std.parseInt(msg) < 101)) { + var results:Array = []; + for (i in 1...(Std.parseInt(msg)+1)) { + results.push(randInt(1,sides)); + } + // Sort results high-to-low + results.sort((a, b) -> b - a); + + m.reply({content:'${sender} rolled a ${sides}-sided die ${Std.parseInt(msg)} times.\n**Results:** ${results.toString()}'}, false); + } else { + m.reply({content:'Please enter a value between 1 and 100.'}, false); + } + } + } // Basic aliases case "angery": m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1079518504413311108/angery.jpg"}, false); @@ -159,10 +228,10 @@ class Onequestionmark { 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); + case "opinions": + m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1147983375701921892/opinions.jpg"}, false); // Image database commands case "hug": m.reply({content:'🫂 *hugs ${msg}*\n${hugDB[randInt(0, hugDB.length-1)]}'}, false);