<commit_before>require 'unirest'
require 'open-uri'

module Cinch
  module Plugins
    class Twitch
      include Cinch::Plugin

      timer 600, method: :check_live
      match /(twitch)$/
      match /(twitch) (.+)/, method: :check_user
      match /(help twitch)$/, method: :help

      def initialize(*args)
        super
        @users = ENV['TWITCH_USERS'].split(',')
        @online = []
      end

      def execute(m)
        @users.each do |user|
          user_get = Unirest.get "https://api.twitch.tv/kraken/streams/#{URI.encode(user)}"
          next if user_get.body['stream'].nil?
          game = user_get.body['stream']['game']
          url = user_get.body['stream']['channel']['url']
          name = user_get.body['stream']['channel']['display_name']
          title = user_get.body['stream']['channel']['status']
          viewers = user_get.body['stream']['viewers']
          m.reply "LIVE: '#{title}' (#{name} playing #{game}) => #{url}"
        end
      end

      def check_live
        response = "LIVE:"
        @users.each do |user|
          user_get = Unirest.get "https://api.twitch.tv/kraken/streams/#{URI.encode(user)}"
          @online.delete(user) if user_get.body['stream'].nil?
          next if user_get.body['stream'].nil?
          next if @online.include? user
          @online << user
          game = user_get.body['stream']['game']
          url = user_get.body['stream']['channel']['url']
          name = user_get.body['stream']['channel']['display_name']
          title = user_get.body['stream']['channel']['status']
          viewers = user_get.body['stream']['viewers']
          ENV["TWITCH_CHANNELS"].split(',').each do |channel|
            Channel(channel).send "LIVE: '#{title}' (#{name} playing #{game}) => #{url}"
          end
        end
      end

      def check_user(m, prefix, check_user, user)
        query = user.split(/[[:space:]]/).join(' ')
        user_get = Unirest.get "https://api.twitch.tv/kraken/streams/#{URI.encode(query)}"
        return m.reply "#{user} is not live bru" if user_get.body['stream'].nil?
        game = user_get.body['stream']['game']
        url = user_get.body['stream']['channel']['url']
        name = user_get.body['stream']['channel']['display_name']
        title = user_get.body['stream']['channel']['status']
        viewers = user_get.body['stream']['viewers']
        m.reply "'#{title}' (#{name} playing #{game}), Viewers: #{viewers} => #{url}"
      end

      def help(m)
        m.reply "checks every 10 minutes if specified twitch broadcasts are live."
        m.reply "type .twitch [user] to check status of specific twitch user"
      end

    end
  end
end<commit_msg>Update twitch plugin to send client id when making api calls<commit_after>require 'unirest'
require 'open-uri'

module Cinch
  module Plugins
    class Twitch
      include Cinch::Plugin

      timer 600, method: :check_live
      match /(twitch)$/
      match /(twitch) (.+)/, method: :check_user
      match /(help twitch)$/, method: :help

      def initialize(*args)
        super
        @users = ENV['TWITCH_USERS'].split(',')
        @online = []
      end

      def execute(m)
        @users.each do |user|
          user_get = Unirest.get "https://api.twitch.tv/kraken/streams/#{URI.encode(user)}",
            headers: { "Accept" => "application/json" },
            parameters: { :client_id => ENV['TWITCH_ID'] }
          next if user_get.body['stream'].nil?
          game = user_get.body['stream']['game']
          url = user_get.body['stream']['channel']['url']
          name = user_get.body['stream']['channel']['display_name']
          title = user_get.body['stream']['channel']['status']
          title = 'No Title' if title == ''
          viewers = user_get.body['stream']['viewers']
          m.reply "LIVE: '#{title}' (#{name} playing #{game}) => #{url}"
        end
      end

      def check_live
        response = "LIVE:"
        @users.each do |user|
          user_get = Unirest.get "https://api.twitch.tv/kraken/streams/#{URI.encode(user)}",
            headers: { "Accept" => "application/json" },
            parameters: { :client_id => ENV['TWITCH_ID'] }
          @online.delete(user) if user_get.body['stream'].nil?
          next if user_get.body['stream'].nil?
          next if @online.include? user
          @online << user
          game = user_get.body['stream']['game']
          url = user_get.body['stream']['channel']['url']
          name = user_get.body['stream']['channel']['display_name']
          title = user_get.body['stream']['channel']['status']
          title = 'No Title' if title == ''
          viewers = user_get.body['stream']['viewers']
          ENV["TWITCH_CHANNELS"].split(',').each do |channel|
            Channel(channel).send "LIVE: '#{title}' (#{name} playing #{game}) => #{url}"
          end
        end
      end

      def check_user(m, prefix, check_user, user)
        query = user.split(/[[:space:]]/).join(' ')
        user_get = Unirest.get "https://api.twitch.tv/kraken/streams/#{URI.encode(query)}",
          headers: { "Accept" => "application/json" },
          parameters: { :client_id => ENV['TWITCH_ID'] }
        return m.reply "#{user} is not live bru" if user_get.body['stream'].nil?
        game = user_get.body['stream']['game']
        url = user_get.body['stream']['channel']['url']
        name = user_get.body['stream']['channel']['display_name']
        title = user_get.body['stream']['channel']['status']
        title = 'No Title' if title == ''
        viewers = user_get.body['stream']['viewers']
        m.reply "'#{title}' (#{name} playing #{game}), Viewers: #{viewers} => #{url}"
      end

      def help(m)
        m.reply "checks every 10 minutes if specified twitch broadcasts are live."
        m.reply "type .twitch [user] to check status of specific twitch user"
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.17526297930098406, 'fraction_numerical': 0.0016966406515100101, 'mean_word_length': 2.5131108462455303, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2446885', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1793, 'n_words': 392}