Skip to content

Instantly share code, notes, and snippets.

@michaelowens
Last active September 25, 2022 14:49
Show Gist options
  • Save michaelowens/2eb554f8eba0e89d2ea24e67ebc7ae96 to your computer and use it in GitHub Desktop.
Save michaelowens/2eb554f8eba0e89d2ea24e67ebc7ae96 to your computer and use it in GitHub Desktop.
Chat commands for Twitch : Pyramid generator, rainbow messages, brainpower, and more to come

Twitch Commands

Chat commands for Twitch.

Install

Current commands

/tccommands
Lists all available commands

/brainpower
> O-oooooooooo AAAAE-A-A-I-A-U- JO-oooooooooooo AAE-O-A-A-U-U-A- E-eee-ee-eee AAAAE-A-E-I-E-A-JO-ooo-oo-oo-oo EEEEO-A-AAA-AAAA

/rainbow <message>
e.g. /rainbow Hello
Will change your username color and send the message 6 times

/pyramid <size> <emoticon>
e.g. /pyramid 3 Kappa
> Kappa
> Kappa Kappa
> Kappa Kappa Kappa
> Kappa Kappa
> Kappa

Changelog

0.6

  • Add support for FFZ autocomplete info

0.5

  • Fixed issue with slow pyramids & rainbow for mods

0.4

  • Refactored to only work with FFZ, which gives the best stability
  • Renamed /commands to /tccommands

0.3

  • Fixed an issue where script would not work, because it couldn't find chat textarea at start

0.2

  • Added server messages when incorrect usage of command
  • New command: /commands

0.1

  • Initial version with /brainpower, /rainbow and /pyramid
// ==UserScript==
// @name Twitch Commands
// @namespace http://michaelowens.nl/
// @homepage https://gist.github.com/michaelowens/2eb554f8eba0e89d2ea24e67ebc7ae96
// @version 0.6
// @description Adds commands to twitch chat! Install FFZ & TamperMonkey first, then install script.
// @author Xikeon (Michael Owens)
// @match *://twitch.tv/*
// @match *://www.twitch.tv/*
// @updateURL https://gist.githubusercontent.com/michaelowens/2eb554f8eba0e89d2ea24e67ebc7ae96/raw/twitchcommands.user.js
// ==/UserScript==
/* jshint esnext:true, asi:true, -W097 */
/* globals $ */
'use strict';
class TwitchCommands {
constructor () {
this.loaded = false
this.$chat = $('.chat_text_input')
this.timeStarted = +new Date()
this.forceStart = false
this.FFZ = false
this.log('Injected')
this.waitForFFZ()
}
log (...params) {
console.log('[Twitch Commands]', ...params)
}
waitForFFZ () {
let secondsSinceStart = ((+new Date()) - this.timeStarted) / 1000
if (typeof unsafeWindow.FrankerFaceZ === 'function') {
this.FFZ = true
this.log('FFZ detected')
this.bindToChatFFZ()
this.setAutocompleteInfo()
return
} else if (secondsSinceStart > 10 && this.$chat.length) {
this.log('Could not detect FFZ.')
return
}
setTimeout(_ => this.waitForFFZ(), 500)
}
bindToChatFFZ () {
this.getCommands()
.forEach(command => {
let name = command.replace('command_', '')
unsafeWindow.FrankerFaceZ.chat_commands[name] = this[command].bind(this)
})
}
setAutocompleteInfo() {
let cc = unsafeWindow.FrankerFaceZ.chat_commands
cc.tccommands.label = '/tccommands'
cc.tccommands.info = 'Show commands added by Twitch Commands'
cc.pyramid.label = '/pyramid &lt;size&gt; &lt;emote&gt;'
cc.pyramid.info = 'Make a pyramid of the given size and emote'
cc.rainbow.label = '/rainbow &lt;message&gt;'
cc.rainbow.info = 'Spam given message in rainbow colors'
cc.brainpower.label = '/brainpower'
cc.brainpower.info = 'Sends the brainpower meme'
}
getCommands () {
return Object.getOwnPropertyNames(Object.getPrototypeOf(this)).filter(name => name.indexOf('command_') === 0)
}
getTimeBetweenMessages (e) {
return this.isModeratorOrHigher(e) ? 100 : 1500
}
isModeratorOrHigher (e) {
return e && e.room.get('isModeratorOrHigher')
}
command_tccommands () {
let commands = this.getCommands().map(name => '/' + name.replace('command_', ''))
return `Twitch Commands: ${commands.join(', ')}`
}
command_pyramid (e, params) {
var size = 0
var emote = ''
if (!params || params.length < 2) {
return 'Example usage: /pyramid 3 FrankerZ'
}
[size, emote] = params
if (size < 2) {
return 'Pyramid can\'t be smaller than 2 emoticons'
}
for (let i = 1; i < (size * 2); i++) {
setTimeout(_ => {
let n = (i > size) ? (size * 2) - i : i
e.room.send((emote + ' ').repeat(n))
}, ((i - 1) * this.getTimeBetweenMessages(e)))
}
}
command_rainbow (e, params) {
if (!params || !params.length) {
return 'Example usage: /rainbow SUB HYPE'
}
const colors = ['#FF0000', '#FF7F00', '#FFFF00', '#00FF00', '#0000FF', '#4B0082'],
originalColor = e.room.chatColor,
timeBetween = this.isModeratorOrHigher(e) ? 300 : 1500
let i = 0
for (let color of colors) {
setTimeout(_ => {
e.room.send(`/color ${color}`)
setTimeout(_ => {
e.room.send(`/me ${params.join(' ')}`)
}, this.isModeratorOrHigher(e) ? 150 : 500)
}, i * timeBetween)
i++
}
setTimeout(_ => {
e.room.send(`/color ${originalColor}`)
}, (i * timeBetween) + 1000)
}
command_brainpower (e) {
e.room.send('O-oooooooooo AAAAE-A-A-I-A-U- JO-oooooooooooo AAE-O-A-A-U-U-A- E-eee-ee-eee AAAAE-A-E-I-E-A-JO-ooo-oo-oo-oo EEEEO-A-AAA-AAAA')
}
}
new TwitchCommands()
@michaelowens
Copy link
Author

