summaryrefslogtreecommitdiff
path: root/crystal
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk+git@omgwallhack.org>2022-08-01 03:43:23 -0700
committerJoe Rayhawk <jrayhawk+git@omgwallhack.org>2022-08-01 03:43:23 -0700
commit6e29c3d5c02eeb4892dc0088b0198c6b2e539f28 (patch)
tree1338ced7ad9e4a3011927c412356691986301219 /crystal
parent71fa23de2e0b45c3333a87ff18a95c0f28869108 (diff)
downloadtwitchtools-6e29c3d5c02eeb4892dc0088b0198c6b2e539f28.tar.gz
twitchtools-6e29c3d5c02eeb4892dc0088b0198c6b2e539f28.zip
bungmobott: More fixes to meta scene sources, handle media sources more intelligently, generalize pipne fanfare.
Diffstat (limited to 'crystal')
-rwxr-xr-xcrystal/bungmobott.cr109
1 files changed, 71 insertions, 38 deletions
diff --git a/crystal/bungmobott.cr b/crystal/bungmobott.cr
index 671ca3c..396b5db 100755
--- a/crystal/bungmobott.cr
+++ b/crystal/bungmobott.cr
@@ -141,8 +141,10 @@ def userlog( ircipc : Channel, settings : Hash(String, String), message : FastIR
end
basedir = settings["statedir"]
userdir = basedir + "/uids/" + uid
+ lastseen = File.info( userdir ).modification_time.to_unix
Dir.mkdir_p( basedir + "/names" )
Dir.mkdir_p( userdir + "/names" )
+ File.touch( userdir )
unless testrefuser2uid( userdir + "/names/" + chatuser )
namelatest = ""
datelatest = Time::UNIX_EPOCH
@@ -164,7 +166,7 @@ def userlog( ircipc : Channel, settings : Hash(String, String), message : FastIR
unless ( message.params[0] == "##{settings["channel"]}" )
return nil
end
- return ( [ chatuser, uid, userdir ] )
+ return ( { chatuser, uid, userdir, lastseen } )
rescue ex
puts ex
end
@@ -459,7 +461,7 @@ spawn do
spawn do
while msg = obsipc.receive
pp msg
- if ( match = msg.match( /^\x10source ([a-z0-9-_]+)/ ) )
+ if ( match = msg.match( /^\x10source ([a-z0-9-_]+)/ ) )
source = match[1]
sources = reversesource( scenes, currentscene )
pp sources
@@ -467,14 +469,29 @@ spawn do
request["request-type"] = "SetSceneItemProperties"
request["message-id"] = "SetSceneItemProperties"
#request["request-type"] = "GetSceneItemProperties"
- scene = sources[source]
- request["scene-name"] = sources[source]
+ unless ( scene = sources[source]? )
+ ircipc.send( { "#" + settings["channel"], "| obs: source not found: #{source}" } )
+ next
+ end
+ request["scene-name"] = scene
request["item"] = source
if ( match = msg.match( /^\x10source ([a-z0-9-_]+) (true|false)/ ) )
request["visible"] = ( match[2] == "true" )
obs_pubsub.send( request.to_json )
elsif ( match = msg.match( /^\x10source ([a-z0-9-_]+)/ ) )
- request["visible"] = ( scenes[scene][source]["render"]? == true )
+ pp scenes[scene][source]["render"]
+ request["visible"] = ( scenes[scene][source]["render"]? != true )
+ # use a random similarly named source instead?
+ randsources = sources.keys.select!{ |x| x =~ /^#{source}/}
+ if ( randsources.size > 1 )
+ #if Random.new.next_bool # 50/50
+ if Random.new.rand(5) == 0 # 20/80
+ source = randsources.sample
+ scene = sources[source]
+ request["scene-name"] = scene
+ request["item"] = source
+ end
+ end
obs_pubsub.send( request.to_json )
end
elsif ( match = msg.match( /^\x10source/ ) )
@@ -504,27 +521,44 @@ spawn do
currentscene = json["scene-name"].as_s
puts "currentscene is " + currentscene
when "MediaEnded"
- request = Hash( String, String | Bool ){
- "request-type" => "SetSceneItemProperties",
- "message-id" => "SetSceneItemProperties",
- "item" => json["sourceName"].as_s,
- "visible" => false
- }
- ircipc.send( { "##{settings["channel"]}", "Disabling #{json["sourceName"].as_s}" } )
- obsipc.send( request.to_json )
- #"sourceName": "media-youdied"
- puts "currentscene is " + currentscene
- if ( ( json["sourceName"].as_s =~ /^media-/ ) && ( currentscene != "meta" ) )
- request = Hash( String, String | Hash( String, String ) ){
- "request-type" => "DeleteSceneItem",
- "message-id" => "DeleteSceneItem",
- "item" => { "name" => json["sourceName"].as_s },
+ pp json
+ source = json["sourceName"].as_s
+ sources = reversesource( scenes, currentscene )
+ scene = sources[source]
+ if scenes[scene][source]["render"] == true
+ request = Hash( String, String | Bool ){
+ "request-type" => "SetSceneItemProperties",
+ "message-id" => "SetSceneItemProperties",
+ "scene-name" => scene,
+ "item" => source,
+ "visible" => false
}
- ircipc.send( { "##{settings["channel"]}", "Deleting #{json["sourceName"].as_s}" } )
+ ircipc.send( { "##{settings["channel"]}", "| obs: Media ended; disabling #{source}" } )
obsipc.send( request.to_json )
end
+# If we want to start deleting temporary media sources?
+# if ( ( source =~ /^media-/ ) && ( scene !~ /^meta/ ) )
+# request = Hash( String, String | Hash( String, String ) ){
+# "request-type" => "DeleteSceneItem",
+# "message-id" => "DeleteSceneItem",
+# "item" => { "name" => json["sourceName"].as_s },
+# }
+# ircipc.send( { "##{settings["channel"]}", "Deleting #{source}" } )
+# obsipc.send( request.to_json )
+# end
when "SourceFilterVisibilityChanged"
ircipc.send( { "##{settings["channel"]}", "| obs: source #{json["sourceName"]} filter #{json["filterName"]} visibility is currently #{json["filterEnabled"]}" } )
+ when "SourceRenamed"
+ sourceprev = json["previousName"].as_s
+ sourcenew = json["newName"].as_s
+ # does not tell us the scenes involved?
+ # Will have to iterate through them.
+ scenes.keys.each{ | scene |
+ if scenes[scene][sourceprev]?
+ scenes[scene][sourcenew] = scenes[scene][sourceprev]
+ scenes[scene].delete(sourceprev)
+ end
+ }
when "SceneItemVisibilityChanged"
scenes[json["scene-name"].as_s][json["item-name"].as_s]["render"] = json["item-visible"].as_bool
ircipc.send( { "##{settings["channel"]}", "| obs: source #{json["item-name"]} visibility is now #{json["item-visible"].as_bool}" } )
@@ -536,7 +570,8 @@ spawn do
when /^GetCurrentScene/
currentscene = json["name"].as_s
if json["message-id"].as_s? !~ /Quietly/
- ircipc.send( { "#" + settings["channel"], "| obs: " + json["sources"].as_a.map{ |source| source["name"] }.join(", ") } )
+ sources = reversesource( scenes, currentscene )
+ ircipc.send( { "#" + settings["channel"], "| obs: " + sources.keys.join(", ") } )
end
when "GetSourceFilters"
ircipc.send( { "#" + settings["channel"], "| obs: " + json["filters"].as_a.map{ |filter| "#{filter["name"].as_s}: #{filter["enabled"].as_bool}" }.join(", ") } )
@@ -615,10 +650,19 @@ loop do
bot.on_message do |message|
spawn do
next unless ( userlogreturn = userlog( ircipc, settings, message ) )
- chatuser, uid, userdir = userlogreturn
- if ( chatuser == "pipne" ) && ( ( Time.utc.to_unix - snifflast ) >= 14400 )
- snifflast = Time.utc.to_unix
- t2smsg( settings, chatuser + " sniff null" )
+ chatuser, uid, userdir, lastseen = userlogreturn
+ # play random fanfare if available.
+ if ( ( Time.utc.to_unix - lastseen ) >= 14400 )
+ {% if flag?(:windows) %}
+ # This file hierarchy gets manually set up for now.
+ # Maybe someday let mods do something like:
+ # !fanfare add pipne https://pip.ne/sniff.mp3
+ if File.exists?( userdir + "/fanfare/" )
+ playaudiofile( userdir + "/fanfare/" + Dir.children( userdir + "/fanfare/" ).sample )
+ end
+ {% else %}
+ t2smsg( settings, "fanfare #{uid} #{chatuser}" )
+ {% end %}
end
if ( t2sreturn = t2s( t2sipc, settings, userdir, chatuser, message.params[1] ) )
lastvoice.insert( 0, t2sreturn )
@@ -744,18 +788,7 @@ loop do
ircipc.send( { "##{settings["channel"]}", "Must provide at least one source name as argument." } )
end
elsif ( cmd =~ /^(metaminute|youdied)$/ )
- request = Hash( String, String | Bool ).new
- request["request-type"] = "SetSceneItemProperties"
- request["message-id"] = "SetSceneItemProperties"
- request["item"] = "media-" + cmd
- # This breaks playback (???)
- #request["visible"] = false
- #obsipc.send( request.to_json )
- #sleep 0.5
- # I should probably set this up to add the source, and then delete the source at the end of playback.
- request["visible"] = true
- #ircipc.send( { "##{settings["channel"]}", "Playing media-#{cmd}" } )
- obsipc.send( request.to_json )
+ obsipc.send( "\x10source media-#{cmd}" )
elsif ( ( cmd =~ /^(status|title)$/ ) && ( mod || own ) )
begin
if match[2]?