diff options
Diffstat (limited to 'crystal')
-rw-r--r-- | crystal/eventsub.cr | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/crystal/eventsub.cr b/crystal/eventsub.cr index 48b3762..6014ebf 100644 --- a/crystal/eventsub.cr +++ b/crystal/eventsub.cr @@ -1,7 +1,7 @@ require "pretty_print" require "json" require "openssl/hmac" - +require "obswebsocket" puts "Content-type: text/plain; charset=UTF-8" puts @@ -15,6 +15,30 @@ settings = Hash(String, String).new end end +# enable explosions? +explosions = Hash( String, String ).new +if File.exists?( settings["configdir"] + "/explosionlist.txt" ) + File.each_line( settings["configdir"] + "/explosionlist.txt" ) do |line| + explosions[ line.downcase ] = line + end +end + +obs = OBSWebSocket::Server.new( "ws://127.0.0.1:4455/" ) + +def obstemporarymediacreate( obs : OBSWebSocket::Server, sname : String, iname, path : String ) + iname = "media-temporary-explosion-#{iname}" + isettings = Hash( String, String | Bool | Int64 | Float64 ){ + "advanced" => true, + "clear_on_media_end" => true, + "color_range" => 0.to_i64, + "is_local_file" => true, + "looping" => false, + "restart_on_activate" => true, + "local_file" => path, + } + response = obs.scenes[sname].createinput( iname, "ffmpeg_source", isettings ) +end + def ircmsg( channel : String, msg : String) if msg !~ /(\r|\n)/ sock = Socket.unix @@ -77,7 +101,14 @@ File.open("/tmp/eventsub.#{Process.pid}.txt", "w", 0o644 ) do |file| sub_broadcaster = ( json["event"]["broadcaster_user_login"]?.as_s? || "unknown" ) sub_plan = ( json["event"]["tier"]?.as_s? || "unknown" ) #sub_months = ( json["event"]["cumulative_months"]?.as_i? || 0 ) - effectsmsg( "overlay gltext 10 " + sub_recver + " subscribed!" ) + unless json["event"]["is_gift"].as_bool + effectsmsg( "overlay gltext 10 " + sub_recver + " subscribed!" ) + spawn do + explosions.values.sample( 5 ).each do | explosion | + obstemporarymediacreate( obs, "meta-foreground", explosion, "C:/cygwin64/home/user/effects/explosions/#{explosion}.webm" ) + end + end + end ircmsg( settings["channel"], sub_recver.to_s + " has subscribed at sub level #" + sub_plan.to_s + " bungmoBlobDance bungmoBlobDance bungmoBlobDance bungmoBlobDance" ) when "channel.subscription.gift" sub_sender = ( json["event"]["user_login"]?.as_s? || "anonymous" ) @@ -87,6 +118,13 @@ File.open("/tmp/eventsub.#{Process.pid}.txt", "w", 0o644 ) do |file| sub_cumulative = ( json["event"]["cumulative_total"]?.as_i? || 0 ) effectsmsg( "overlay gltext 10 #{sub_sender} donated #{sub_total} subs!" ) ircmsg( settings["channel"], "#{sub_sender} has gifted #{sub_total} tier #{sub_plan} subscription for a total of #{sub_cumulative}" ) + spawn do + count = sub_total * 5 + ( count > 50 ) && ( count = 50 ) + explosions.values.sample( count ).each do | explosion | + obstemporarymediacreate( obs, "meta-foreground", explosion, "C:/cygwin64/home/user/effects/explosions/#{explosion}.webm" ) + end + end when "channel.subscription.message" sub_sender = ( json["event"]["user_login"]?.as_s? || "anonymous" ) sub_plan = ( json["event"]["tier"]?.as_s? || "unknown" ) |