summaryrefslogtreecommitdiff
path: root/crystal
diff options
context:
space:
mode:
Diffstat (limited to 'crystal')
-rw-r--r--crystal/bungmobott.cr60
1 files changed, 38 insertions, 22 deletions
diff --git a/crystal/bungmobott.cr b/crystal/bungmobott.cr
index 8a60697..29bc46f 100644
--- a/crystal/bungmobott.cr
+++ b/crystal/bungmobott.cr
@@ -309,13 +309,15 @@ connections = Hash(OpenSSL::SSL::Socket::Server, Hash(String, String)).new
gamesurgeircifc = Channel( Tuple( String, String ) ).new
# commandifc: serv, chan, user, msg
commandifc = Channel( Tuple( String, FastIRC::Message ) ).new
-# t2sifc: voice, text
+# t2sifc: voice, text
t2sifc = Channel( Tuple( String, String ) ).new
twitchircifc = Channel( Tuple( String, String ) ).new
twitchapiifc = Channel( Tuple( String, String | UInt64 ) ).new
bbscliifc = Channel( String ).new
# currently unused
-#bbssrvifc = Channel( String ).new
+# bbssrvifc = Channel( String ).new
+# FIXME: need to channel up subscriptions between command_dispatch/bbssrv and twitchapi
+#twitchapieventsubs = Hash( Channel( String ) )
waitgroup = Channel( String ).new
fiberifc = Channel( Fiber ).new
fibers = Hash( String, Fiber ).new
@@ -763,15 +765,14 @@ spawn name: "command_dispatch" do
next unless ( userlogreturn = userlog( config, service, message ) )
chatuser, uid, userdir, lastseen, oldname = userlogreturn
- pp userlogreturn
# Have we seen this user lately?
if ( ( Time.utc.to_unix - lastseen ) >= 14400 )
if service =~ /^twitch/ && uid.is_a?( UInt64 )
if twitchapi
- puts( "#{Fiber.current.name} tx twitchapiifc: get_user, #{uid}" )
- twitchapiifc.send( { "get_user", uid.to_s } )
- puts( "#{Fiber.current.name} tx twitchapiifc: get_followers, #{uid}" )
- twitchapiifc.send( { "get_followers", uid.to_s } )
+ send_and_log( twitchapiifc, { "get_user", uid.to_u64 } )
+ send_and_log( twitchapiifc, { "get_followers", uid.to_u64 } )
+ elsif fibers["BungmoBott::Socket client"]?
+ send_and_log( bbscliifc, "twitchapigetuser id:#{uid}" )
end
prevnames = Array( String ).new
if ( prevnames = Dir.children( Path.new( userdir, "names" ).normalize ) ) && ( prevnames.size > 1 )
@@ -837,9 +838,26 @@ spawn name: "command_dispatch" do
# As a matter of policy:
# BungmoBott::Socket clients can only say things in their own authenticated channel
# Direct IRC clients can say things whereever.
- if ( service =~ /^twitch/ && exec.func == "detect_rename" && uid.is_a?( UInt64 ) )
- if oldname.is_a?( String )
- say( service, config.chat_user.not_nil!.twitch.not_nil!, "Rename detected: #{uid}: #{oldname} -> #{chatuser}" )
+ if service =~ /^twitch/
+ if ( exec.func == "detect_rename" && uid.is_a?( UInt64 ) )
+ if oldname.is_a?( String )
+ say( service, config.chat_user.not_nil!.twitch.not_nil!, "Rename detected: #{uid}: #{oldname} -> #{chatuser}" )
+ end
+ next
+ end
+
+ end
+ if ( exec.func == "twitchapi_get_user" )
+ if ( match = / ([a-zA-Z0-9_]+)/.match( message.params[1] ) )
+ if twitchapi
+ send_and_log( twitchapiifc, { "get_user", match[1] } )
+ elsif fibers["BungmoBott::Socket client"]?
+ send_and_log( bbscliifc, "twitchapigetuser name:#{match[1]}" )
+ else
+ say( service, ircchannel, "| No Twitch API access configured." )
+ end
+ else
+ say( service, ircchannel, "| Requires twitch username as argument." )
end
next
end
@@ -1076,14 +1094,7 @@ spawn name: "command_dispatch" do
# gamesurgeircifc.send( { "##{settings["channel"]}", "Must provide at least one source name as argument." } )
# end
# # FIXME: This is only half-implemented
-# elsif ( ( cmd =~ /^(user)$/ ) && ( mod || own ) )
-# if match[2]? && match[2] =~ /[a-z][a-z0-9_]+/
-# twitchapiifc.send( { "get_user", match[2] } )
-# elsif match[2]? && match[2] =~ /[0-9]+/
-# twitchapiifc.send( { "get_user", match[2].to_u64 } )
-# else
-# twitchapiifc.send( { "get_user", settings["channel_id"].to_u64 } )
-# end
+
# elsif ( ( cmd =~ /^(status|title)$/ ) && ( mod || own ) )
# if match[2]?
# client.put_channel!( settings["channel_id"].to_u64, title: match[2] )
@@ -1323,7 +1334,6 @@ if twitchclient.is_a?( Twitcr::Client )
case cmd
when "get_user"
userinfo = JSON.parse( twitchclient.get_user( arg ) )["data"][0]
- pp userinfo
unless userinfo["broadcaster_type"].as_s.blank?
puts "\033[38;5;12m#{userinfo["login"]} is #{userinfo["broadcaster_type"]}\033[0m"
end
@@ -1464,7 +1474,7 @@ if ( secrets.gamesurge_password && config.chat_user.not_nil!.gamesurge && config
begin
bot = GameSurge::IRC::Client.new( nick: config.chat_user.not_nil!.gamesurge.not_nil!, token: secrets.gamesurge_password.not_nil!, log_mode: true )
bot.tags = [ "membership", "tags", "commands" ]
-
+
# Outgoing IRC message fiber
# "Most IRC servers limit messages to 512 bytes in length, including the trailing CR-LF characters."
# PRIVMSG #channel message\r\n
@@ -1540,8 +1550,6 @@ if ( secrets.gamesurge_password && config.chat_user.not_nil!.gamesurge && config
# else
# gamesurgeircifc.send( { "##{settings["channel"]}", "| current sources: #{obs.scenes["meta-bullshit"].to_h.keys.map{ | s | s.sub( /^medialoop-bullshit-/, "") } .join(" ")}" } )
# end
-# elsif ( cmd =~ /^(system|dxdiag|computer)$/ ) && ( Crystal::DESCRIPTION =~ /linux/ )
-# gamesurgeircifc.send( { "##{settings["channel"]}", "| https://bungmonkey.omgwallhack.org/tmp/DxDiag.txt" } )
# end
rescue ex
pp ex
@@ -1725,6 +1733,14 @@ if config.bungmobott_listen
end
elsif ( match = message.match( /^say (twitch|gamesurge) (.+)/i ) )
say( match[1], connections[client]["user"], match[2] )
+ elsif ( message =~ /^twitchapi/i)
+ if ( twitchapi )
+ if ( match = message.match( /^twitchapigetuser id:(\d+)/i ) )
+ send_and_log( twitchapiifc, { "get_user", match[1].to_u64 } )
+ elsif ( match = message.match( /^twitchapigetuser name:(\w+)/i ) )
+ send_and_log( twitchapiifc, { "get_user", match[1] } )
+ end
+ end
elsif ( message =~ /testchannelsubs/ )
#commandifc.send( "testchannelsubs" )
end