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()
@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