diff --git a/src/commands/commands/fun/magic8ball.ts b/src/commands/commands/fun/magic8ball.ts new file mode 100644 index 0000000..b12f01d --- /dev/null +++ b/src/commands/commands/fun/magic8ball.ts @@ -0,0 +1,66 @@ +import { Command } from "../../Command"; +import crypto from "crypto"; + +// Possible answers +const answers = [ + "It is certain", + "It is decidedly so", + "Without a doubt", + "Yes, definitely", + "You may rely on it", + "As I see it, yes", + "Most likely", + "Outlook good", + "Yes", + "Signs point to yes", + "Reply hazy, try again", + "Ask again later", + "Better not tell you now", + "Cannot predict now", + "Concentrate and ask again", + `Don't count on it`, + "My reply is no", + "My sources say no", + "Outlook not so good", + "Very doubtful" +]; + +export const magic8ball = new Command( + "magic8ball", + ["magic8ball", "8ball", "8"], + "magic8ball bozo", + "magic8ball ", + (msg, agent) => { + /** + * Magic 8 ball command + * + * Returns a unique answer for every question asked. + */ + + // Check arguments + // We're not checking for question marks since the user might think that's too much work + if (!msg.argv[1]) return `🎱 Ask me a question, dummy`; + + // Hash the question (the user will get the same response for repeated questions) + // We use a predictable but unique salt (security by obscurity?) + const hash = crypto.createHash("sha-256"); + hash.update("magic" + msg.argv[1] + "8ball"); + + // Use the question hash as the index + const hex = hash.digest("hex"); + let index = parseInt(hex[0] + hex[1] + hex[2], 16); + + // Make sure the index is within the bounds of the answers array + while (index >= answers.length) { + index -= answers.length; + } + + while (index <= 0) { + index += answers.length; + } + + // Answer the user's question + let answer = answers[index]; + return `🎱 ${answer}, ${msg.p.name}`; + } +); diff --git a/src/commands/index.ts b/src/commands/index.ts index 9c2b671..8716eea 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -6,12 +6,18 @@ import { id } from "./commands/utility/id"; import { msg } from "./commands/utility/msg"; import { math } from "./commands/utility/math"; import { memory } from "./commands/utility/memory"; +import { magic8ball } from "./commands/fun/magic8ball"; export function loadCommands() { + // cringe const general = new CommandGroup("general", "⭐ General"); general.addCommands([help, about]); CommandHandler.addCommandGroup(general); + const fun = new CommandGroup("fun", "✨ Fun"); + fun.addCommands([magic8ball]); + CommandHandler.addCommandGroup(fun); + const utility = new CommandGroup("utility", "🔨 Utility"); utility.addCommands([math, memory, id, msg]); CommandHandler.addCommandGroup(utility); diff --git a/src/services/switchchat/index.ts b/src/services/switchchat/index.ts index f6a27a9..81c1f33 100644 --- a/src/services/switchchat/index.ts +++ b/src/services/switchchat/index.ts @@ -23,6 +23,8 @@ export class SwitchChatAgent extends ServiceAgent { this.client.defaultName = this.desiredUser.name; this.client.defaultFormattingMode = "markdown"; + + console.log("SwitchChat owner only mode:", config.ownerOnly); } public start() {