All Projects → TwitchLib → Twitchlib

TwitchLib / Twitchlib

Licence: mit
C# Twitch Chat, Whisper, API and PubSub Library. Allows for chatting, whispering, stream event subscription and channel/account modification. Supports .NET Core 2.0

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Twitchlib

Twitch4j
Modular Async/Sync/Reactive Twitch API Client / IRC Client
Stars: ✭ 209 (-59.73%)
Mutual labels:  api, twitch, chat, pubsub
Telebot.nim
Async client for Telegram Bot API in pure Nim [Bot API 5.1]
Stars: ✭ 93 (-82.08%)
Mutual labels:  api, bot, chat, client
Tiledesk Server
Tiledesk server. Tiledesk is an Open Source Live Chat platform written in NodeJs and MongoDB
Stars: ✭ 94 (-81.89%)
Mutual labels:  api, bot, chat
Matrixcli
Command line matrix client
Stars: ✭ 69 (-86.71%)
Mutual labels:  bot, chat, client
Mojo Weixin
使用Perl语言(不会没关系)编写的个人账号微信/weixin/wechat客户端框架(非GUI),可通过插件提供基于HTTP协议的api接口供其他语言或系统调用
Stars: ✭ 1,181 (+127.55%)
Mutual labels:  api, bot, chat
Twitch
Interact with Twitch's API, chat, PubSub and subscribe to WebHooks.
Stars: ✭ 237 (-54.34%)
Mutual labels:  api, twitch, pubsub
Python Twitch Client
Python wrapper for Twitch API
Stars: ✭ 137 (-73.6%)
Mutual labels:  api, twitch, client
Mojo Webqq
【重要通知:WebQQ将在2019年1月1日停止服务,此项目目前已停止维护,感谢大家四年来的一路陪伴】使用Perl语言(不会没关系)编写的smartqq/webqq客户端框架(非GUI),可通过插件提供基于HTTP协议的api接口供其他语言或系统调用
Stars: ✭ 1,755 (+238.15%)
Mutual labels:  api, bot, chat
Twitch Js
A community-centric, community-supported version of tmi.js
Stars: ✭ 225 (-56.65%)
Mutual labels:  api, bot, twitch
Messenger
Package messenger is used for making bots for use with Facebook messenger
Stars: ✭ 278 (-46.44%)
Mutual labels:  api, bot, client
Ts3audiobot
Advanced Musicbot for Teamspeak 3
Stars: ✭ 397 (-23.51%)
Mutual labels:  bot, client
Node Vault
Client for HashiCorp's Vault
Stars: ✭ 391 (-24.66%)
Mutual labels:  api, client
Nats.net
The official C# Client for NATS
Stars: ✭ 378 (-27.17%)
Mutual labels:  pubsub, client
Javacord
An easy to use multithreaded library for creating Discord bots in Java.
Stars: ✭ 368 (-29.09%)
Mutual labels:  api, bot
Yakyak
Desktop chat client for Google Hangouts
Stars: ✭ 3,869 (+645.47%)
Mutual labels:  chat, client
Groupbutler
This bot can help you in managing your group with rules, anti-flood, description, custom triggers, and much more!
Stars: ✭ 399 (-23.12%)
Mutual labels:  bot, chat
Twitch Chat Downloader
Download chat messages from past broadcasts on Twitch
Stars: ✭ 404 (-22.16%)
Mutual labels:  twitch, chat
Joe
A general-purpose bot library inspired by Hubot but written in Go. 🤖
Stars: ✭ 417 (-19.65%)
Mutual labels:  bot, chat
Quaternion
A Qt5-based IM client for Matrix
Stars: ✭ 438 (-15.61%)
Mutual labels:  chat, client
Pg Listen
📡 PostgreSQL LISTEN & NOTIFY for node.js that finally works.
Stars: ✭ 348 (-32.95%)
Mutual labels:  events, pubsub

Platform: iOS

PLEASE check the "Dev" build before doing a PR if master does not have a feature your looking for.

About

