2.0.3 • Published 3 years ago

@stream-blitz/create-handler v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@stream-blitz/create-handler

Create an effect handler to respond to chat commands on Twitch.

Install

npm install @stream-blitz/create-handler

Usage

Basic usage:

const createHandler = require('@stream-blitz/create-handler');

exports.handler = createHandler({
  name: 'ahem',
  description: 'Pay attention!',
  handler: () => ({
    message: 'Hey. Look at me.', // chat message
    audio: 'https://example.com/assets/ahem.mp3', // sound effect played on stream
    image: 'https://example.com/assets/knock.gif', // image shown on stream
    duration: 3,
  }),
});

Advanced Usage

This example handler returns all available settings:

const createHandler = require('@stream-blitz/create-handler');

exports.handler = createHandler({
  name: 'boop',
  description: 'Do a mischief on a the screen!',
  handler: ({ message, command, args, author, extra }) => {
    // only allow moderators to fire this command
    if (!author.roles.includes('MODERATOR')) {
      return;
    }

    console.log(`The full chat message is “${message}”`);
    console.log(`The command called is “${command}”`);
    console.log(`The arguments for this command are “${args.join(', ')}”`);
    console.log(`The user who called this command is @${author.username}`);
    console.log(`The Twitch channel where this command should run is ${extra.channel}`);

    return {
      message: 'BOOP!',
      audio: 'https://example.org/assets/boop.mp3',
      image: 'https://example.org/assets/boop.gif',
      duration: 2,
    };
  },
});

API

createHandler API

namerequireddescription
nameyesName of the command. Only letters, numbers, & hyphens.
descriptionA description of what the command does.
handleryesA function to handle the command. Must return a valid Effect.

handler arguments

namedescription
messageFull message as sent to Twitch chat
commandName of the command that was called
argsArray of arguments passed to the command
authorObject with information about the user who called the command
author.idTwitch user ID
author.usernameTwitch username
author.rolesArray of user roles (values: MODERATOR, SUBSCRIBER, BROADCASTER)
extraAdditional information about the command
extra.channelThe Twitch channel username where the chat message was posted

Effect return type

All handler functions must return an object with the following properties. All of these properties are optional, but if you don’t include any of them, nothing will happen when your effect is called, and that would be a real bummer.

nametypedescriptiondefault
messagestringA message to send to chat. Can include Twitch emotes.
audiostringURL of an MP3 file to play as part of the effect.
imagestringURL of an image to display as part of the effect.
durationnumberNumber of seconds to show the image on screen.4
3.0.0-beta.0

3 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.0

5 years ago

0.1.0

5 years ago

0.0.3

5 years ago

0.0.2

6 years ago

0.0.1

6 years ago