From d627b1cc48076c31a194abe24858916be1f1e2d2 Mon Sep 17 00:00:00 2001 From: Mike Zrimsek Date: Wed, 9 Jun 2021 00:31:01 -0400 Subject: [PATCH] randomly pad commands with no width spaces to allow bot to say the same command several times in a row with no restrictions --- constants/commands.js | 3 +++ index.js | 6 +++--- utils/index.js | 15 ++++++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/constants/commands.js b/constants/commands.js index 594c5af..1ae432a 100644 --- a/constants/commands.js +++ b/constants/commands.js @@ -1,5 +1,7 @@ const COMMAND_PREFACE = '!'; +const COMMAND_SPACER = '\u200c'; + const ADMIN_USER = 'bastulos'; const ADMIN_COMMANDS = { @@ -29,6 +31,7 @@ const HELP_COMMAND = 'help'; module.exports = { COMMAND_PREFACE, + UNICODE_COMMAND_SPACER: COMMAND_SPACER, ADMIN_USER, ADMIN_COMMANDS, OBS_COMMANDS, diff --git a/index.js b/index.js index a0c324b..f7d68a2 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,7 @@ const { COMMAND_PREFACE, ADMIN_USER, OBS_COMMANDS } = require('./constants/comma const { handleAdminCommand, handleOBSCommand, handleModCommand, handleTwitchUserCommand } = require('./commands/twitch'); const { handleUserCommand, handleHelpCommand } = require('./commands/shared'); -const { loadUserCommands } = require('./utils'); +const { loadUserCommands, randomlyPadContent } = require('./utils'); // init twitch client const twitchClient = new tmi.client(tmiConfig); @@ -73,7 +73,7 @@ twitchClient.on('chat', async (channel, userInfo, message, self) => { const messageParts = message.split(' '); const username = `@${userInfo.username}`; - const printFunc = content => twitchClient.say(channel, content); + const printFunc = content => twitchClient.say(channel, randomlyPadContent(content)); const commandsActiveUpdateFunc = newState => commandsActive = newState; try { @@ -109,7 +109,7 @@ discordClient.on('message', async message => { const messageParts = content.split(' '); const username = `<@!${member.user.id}>`; - const printFunc = content => message.channel.send(content); + const printFunc = content => message.channel.send(randomlyPadContent(content)); try { const userCommands = await loadUserCommands(firestore); diff --git a/utils/index.js b/utils/index.js index 7c173c4..d124a1c 100644 --- a/utils/index.js +++ b/utils/index.js @@ -1,13 +1,25 @@ +const { UNICODE_COMMAND_SPACER } = require('../constants/commands'); const { COMMANDS_COLLECTION, WORD_TRACKING_COLLECTION } = require('../constants/firebase'); function getRandomColor() { return (Math.random() * 4294967296) >>> 0; } +function getRandomInt(max, offset = 0) { + return Math.floor(Math.random() * max) + offset; +} + function replaceRequestingUserInMessage(username, command) { return command.replace('{user}', username); } +function randomlyPadContent(content) { + const numToPad = getRandomInt(99, 1); + const padding = UNICODE_COMMAND_SPACER.repeat(numToPad); + console.log(`${content}${padding}`.length); + return `${content}${padding}`; +} + async function loadUserCommands(firestore) { const commandsSnapshot = await firestore.collection(COMMANDS_COLLECTION).get(); logger.info('User commands loaded'); @@ -24,5 +36,6 @@ module.exports = { getRandomColor, replaceRequestingUserInMessage, loadUserCommands, - loadTrackingPhrases + loadTrackingPhrases, + randomlyPadContent }; \ No newline at end of file