twitch-chat library is a Twitch chat client which uses Twitch IRC. EventMachine is used to handle connection to server. 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.
Add this line to your application's Gemfile:
gem 'twitch-chat'
And then execute:
$ bundle
Or install it yourself as:
$ gem install twitch-chat
require 'twitch/chat'
client = Twitch::Chat::Client.new(channel: 'channel', nickname: 'nickname', password: 'twitch_oath_token') do
on(:connected) 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')
- 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