How to use twitch-js - 6 common examples

To help you get started, we’ve selected a few twitch-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github destinygg / chat-bot / lib / services / twitch-chat.js View on Github external
connect() {
    this.client = new TwitchJsClient(this.options);
    this.client.on('message', this.parseMessages.bind(this));
    this.client.on('connected', e => {
      this.emit('open', e);
    });
    this.client.connect().catch(err => {
      this.logger.error('Problem logging into twitch:', err);

      // eslint-disable-next-line no-process-exit
      process.exit(0);
    });
  }
github twitch-js / twitch-js / examples / node.js View on Github external
// Instantiate clients.
const { api, chat } = new TwitchJs({ token, username });

// Get featured streams.
api.get('streams/featured', { version: 'kraken' }).then(response => {
  console.log(response);
  // Do stuff ...
});

const handleMessage = message => {
  console.log(message);
  // Do other stuff ...
};

// Listen for all events.
chat.on(TwitchJs.Chat.Events.ALL, handleMessage);

// Connect ...
chat.connect().then(() => {
  // ... and then join the channel.
  chat.join(channel);
});
github codigofalado / twitch-giphy / src / index.ts View on Github external
async function main() {
  try {
    // Inicia o servidor
    const Server = server();

    // Inicializa a API da Twitch e do Giphy
    const { channels, token, username } = config.twitch;
    const { token: giphy_token, rating } = config.giphy;
    const { chat } = new twitch({ token, username });
    const gif = giphy(giphy_token);

    // Conecta na Twitch e aos entra nos chats configurados
    await chat.connect();
    await Promise.all(channels.map(ch => chat.join(ch)));

    // Escutar todas as mensagem privadas
    chat.on('PRIVMSG', async payload => {
      const {
        tags: { color },
        username,
        message,
        channel,
      } = payload;

      // Caso o usuário não tem uma cor definida, ele irá gerar uma cor
github mccxiv / tc / src / tc-renderer / ng / providers / irc.js View on Github external
'subscribers',
      'subscription',
      'subgift',
      'timeout',
      'unhost',
      'whisper'
    ]

    const clientSettings = {
      options: {debug: false, clientId: CLIENT_ID},
      connection: {timeout: 20000, reconnect: true, secure: true},
      identity: angular.copy(settings.identity),
      channels: []
    }

    client = new Client(clientSettings)
    client.connect()
    client.on('connected', joinChannels)
    onBadLogin(destroy)
    forwardEvents(client, ee, events)

    client.on('connected', () => {
      ee.ready = true
      setTimeout(() => $rootScope.$apply(), 0)
    })

    // Disconnected event gets spammed on every connection
    // attempt. This is not ok if the internet is temporarily
    // down, for example.
    onlyEmitDisconnectedOnce()

    function onlyEmitDisconnectedOnce () {
github sogehige / sogeBot / src / bot / tmi.ts View on Github external
async initClient (type: 'bot' | 'broadcaster') {
    clearTimeout(this.timeouts[`initClient.${type}`]);
    const [token, username, channel] = await Promise.all([
      oauth[type + 'AccessToken'],
      oauth[type + 'Username'],
      oauth.generalChannel,
    ]);

    try {
      if (token === '' || username === '' || channel === '') {
        throw Error(`${type} - token, username or channel expected`);
      }
      const log = isDebugEnabled('tmi.client') ? { level: 'debug' } : { level: 'silent' };
      this.client[type] = new TwitchJs({
        token,
        username,
        log,
        onAuthenticationFailure: () => oauth.refreshAccessToken(type).then(token => token),
      });
      this.loadListeners(type);
      await (this.client[type] as TwitchJs).chat.connect();
      await this.join(type, channel);
    } catch (e) {
      if (type === 'broadcaster' && !this.broadcasterWarning) {
        error('Broadcaster oauth is not properly set - hosts will not be loaded');
        error('Broadcaster oauth is not properly set - subscribers will not be loaded');
        this.broadcasterWarning = true;
      }
      this.timeouts[`initClient.${type}`] = setTimeout(() => this.initClient(type), 10000);
    }
github HiDeoo / YaTA / src / containers / Chat.tsx View on Github external
constructor(props: Props) {
    super(props)

    if (_.isNil(props.loginDetails)) {
      this.state = {
        error: new Error('No login details provided.'),
      }
    }

    this.client = tmi.client({
      channels: [],
      connection: { reconnect: true, secure: true },
      identity: props.loginDetails || undefined,
      options: { clientId: process.env.REACT_APP_TWITCH_CLIENT_ID, debug: false },
    })
  }

twitch-js

Javascript library for the Twitch Messaging Interface.

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis