From 6f24f9c3ed94c5b8f8df7602690e52193bff2841 Mon Sep 17 00:00:00 2001 From: Jared White Date: Tue, 8 Jun 2021 11:07:52 -0500 Subject: [PATCH 1/3] Update for Helix --- .gitignore | 2 +- Gemfile.lock | 1 + README.md | 2 +- config.yml | 6 +++--- lib/plugins/mos_bot_plugin.rb | 2 +- lib/stream_finder.rb | 16 ++++++++-------- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index e0a01f7..1d3ed4c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -my_config.yml +config.yml diff --git a/Gemfile.lock b/Gemfile.lock index 5f31b8d..ef90a85 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,6 +8,7 @@ GEM PLATFORMS ruby + x64-mingw32 DEPENDENCIES cinch diff --git a/README.md b/README.md index 6a83145..74ceae3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ MOSBot    [![alt text](https://api.codeclimate.com/v1/badges/6ddeda072827f6726041/maintainability)](https://codeclimate.com/github/anderlechtt/mos_bot/maintainability) ====== -A bot playing [Marbles On Stream](http://pixelbypixelcanada.com/mos.html) with Twitch streamers. Written in Ruby. +A bot playing [Marbles On Stream](http://pixelbypixelcanada.com/mos.html) with Twitch streamers. Written in Ruby, migrated to Helix. How does it work? ----------------- diff --git a/config.yml b/config.yml index 40d8cd0..4b11248 100644 --- a/config.yml +++ b/config.yml @@ -1,7 +1,7 @@ twitch_api: - username: - oauth_key: - client_id: + username: WhiteTP0ison + oauth_key: oauth:pxgjaq3z3solytc9gfv0fpgx4xi19t + client_id: uykrh1vnt03mp6z69kf9hvyw0rl60q mos_bot: log_level: info update_channels_timer_interval: 120 # 2 minutes diff --git a/lib/plugins/mos_bot_plugin.rb b/lib/plugins/mos_bot_plugin.rb index ba6a936..7e168c6 100644 --- a/lib/plugins/mos_bot_plugin.rb +++ b/lib/plugins/mos_bot_plugin.rb @@ -108,4 +108,4 @@ def play(chan) logger.info "[#{chan}] PLAY REQUESTED! triggered on " \ "#{@channels[chan].play_requests} play requests" end -end +end \ No newline at end of file diff --git a/lib/stream_finder.rb b/lib/stream_finder.rb index e756667..9eb203b 100644 --- a/lib/stream_finder.rb +++ b/lib/stream_finder.rb @@ -3,13 +3,13 @@ # uses twich api to get mos live streams class StreamFinder def self.fetch_streams - url = 'https://api.twitch.tv/kraken/streams/' + url = 'https://api.twitch.tv/helix/streams/' options = { headers: { 'Client-ID' => Settings.twitch_api['client_id'] }, format: :plain, - query: { game: 'Marbles On Stream' } + query: { game_id: '509511' } } data = HTTParty.get(url, options) @@ -18,8 +18,8 @@ def self.fetch_streams def self.parse_stream(stream) { - stream[:channel][:name] => { - viewers: stream[:viewers], + stream[:user_name] => { + viewers: stream[:viewer_count], updated_at: Time.now } } @@ -28,10 +28,10 @@ def self.parse_stream(stream) def self.parse_streams(streams, min_viewers, max_channels) channels = {} - if streams[:_total] > 0 - streams[:streams].each do |stream| + if streams[:data].count > 0 + streams[:data].each do |stream| break if channels.size >= max_channels - next if stream[:viewers] < min_viewers + next if stream[:viewer_count] < min_viewers channels.merge! parse_stream(stream) end @@ -44,4 +44,4 @@ def self.find(min_viewers = 40, max_channels = 20) streams = fetch_streams parse_streams(streams, min_viewers, max_channels) end -end +end \ No newline at end of file From 3efda551dae656848e5a5aa268fe4b97039a85b9 Mon Sep 17 00:00:00 2001 From: "Jared M. White" Date: Tue, 8 Jun 2021 11:09:18 -0500 Subject: [PATCH 2/3] Obfuscate personal info --- config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config.yml b/config.yml index 4b11248..4a2c77d 100644 --- a/config.yml +++ b/config.yml @@ -1,7 +1,7 @@ twitch_api: - username: WhiteTP0ison - oauth_key: oauth:pxgjaq3z3solytc9gfv0fpgx4xi19t - client_id: uykrh1vnt03mp6z69kf9hvyw0rl60q + username: + oauth_key: + client_id: mos_bot: log_level: info update_channels_timer_interval: 120 # 2 minutes From 3f45b0e911fcac61cb3c9e4fadf3c2df44e241fb Mon Sep 17 00:00:00 2001 From: Jared White Date: Tue, 8 Jun 2021 12:12:18 -0500 Subject: [PATCH 3/3] Fix errors --- config.yml | 6 +++--- lib/stream_finder.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config.yml b/config.yml index 4b11248..91e5ce1 100644 --- a/config.yml +++ b/config.yml @@ -1,7 +1,7 @@ twitch_api: - username: WhiteTP0ison - oauth_key: oauth:pxgjaq3z3solytc9gfv0fpgx4xi19t - client_id: uykrh1vnt03mp6z69kf9hvyw0rl60q + username: + oauth_key: + client_id: mos_bot: log_level: info update_channels_timer_interval: 120 # 2 minutes diff --git a/lib/stream_finder.rb b/lib/stream_finder.rb index 9eb203b..c8b4ae8 100644 --- a/lib/stream_finder.rb +++ b/lib/stream_finder.rb @@ -28,7 +28,7 @@ def self.parse_stream(stream) def self.parse_streams(streams, min_viewers, max_channels) channels = {} - if streams[:data].count > 0 + if Array(streams[:data]).count > 0 streams[:data].each do |stream| break if channels.size >= max_channels next if stream[:viewer_count] < min_viewers