Skip to content

A TypeScript-based bun package for Twitch bot creation. It integrates IRC and EventSub integration. (waiting for an official bun package manager.)

License

Notifications You must be signed in to change notification settings

MolikoDeveloper/TwitchTS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

this project was created with bun.

Warning

W.I.P Please Do not use in Production.

TwitchTS (bun)

install:

bun:

bun install MolikoDeveloper/TwitchTS

Connect to Chat IRC

you can connect to the chat as anonymous, or with your username and twitch Oauth Token

import {IrcClient} from 'twitchts';

const chat = new IrcClient({
    channels: ['CHANNEL'],
    identity:{
        user:{
            username: "<YOUR_USERNAME>",
            token: "<YOUR TOKEN>",
            refreshToken: "<YOUR REFRESH TOKEN IF YOU GENERATE A CODE>.",
            code: "<oauth code>" 
        },
    }
    debug:true,
    profaneFilter: true;
});


chat.on('message', (channel, tags, message, self) => {
    if (self) return; //if self == channel.idendity return.
    
    if(message.toLocaleLowerCase().includes("hello")){
        chat.say(channel, `hi @${tags['display-name']}`);
    }
})

EventSub (websocket)

import { EventSub } from 'twitchts';

let client: EventSub = new EventSub({
    identity: {
        user: {
            token: `<YOUR TOKEN HERE, WITHOUT 'Bearer ...'>`,
            refreshToken: `<REFRESHTOKEN>`,
            code: `<oauth code>`
        },
        app: {
            clientId: `<YOUR CLIENT ID>`,
            secret: `<YOUR APP SECRET>`,
            redirect_uri: `<URL>`,
            events: ['ChannelUpdate','ChannelBan','ChannelFollow', '<other...>'],
            actions: ['<WORK IN PROGRESS>'] //send whisper, messages with helix api, raid, poll, predictions, etc...
        }
    },
    channels: ["<CHANNEL USERNAME OR DISPLAY NAME>"],
    debug: true, //print debug information, token links for eventsub
    testWebsocket: false
});

client.on('ChannelUpdate', (event) => {
    console.log('New Title:',event.title);
});

client.on('ChannelBan', (event) => {
    console.log(event.user_name, event.reason);
});

client.on('ChannelFollow', (event) => {
    console.log(event.user_name, 'is a new follower!');
});

IRC and EventSub at same time.

yes, the Options are compatible with both.

import { EventSub, IrcClient, type Options } from '..';

const option: Options = {
    identity: {
        user: {
            username: '<user_name>', //all without < >
            token: `<token>`,
            refreshToken: `<refresh_token>`,
            code: `<code>`
        },
        app: {
            clientId: `<client_id>`,
            secret: `<app_secret>`,
            redirect_uri: `<URL>`,
            events: ['ChannelFollow'],
            actions: []
        }
    },
    channels: ["albertosaurus_ac"],
    debug: true,
    testWebsocket: false
}

const subs = new EventSub(option);
const chat = new IrcClient(option);

//
subs.on('ChannelFollow', (event) => {
    chat.say(event.broadcaster_user_name, `Thanks for your follow @${event.user_name}!`)
    chat.say(event.broadcaster_user_name, `BUT NOW YOU ARE BANNED! WAJAJAJA`);
    subs.ban(event.broadcaster_user_name,event.broadcaster_user_name);
    subs.unban(event.broadcaster_user_name,event.broadcaster_user_name);
    chat.say(event.broadcaster_user_name, `im joking, just chill.`);

});

TO-DO

Generate Token

pending

function GetTokens(client_id, secret, code, redirect_uri){
    console.log(Token)
    console.log(RefreshToken)
}

Twitch CLI (WebSocket EventSub)

start server with:

twitch event websocket start-server

send event from server:

twitch event trigger channel.ban --transport=websocket

huge thanks these projects:

@ppauel (twitch-eventsub) and tmijs (tmi.js)

About

A TypeScript-based bun package for Twitch bot creation. It integrates IRC and EventSub integration. (waiting for an official bun package manager.)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published