Skip to content

Instantly share code, notes, and snippets.

@oelna
Last active June 12, 2020 12:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
A few custom Nightbot commands to use on Twitch

Nightbot custom commands

This is an incomplete list of Nightbot commands I use on my Twitch channel to facilitate the teaching of webdesign. Many commands only generate links to specific sites, but some also offer advanced functionality, such as RNG. You should probably adjust the code, if you'd like to use them.

Random Number

Command: !random
Description: Generate a random number between 1 and 100, or a specific interval
Usage: !random, !random 1 10 or !random 5 20

$(eval if ($(1) && $(2)) {
	Math.floor(Math.random() * ($(2) - $(1) + 1) + $(1));
} else {
	Math.floor((Math.random() * 100) + 1);
})

Chance

Command: !chance
Description: Calculate a percentage
Usage: !chance 1 in 32

$(eval if ('$(1)' !== 'null' && '$(3)' !== 'null') {
	let n = 100 * parseInt('$(1)') / parseInt('$(3)'); 
	if (n % 1 === 0) {
		(n).toString() + '%'
	} else {
		(n).toFixed(2).toString() + '%' 
	}
} else { 
	'Usage: !chance [number] in [number], eg: !chance 1 in 5' 
})

Pick

Command: !pick
Description: Pick one of up to nine supplied parameters at random
Usage: !pick apple banana orange starfruit

$(eval if ('$(1)' !== 'null') {
	const params = ['$(1)', '$(2)', '$(3)', '$(4)', '$(5)', '$(6)', '$(7)', '$(8)', '$(9)'];
	const filtered = params.filter(param => param !== 'null');

	'From '+filtered.length+' choices I picked: '+filtered[Math.floor(Math.random() * filtered.length)];
} else {
	'Usage: !pick [term1] [term2] … [term9], eg: !pick apple banana orange'
})

Google Link

Command: !google
Description: Generate a link for a specific google search
Usage: !google african elephant

Here is your Google search: https://www.google.com/search?q=$(querystring)

Stackoverflow Link

Command: !so
Description: Generate a link for a specific search on Stackoverflow
Usage: !so random number in javascript

Here is your Stackoverflow search: https://stackoverflow.com/search?q=$(querystring)

MDN Link

Command: !mdn
Description: Generate a link to (german) MDN for a specific HTML element or CSS property
Usage: !mdn css background-color or !mdn html li

$(eval if ('$(1)' !== 'null' && '$(2)' !== 'null') {
	if ('$(1)'.toUpperCase() == 'HTML') {
		'https://developer.mozilla.org/de/docs/Web/HTML/Element/$(2)'
	} else {
		'https://developer.mozilla.org/de/docs/Web/CSS/$(2)'
	}
} else {
	'Usage: !mdn [html|css] [element|property], eg: !mdn html li'
})

SelfHTML Link

Command: !sh
Description: Generate a link to (german) SelfHTML for a specific term
Usage: !sh background-color or !sh li

$(eval if ('$(1)' !== 'null') {
	'https://wiki.selfhtml.org/index.php?search=$(querystring)'
} else {
	'Usage: !sh [element|property], eg: !sh background-color'
})

Github Link

Command: !github
Description: Generate a link to a Github user profile
Usage: !github oelna

$(eval if ('$(1)' !== 'null') {
	'$(user) Link to Github profile: https://github.com/$(1)/'
} else {
	'Link to Github profile: https://github.com/oelna/'
})

Keybase Link

Command: !kb
Description: Generate a link to a Keybase user profile
Usage: !kb oelna

$(eval if ('$(1)' !== 'null') {
	'$(user) Link to Keybase profile: https://keybase.io/$(1)/'
} else {
	'Link to Keybase profile: https://keybase.io/oelna/'
})

Twitch stream uptime

Command: !uptime
Description: Display how long the stream has been going
Usage: !uptime

The stream has been live for $(twitch $(channel) "{{uptimeLength}}").

Twitch user join date

Command: !created
Description: Display when a specified user account was created
Usage: !created oelna

$(twitch $(user) "The account {{displayName}} was created on the date of: {{createdAt}}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment