{{ message }}

Instantly share code, notes, and snippets.

# oelna/commands.md

Last active Jun 12, 2020
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'
})```

Command: `!google`
Usage: `!google african elephant`

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

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)
``````

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'
})```

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'
})```

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 {
})```

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 {
})```

## 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}}")
``````