TwitchLib is a powerful C# library that allows for interaction with various Twitch services. Currently supported services are: chat and whisper, API's (v5, helix, undocumented, and third party), PubSub event system, and Twitch Extensions. Below are the descriptions of the core components that make up TwitchLib.

Talk directly with us on Discord. https://discord.gg/8NXaEyV

  • TwitchLib.Client: Handles chat and whisper Twitch services. Complete with a suite of events that fire for virtually every piece of data received from Twitch. Helper methods also exist for replying to whispers or fetching moderator lists.
  • TwitchLib.Api: Complete coverage of v5, and Helix endpoints. The API is now a singleton class. This class allows fetching all publicly accessible data as well as modify Twitch services like profiles and streams.
  • TwitchLib.PubSub: Supports all documented Twitch PubSub topics as well as a few undocumented ones.
  • TwitchLib.Extension: EBS implementation for validating requests, interacting with extension via PubSub and calling Extension endpoints.
  • TwitchLib.Unity: Unity wrapper system for TwitchLib to allow easy usage of TwitchLib in Unity projects!
  • TwitchLib.Webhook: Implements ASP.NET Core Webhook Receiver with TwitchLib. [Requires DotNet Core 2.1+]

Features

  • TwitchLib.Client:
    • Send formatted or raw messages to Twitch
    • Chat and Whisper command detection and parsing
    • Helper methods
      • Timeout, ban, unban users
      • Change chat color and clear chat
      • Invoke stream commercials and hosts
      • Emote only, follower only, subscriber only, and slow mode
      • Reply-to whisper support
    • Handles chat and whisper events:
      • Connected and Joined channel
      • Channel and User state changed
      • Message received/sent
      • Whisper received/sent
      • User joined/left
      • Moderator joined/left
      • New subscriptions and resubscriptions
      • Hosting and raid detection
      • Chat clear, user timeouts, user bans
  • TwitchLib.APi:
    • Supported Twitch API endpoints:v5, Helix
    • Supported API sections:
      • Badges, Bits, Blocks
      • ChannelFeeds, Channels, Chat, Clips, Collections, Communities,
      • Follows
      • Games
      • HypeTrain
      • Ingests
      • Root
      • Search, Streams, Subscriptions
      • Teams
      • ThirdParty
      • Undocumented
        • ClipChat
        • TwitchPrimeOffers
        • ChannelHosts
        • ChatProperties
        • ChannelPanels
        • CSMaps
        • CSStreams
        • RecentMessages
        • Chatters
        • RecentChannelEvents
        • ChatUser
        • UsernameAvailable
      • User
      • Videos
    • Services
      • FollowerService: Service for detection of new followers in somewhat real time.
      • LiveStreamMonitor: Service for detecting when a channel goes online/offline in somewhat real time.
      • MessageThrottler: Service to throttle chat messages to abide by Twitch use requirements.
  • TwitchLib.PubSub:
    • Supported topics:
      • ChatModeratorActions
      • BitsEvents
      • VideoPlayback
      • Whispers
      • Subscriptions
      • (Dev) Channel Points
  • TwitchLib.Extension:
    • Developed to be used as part of an EBS (extension back-end service) for a Twitch Extension.
    • Perform API calls related to Extensions (create secret, revoke, channels using extension, etc.)
    • Validation of requests to EBS using extension secret and JWT.
    • Interact with extension via PubSub.

Documentation

Doxygen

For complete library documentation, view the doxygen docs here.

Implementing

Below are basic examples of how to utilize each of the core components of TwitchLib. These are C# examples. NOTE: Twitchlib.API currently does not support Visual Basic. UPDATE: PR'd Visual Basic fix but requires testing by someone that uses it.

Twitchlib.Client - CSharp