@wiiarctus I can confirm this behaviour. As soon as I install BTTV (alongside of FFZ) it stops working. From what I can see, all chat commands offered by FFZ stop working. Seeing as I use the same API as FFZ uses for their commands, there's not much I can do about this. I'd suggest only using FFZ. Is there a specific reason you're using both?

@wiiarctus
Copy link

Okay now it is working again, thanks^^ Could you add it so that if I use /rainbow it will use my color that I had before (I had black and after the command a random one^^)?

@michaelowens
Copy link
Author

@wiiarctus It should go back to the color you originally had (if you still have turbo). Twitch can be slow with updating the colors on your own chat (e.g. others will see the changes right away, your rainbow might look like it posts messages in the same color). After the rainbow is done it should show your own color again after a couple of messages (usually 2 or 3). Does it not do this at all? If not then I might have to add some debug code and we can test again.

@BranDougherty
Copy link

Hi, I wanted to use multiple emote pyramids so I replaced line 98 of the script with this:

size = params[0]

for (let i = 1; i < params.length; i++) {
    emote += params[i];
    emote += ' ';
}

I don't think this has any adverse effects on regular use except it adds a trailing space which doesn't seem to make it through into the chat, either in between the emotes or after the message. You could get rid of the extra space in line 107 if you want to do this I guess. Thanks for the script!

@michaelowens
Copy link
Author

Hey @BranDougherty , glad you're enjoying the script. I'll see if I might add that into the script, if I don't find any side effects I don't see why not.

@tripelm
Copy link

tripelm commented Apr 5, 2017

Hey, It doesnt work for me i installed all like it stays there and reloadet twitch even restartet my browser

@NinjaKiero
Copy link

Was working fine, but then it just stopped. FFZ and TamperMonkey are still installed. I've tried reinstalling the script several times but it still doesn't work.

@Luso0
Copy link

Luso0 commented Apr 25, 2018

Now with legacy chat gone, any chance on getting an update for the new Twitch chat?

@wiiarctus
Copy link

Hey @michaelowens do you have any plans on updating this script? It would be very neat to be able to use it again! :)

@michaelowens
Copy link
Author

Hey @wiiarctus, I was actually thinking about this not too long ago. I might see if I can find some time to make this work for the current FFZ version in the near future.

@Geczy
Copy link

Geczy commented Sep 15, 2021

@grantzimmerman
Copy link

Followed the instructions to install, but when I try to type the commands in chat it will just say "unrecognized command".

@JonJaded
Copy link

JonJaded commented Oct 5, 2021

Followed the instructions to install, but when I try to type the commands in chat it will just say "unrecognized command".

this tool no longer works with the current version of FFZ.

@grantzimmerman
Copy link

Followed the instructions to install, but when I try to type the commands in chat it will just say "unrecognized command".

this tool no longer works with the current version of FFZ.

Is there a tool like this available somewhere? I was looking for something that could do a pyramid primarily.

@Verygafanhot
Copy link

it doesen't work anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment