summaryrefslogtreecommitdiff
path: root/crystal/bungmobott.cr
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk+git@omgwallhack.org>2022-11-21 22:57:17 -0800
committerJoe Rayhawk <jrayhawk@omgwallhack.org>2022-11-21 23:42:15 -0800
commit47adaa9a252f82688eabbf6f18d9ddd786e1cb70 (patch)
tree8c5a2e84d24eaa1e0908ebd0f554335125de9b31 /crystal/bungmobott.cr
parent900cfd41163c906e054b1a1cad557e2df3947322 (diff)
downloadtwitchtools-47adaa9a252f82688eabbf6f18d9ddd786e1cb70.tar.gz
twitchtools-47adaa9a252f82688eabbf6f18d9ddd786e1cb70.zip
crystal: crystal-obs-websocket API updates
Diffstat (limited to 'crystal/bungmobott.cr')
-rwxr-xr-xcrystal/bungmobott.cr35
1 files changed, 25 insertions, 10 deletions
diff --git a/crystal/bungmobott.cr b/crystal/bungmobott.cr
index 34c2328..642d0b3 100755
--- a/crystal/bungmobott.cr
+++ b/crystal/bungmobott.cr
@@ -112,7 +112,7 @@ ircipc = Channel( Tuple( String, String ) ).new
t2sipc = Channel( Tuple( String, String ) ).new
twitchipc = Channel( Tuple( String, Union( String, UInt64 ) ) ).new
-obs = OBSWebSocket::Server.new( "ws://127.0.0.1:4455/" )
+obs = OBS::WebSocket.new( "ws://127.0.0.1:4455/" )
# OBS event thread
spawn do
@@ -122,7 +122,7 @@ spawn do
obs.inputs[key].delete!
end
end
- obs.reqchan.send( { evchan, "subscribe events" } )
+ obs.eventsub_add( evchan )
while json = evchan.receive
# A Fiber.yield occurs after this to make sure "json" doesn't get overwritten before we can use it.
spawn do
@@ -132,7 +132,7 @@ spawn do
ircipc.send( { "#" + settings["channel"], "| obs: switched scene to " + ( d["eventData"]["sceneName"]?.as_s? || "unknown" ) } )
when "MediaInputPlaybackEnded"
if d["eventData"]["inputName"].as_s =~ /^media-temporary-/
- obs.reqchan.send( { nil, OBSWebSocket.req( "RemoveInput", UUID.random.to_s, JSON.parse({ "inputName" => d["eventData"]["inputName"].as_s }.to_json) ) } )
+ obs.send( OBS.req( "RemoveInput", UUID.random.to_s, JSON.parse({ "inputName" => d["eventData"]["inputName"].as_s }.to_json) ) )
elsif d["eventData"]["inputName"].as_s =~ /^media-/
obs.scenes.current.metascene[d["eventData"]["inputName"].as_s][0].disable!
end
@@ -162,7 +162,7 @@ spawn do
end
when "SourceFilterEnableStateChanged"
edata = d["eventData"]
- ircipc.send( { "##{settings["channel"]}", "| obs: source #{edata["sourceName"].as_s} filter #{edata["filterName"].as_s} visibility is currently #{edata["filterEnabled"].as_s}" } )
+ ircipc.send( { "##{settings["channel"]}", "| obs: source #{edata["sourceName"].as_s} filter #{edata["filterName"].as_s} visibility is currently #{edata["filterEnabled"].as_bool}" } )
end
end
Fiber.yield
@@ -197,7 +197,16 @@ spawn do
end
end
-def obstemporarymediacreate( obs : OBSWebSocket::Server, sname : String, iname, path : String )
+def obsrandommediaenable( obs : OBS::WebSocket, siname : String )
+ if ( Random.rand(3) < 2 )
+ obs.scenes.current.metascene[siname][0].enable!
+ else
+ randsiname = obs.scenes.current.metascene.keys.select( /^#{siname}/ ).sample( 1 )[0]
+ obs.scenes.current.metascene[randsiname][0].enable!
+ end
+end
+
+def obstemporarymediacreate( obs : OBS::WebSocket, sname : String, iname, path : String )
iname = "media-temporary-effect-#{iname}"
isettings = Hash( String, String | Bool | Int64 | Float64 ){
"advanced" => true,
@@ -212,7 +221,7 @@ def obstemporarymediacreate( obs : OBSWebSocket::Server, sname : String, iname,
# Skip ORM stuff and configure the SceneItem as fast as we possibly can
if ( rdata = response["responseData"]? ) && ( goodtransform = obs.sources.last_known_real_transform?( iname ) )
siid = rdata["sceneItemId"].as_i64
- obs.reqchan.send( { nil, OBSWebSocket.req( "SetSceneItemTransform", UUID.random.to_s, JSON.parse( { "sceneName" => sname, "sceneItemId" => siid, "sceneItemTransform" => { "positionX" => goodtransform.to_h["positionX"], "positionY" => goodtransform.to_h["positionY"] } }.to_json ) ) } )
+ obs.send( OBS.req( "SetSceneItemTransform", UUID.random.to_s, JSON.parse( { "sceneName" => sname, "sceneItemId" => siid, "sceneItemTransform" => { "positionX" => goodtransform.to_h["positionX"], "positionY" => goodtransform.to_h["positionY"] } }.to_json ) ) )
end
end
@@ -600,8 +609,15 @@ loop do
end
end
end
- if ( message.params[1] =~ /thanks.*obama/i )
- obs.scenes["meta-foreground"]["media-youdied-thanksobama"].enable!
+ case message.params[1]
+ when /pl(ease|z).+nerf/i
+ obsrandommediaenable( obs, "media-youdied-nerf" )
+ when /you.+died/i
+ obsrandommediaenable( obs, "media-youdied" )
+ when /did +nothing +wrong/i
+ obsrandommediaenable( obs, "media-youdied-tiggs" )
+ when /thanks.+obama/i
+ obsrandommediaenable( obs, "media-youdied-thanksobama" )
end
next unless ( ( match = message.params[1].match(/^ *!([A-Za-z]+) (([a-zA-Z0-9= _\:,.&'\/?;\\\(\)\[\]+\-]|!)+)/) || message.params[1].match(/^ *!([A-Za-z]+)/) ) )
cmd = match[1]
@@ -717,7 +733,7 @@ loop do
ircipc.send( { "##{settings["channel"]}", "Must provide at least one source name as argument." } )
end
elsif ( cmd =~ /^(metaminute|youdied)$/ )
- obs.scenes.current.metascene["media-#{cmd}"][0].enable!
+ obsrandommediaenable( obs, "media-#{cmd}" )
elsif ( cmd =~ /^fart(s|)$/ ) && ( sub || mod || own || vip )
if effects.values.select( /^farts/ ).size > 0
if ( match[2]? ) && ( match[2].match( /^([0-9]+)/ ) && ( match[2].to_i > 1 ) && ( match[2].to_i <= 32 ) )
@@ -777,7 +793,6 @@ loop do
if match[2]? && match[2] =~ /^([a-zA-Z0-9 -])+$/
definition = urbandef( match[2] )
ircipc.send( { "##{settings["channel"]}", definition[0,400] } )
- # FIXME: maybe somehow fold this into the existing voice logic
t2s( t2sipc, settings, userdir, chatuser, definition[0,400] )
else
ircipc.send( { "##{settings["channel"]}", "| Urban Dictionary search term should consist of letters, numbers, spaces, and/or hyphens." } )