Skip to content

Commit

Permalink
randomly pad commands with no width spaces to allow bot to say the sa…
Browse files Browse the repository at this point in the history
…me command several times in a row with no restrictions
  • Loading branch information
Mike Zrimsek committed Jun 9, 2021
1 parent 440d872 commit d627b1c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions constants/commands.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const COMMAND_PREFACE = '!';

const COMMAND_SPACER = '\u200c';

const ADMIN_USER = 'bastulos';

const ADMIN_COMMANDS = {
Expand Down Expand Up @@ -29,6 +31,7 @@ const HELP_COMMAND = 'help';

module.exports = {
COMMAND_PREFACE,
UNICODE_COMMAND_SPACER: COMMAND_SPACER,
ADMIN_USER,
ADMIN_COMMANDS,
OBS_COMMANDS,
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 14 additions & 1 deletion utils/index.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -24,5 +36,6 @@ module.exports = {
getRandomColor,
replaceRequestingUserInMessage,
loadUserCommands,
loadTrackingPhrases
loadTrackingPhrases,
randomlyPadContent
};

0 comments on commit d627b1c

Please sign in to comment.