Skip to content

Instantly share code, notes, and snippets.

@brian6932
Last active January 24, 2024 13:43
Show Gist options
  • Save brian6932/e9cee7c6d1e739b73c1485c652ce7948 to your computer and use it in GitHub Desktop.
Save brian6932/e9cee7c6d1e739b73c1485c652ce7948 to your computer and use it in GitHub Desktop.
const
scramble = `scramble`,
scrambled = scramble + `d`,
admins = new Set()
.add(4333339)
.add(15619810),
rw = async () => {
const cmd = await command.execute(rw.name)
if (!cmd.success)
throw Error(`$${rw.name} \u{2022} ${cmd.reason ?? cmd.reply}`)
return cmd.reply
},
scrambler = word => {
switch (word.length) {
case 1:
return word
case 2:
return word[1] + word[0]
}
const chars = [...word]
for (;;)
for (const i of chars.sort(() => Math.random() - .5).keys())
if (chars[i] !== word[i])
return chars.join(``)
},
nw = async word => {
const
nextWord = await rw(),
scrambledWord = scrambler(nextWord)
channelCustomData.set(scramble, nextWord)
channelCustomData.set(scrambled, scrambledWord)
return `the word was ${word}! ${scrambledWord} is our new word.`
},
commands = {
'-skip': async word => {
if (!(admins.has(executorID) || permissions.get() > 2))
throw Error(`This subcommand is priv-ed to broadcasters, ambassadors, and admins only`)
return `Skipping, ${await nw(word)}`
},
'-rescramble': word => {
const
lastScrambled = channelCustomData.get(scrambled),
nextScrambled = scrambler(word)
channelCustomData.set(scrambled, nextScrambled)
return `Rescrambling, ${lastScrambled} -> ${nextScrambled}`
}
},
sc = async () => {
let word = channelCustomData.get(scramble)
if (!word) {
channelCustomData.set(scramble, word = await rw())
const scrambledWord = scrambler(word)
channelCustomData.set(scrambled, scrambledWord)
return `${scrambledWord} is our new word.`
}
if (!args.length)
throw Error(`There's currently a scramble active. Solve ${channelCustomData.get(scrambled)} before asking for a new word.`)
const cmd = commands[args[0]]
if (cmd)
return cmd(word)
if (word !== args[0])
return `Wrong, try to solve ${channelCustomData.get(scrambled)} again.`
return `Correct, ${await nw(word)}`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment