How to use the twitch-js function in twitch-js

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 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 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);
    }

twitch-js

Javascript library for the Twitch Messaging Interface.

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis