Socket
Book a DemoInstallSign in
Socket

twitch-chat

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twitch-chat

0.0.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

Twitch::Chat

twitch-chat library is a Twitch chat client that uses Twitch IRC. EventMachine is used to handle connections to servers. With the help of this library you can connect to any Twitch's channel and handle various chat events. Can be used as twitch chat bot engine.

Installation

Add this line to your application's Gemfile:

gem 'twitch-chat'

And then execute:

$ bundle

Or install it yourself as:

$ gem install twitch-chat

Usage

require 'twitch-chat'

client = Twitch::Chat::Client.new(channel: 'channel', nickname: 'nickname', password: 'twitch_oath_token') do
  on(:connect) do
    send_message 'Hi guys!'
  end

  on(:subscribe) do |user|
    client.send_message "Hi #{user}, thank you for subscription"
  end

  on(:slow_mode) do
    send_message "Slow down guys"
  end

  on(:subscribers_mode_off) do
    send_message "FREEEEEDOOOOOM"
  end

  on(:message) do |user, message|
    send_message "Current time: #{Time.now.utc}" if message == '!time'
  end

  on(:message) do |user, message|
    send_mesage "Hi #{user}!" if message.include?("Hi #{nickname}")
  end

  on(:message) do |user, message|
    send_message channel.moderators.join(', ') if message == '!moderators'
  end

  on(:new_moderator) do |user|
    send_message "#{user} is our new moderator"
  end

  on(:remove_moderator) do |user|
    send_message "#{user} is no longer moderator"
  end

  on(:disconnect) do
    send_message 'Bye guys!'
  end
end

client.run!

List of events: :message, :slow_mode, :r9k_mode, :subscribers_mode, :slow_mode_off, :r9k_off, :subscribers_mode_off, :subscribe, :connect, :disconnect, not_supported, raw.

raw event is triggered for every twitch irc message. not_supported event is triggered for not supported twitch irc messages.

if local variable access is needed, the first block variable is the client:


Twitch::Chat::Client.new(channel: 'channel', nickname: 'nickname', password: 'twitch_oath_token') do |client|
  # client is the client instance
end

By default, logging is done to the STDOUT, but you can change it by passing log file path as :output parameter in initializer

Twitch::Chat::Client.new(channel: 'channel', nickname: 'nickname', password: 'twitch_oath_token', output: 'file.log')

Contributing

  • Fork it ( https://github.com/enotpoloskun/twitch-chat/fork )
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request

FAQs

Package last updated on 07 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.