using System;
using TwitchLib.Client;
using TwitchLib.Client.Enums;
using TwitchLib.Client.Events;
using TwitchLib.Client.Extensions;
using TwitchLib.Client.Models;
using TwitchLib.Communication.Clients;
using TwitchLib.Communication.Models;

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Bot bot = new Bot();
            Console.ReadLine();
        }
    }

    class Bot
    {
        TwitchClient client;
	
        public Bot()
        {
            ConnectionCredentials credentials = new ConnectionCredentials("twitch_username", "access_token");
	    var clientOptions = new ClientOptions
                {
                    MessagesAllowedInPeriod = 750,
                    ThrottlingPeriod = TimeSpan.FromSeconds(30)
                };
            WebSocketClient customClient = new WebSocketClient(clientOptions);
            client = new TwitchClient(customClient);
            client.Initialize(credentials, "channel");

            client.OnLog += Client_OnLog;
            client.OnJoinedChannel += Client_OnJoinedChannel;
            client.OnMessageReceived += Client_OnMessageReceived;
            client.OnWhisperReceived += Client_OnWhisperReceived;
            client.OnNewSubscriber += Client_OnNewSubscriber;
            client.OnConnected += Client_OnConnected;

            client.Connect();
        }
  
        private void Client_OnLog(object sender, OnLogArgs e)
        {
            Console.WriteLine($"{e.DateTime.ToString()}: {e.BotUsername} - {e.Data}");
        }
  
        private void Client_OnConnected(object sender, OnConnectedArgs e)
        {
            Console.WriteLine($"Connected to {e.AutoJoinChannel}");
        }
  
        private void Client_OnJoinedChannel(object sender, OnJoinedChannelArgs e)
        {
            Console.WriteLine("Hey guys! I am a bot connected via TwitchLib!");
            client.SendMessage(e.Channel, "Hey guys! I am a bot connected via TwitchLib!");
        }

        private void Client_OnMessageReceived(object sender, OnMessageReceivedArgs e)
        {
            if (e.ChatMessage.Message.Contains("badword"))
                client.TimeoutUser(e.ChatMessage.Channel, e.ChatMessage.Username, TimeSpan.FromMinutes(30), "Bad word! 30 minute timeout!");
        }
        
        private void Client_OnWhisperReceived(object sender, OnWhisperReceivedArgs e)
        {
            if (e.WhisperMessage.Username == "my_friend")
                client.SendWhisper(e.WhisperMessage.Username, "Hey! Whispers are so cool!!");
        }
        
        private void Client_OnNewSubscriber(object sender, OnNewSubscriberArgs e)
        {
            if (e.Subscriber.SubscriptionPlan == SubscriptionPlan.Prime)
                client.SendMessage(e.Channel, $"Welcome {e.Subscriber.DisplayName} to the substers! You just earned 500 points! So kind of you to use your Twitch Prime on this channel!");
            else
                client.SendMessage(e.Channel, $"Welcome {e.Subscriber.DisplayName} to the substers! You just earned 500 points!");
        }
    }
}

Twitchlib.Client - Visual Basic

Imports System
Imports TwitchLib.Client
Imports TwitchLib.Client.Enums
Imports TwitchLib.Client.Events
Imports TwitchLib.Client.Extensions
Imports TwitchLib.Client.Models

Module Module1

    Sub Main()
        Dim bot As New Bot()
        Console.ReadLine()
    End Sub

    Friend Class Bot
        Private client As TwitchClient

        Public Sub New()
            Dim credentials As New ConnectionCredentials("twitch_username", "Token")

            client = New TwitchClient()
            client.Initialize(credentials, "Channel")

            AddHandler client.OnJoinedChannel, AddressOf onJoinedChannel
            AddHandler client.OnMessageReceived, AddressOf onMessageReceived
            AddHandler client.OnWhisperReceived, AddressOf onWhisperReceived
            AddHandler client.OnNewSubscriber, AddressOf onNewSubscriber
            AddHandler client.OnConnected, AddressOf Client_OnConnected

            client.Connect()
        End Sub
        Private Sub Client_OnConnected(ByVal sender As Object, ByVal e As OnConnectedArgs)
            Console.WriteLine($"Connected to {e.AutoJoinChannel}")
        End Sub
        Private Sub onJoinedChannel(ByVal sender As Object, ByVal e As OnJoinedChannelArgs)
            Console.WriteLine("Hey guys! I am a bot connected via TwitchLib!")
            client.SendMessage(e.Channel, "Hey guys! I am a bot connected via TwitchLib!")
        End Sub

        Private Sub onMessageReceived(ByVal sender As Object, ByVal e As OnMessageReceivedArgs)
            If e.ChatMessage.Message.Contains("badword") Then
                client.TimeoutUser(e.ChatMessage.Channel, e.ChatMessage.Username, TimeSpan.FromMinutes(30), "Bad word! 30 minute timeout!")
            End If
        End Sub
        Private Sub onWhisperReceived(ByVal sender As Object, ByVal e As OnWhisperReceivedArgs)
            If e.WhisperMessage.Username = "my_friend" Then
                client.SendWhisper(e.WhisperMessage.Username, "Hey! Whispers are so cool!!")
            End If
        End Sub
        Private Sub onNewSubscriber(ByVal sender As Object, ByVal e As OnNewSubscriberArgs)
            If e.Subscriber.SubscriptionPlan = SubscriptionPlan.Prime Then
                client.SendMessage(e.Channel, $"Welcome {e.Subscriber.DisplayName} to the substers! You just earned 500 points! So kind of you to use your Twitch Prime on this channel!")
            Else
                client.SendMessage(e.Channel, $"Welcome {e.Subscriber.DisplayName} to the substers! You just earned 500 points!")
            End If
        End Sub
    End Class


