Sha256: 422c1458fc2fa6a9e7a41c69c9ee38510ff4b6d5ee18c2f57f542953398e1aa2

Contents?: true

Size: 1.09 KB

Versions: 15

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Twitch
  module Bot
    # Twitch chat client object
    class Client
      # Respond to a :ping event with a pong so we don't get disconnected.
      class PingHandler < Twitch::Bot::EventHandler
        def call
          client.send_data "PONG :#{event.hostname}"
        end

        def self.handled_events
          [:ping]
        end
      end

      # Handle the :authenticated event required for joining our channel.
      class AuthenticatedHandler < Twitch::Bot::EventHandler
        def call
          client.join_default_channel
        end

        def self.handled_events
          [:authenticated]
        end
      end

      # Handle a change in moderators on the channel.
      class ModeHandler < Twitch::Bot::EventHandler
        def call
          user = event.user
          case event.mode
          when :add_moderator
            client.add_moderator(user)
          when :remove_moderator
            client.remove_moderator(user)
          end
        end

        def self.handled_events
          [:mode]
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
twitch-bot-6.0.0 lib/twitch/bot/default_handlers.rb
twitch-bot-5.0.6 lib/twitch/bot/default_handlers.rb
twitch-bot-5.0.5 lib/twitch/bot/default_handlers.rb
twitch-bot-5.0.4 lib/twitch/bot/default_handlers.rb
twitch-bot-5.0.2 lib/twitch/bot/default_handlers.rb
twitch-bot-5.0.1 lib/twitch/bot/default_handlers.rb
twitch-bot-5.0.0 lib/twitch/bot/default_handlers.rb
twitch-bot-4.1.1 lib/twitch/bot/default_handlers.rb
twitch-bot-4.1.0 lib/twitch/bot/default_handlers.rb
twitch-bot-4.0.1 lib/twitch/bot/default_handlers.rb
twitch-bot-4.0.0 lib/twitch/bot/default_handlers.rb
twitch-bot-3.2.1 lib/twitch/bot/default_handlers.rb
twitch-bot-3.2.0 lib/twitch/bot/default_handlers.rb
twitch-bot-3.1.0 lib/twitch/bot/default_handlers.rb
twitch-bot-2.1.1 lib/twitch/bot/default_handlers.rb