End Module

For a complete list of TwitchClient events and calls, click here

Twitchlib.API - CSharp

Note: TwitchAPI is now a singleton class that needs to be instantiated with optional clientid and auth token. Please know that failure to provide at least a client id, and sometimes an access token will result in exceptions. The v3 subclass operates almost entirely on Twitch usernames. v5 and Helix operate almost entirely on Twitch user id's. There are methods in all Twitch api versions to get corresponding usernames/userids.

using System.Collections.Generic;
using System.Threading.Tasks;

using TwitchLib.Api;
using TwitchLib.Api.Helix.Models.Users;
using TwitchLib.Api.V5.Models.Subscriptions;

namespace Example
{
    class Program
    {
        private static TwitchAPI api;

        private void Main()
        {
            api = new TwitchAPI();
            api.Settings.ClientId = "client_id";
            api.Settings.AccessToken = "access_token"; // App Secret is not an Accesstoken
        }

        private async Task ExampleCallsAsync()
        {
            //Checks subscription for a specific user and the channel specified.
            Subscription subscription = await api.V5.Channels.CheckChannelSubscriptionByUserAsync("channel_id", "user_id");

            //Gets a list of all the subscritions of the specified channel.
            List<Subscription> allSubscriptions = await api.V5.Channels.GetAllSubscribersAsync("channel_id");

            //Get channels a specified user follows.
            GetUsersFollowsResponse userFollows = await api.Helix.Users.GetUsersFollowsAsync("user_id");

            //Get Specified Channel Follows
            var channelFollowers = await api.V5.Channels.GetChannelFollowersAsync("channel_id");

            //Return bool if channel is online/offline.
            bool isStreaming = await api.V5.Streams.BroadcasterOnlineAsync("channel_id");

            //Update Channel Title/Game
            await api.V5.Channels.UpdateChannelAsync("channel_id", "New stream title", "Stronghold Crusader");
        }
    }
}

Twitchlib.API - Visual Basic

Imports System.Collections.Generic
Imports System.Threading.Tasks

Imports TwitchLib.Api
Imports TwitchLib.Api.Models.Helix.Users.GetUsersFollows
Imports TwitchLib.Api.Models.Helix.Users.GetUsers
Imports TwitchLib.Api.Models.v5.Subscriptions

Module Module1

    Public api As TwitchAPI

    Sub Main()
        api = New TwitchAPI()
        api.Settings.ClientId = "Client_id"
        api.Settings.AccessToken = "access_token" // App Secret is not an Accesstoken
        streaming().Wait()
        getchanfollows().Wait()
        getusersubs().Wait()
        getnumberofsubs().Wait()
        getsubstochannel().Wait()
        Console.ReadLine()
    End Sub

    Private Async Function getusersubs() As Task
        'Checks subscription for a specific user and the channel specified.
        Dim subscription As Subscription = Await api.Channels.v5.CheckChannelSubscriptionByUserAsync("channel_id", "user_id")
        Console.WriteLine("User subed: " + subscription.User.Name.ToString)
    End Function

    Private Async Function streaming() As Task
        'shows if the channel is streaming or not (true/false)
        Dim isStreaming As Boolean = Await api.Streams.v5.BroadcasterOnlineAsync("channel_id")
        If isStreaming = True Then
            Console.WriteLine("Streaming")
        Else
            Console.WriteLine("Not Streaming")
        End If
    End Function

    Private Async Function chanupdate() As Task
        'Update Channel Title/Game
        'not used this yet
        Await api.Channels.v5.UpdateChannelAsync("channel_id", "New stream title", "Stronghold Crusader")
    End Function

    Private Async Function getchanfollows() As Task
        'Get Specified Channel Follows
        Dim channelFollowers = Await api.Channels.v5.GetChannelFollowersAsync("channel_id")
        Console.WriteLine(channelFollowers.Total.ToString)
    End Function

    Private Async Function getchanuserfollow() As Task
        'Get channels a specified user follows.
        Dim userFollows As GetUsersFollowsResponse = Await api.Users.helix.GetUsersFollowsAsync("user_id")
        Console.WriteLine(userFollows.TotalFollows.ToString)
    End Function

    Private Async Function getnumberofsubs() As Task
        'Get the number of subs to your channel
        Dim numberofsubs = Await api.Channels.v5.GetChannelSubscribersAsync("channel_id")
        Console.WriteLine(numberofsubs.Total.ToString)
    End Function

    Private Async Function getsubstochannel() As Task
        'Gets a list of all the subscritions of the specified channel.
        Dim allSubscriptions As List(Of Subscription) = Await api.Channels.v5.GetAllSubscribersAsync("channel_id")
        Dim num As Integer
        For num = 0 To allSubscriptions.Count - 1
            Console.WriteLine(allSubscriptions.Item(num).User.Name.ToString)
        Next num
    End Function

End Module

For a complete list of TwitchAPI calls, click here

Twitchlib.PubSub

using System;
using TwitchLib.PubSub;
using TwitchLib.PubSub.Events;

namespace TwitchLibPubSubExample
{
    class Program
    {
        private TwitchPubSub client;
        
        static void Main(string[] args)
        {
            Run();
        }
        
        private void Run()
        {
            client = new TwitchPubSub();

            client.OnPubSubServiceConnected += onPubSubServiceConnected;
            client.OnListenResponse += onListenResponse;
            client.OnStreamUp += onStreamUp;
            client.OnStreamDown += onStreamDown;

            client.ListenToVideoPlayback("channelUsername");
            client.ListenToBitsEvents("channelTwitchID");
            
            client.Connect();
        }
        

        private void onPubSubServiceConnected(object sender, EventArgs e)
        {
            // SendTopics accepts an oauth optionally, which is necessary for some topics
            client.SendTopics();
        }
        
        private void onListenResponse(object sender, OnListenResponseArgs e)
        {
            if (!e.Successful)
                throw new Exception($"Failed to listen! Response: {e.Response}");
        }

        private void onStreamUp(object sender, OnStreamUpArgs e)
        {
            Console.WriteLine($"Stream just went up! Play delay: {e.PlayDelay}, server time: {e.ServerTime}");
        }

        private void onStreamDown(object sender, OnStreamDownArgs e)
        {
            Console.WriteLine($"Stream just went down! Server time: {e.ServerTime}");
        }
    }
}

For a complete list of TwitchPubSub functionality, click here

TwitchLib.Extension

See the Extension README here.

Examples, Applications, Community Work, and Projects

NOTE: Use these projects as a reference, they are NOT guaranteed to be up-to-date.

If you have any issues using these examples, please indicate what example you are referencing in the Issue or in Discord.

Installation

NuGet

To install this library via NuGet via NuGet console, use:

Install-Package TwitchLib

and via Package Manager, simply search:

TwitchLib

You are also more than welcome to clone/fork this repo and build the library yourself!

Dependencies

Contributors

Credits and Other Project Licenses

License

This project is available under the MIT license. See the LICENSE file for more info.

:)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].