diff options
-rw-r--r-- | crystal/lib/bungmobott/src/bungmobott.cr | 2 | ||||
-rw-r--r-- | crystal/tcpsocket.cr | 33 |
2 files changed, 30 insertions, 5 deletions
diff --git a/crystal/lib/bungmobott/src/bungmobott.cr b/crystal/lib/bungmobott/src/bungmobott.cr index 8c7f755..4fdb9d2 100644 --- a/crystal/lib/bungmobott/src/bungmobott.cr +++ b/crystal/lib/bungmobott/src/bungmobott.cr @@ -40,7 +40,7 @@ module BungmoBott include YAML::Serializable::Unmapped property perm : Array( String )? = nil property func : String - property arg : Array( String? )? = nil + property arg : Array( String )? = nil end class JoinChannels diff --git a/crystal/tcpsocket.cr b/crystal/tcpsocket.cr index 989233e..a330aaf 100644 --- a/crystal/tcpsocket.cr +++ b/crystal/tcpsocket.cr @@ -18,7 +18,7 @@ struct Nil def as_s? self end - def []?( v : String | Int ) + def []?( v : String | Int64 | Int32 | Range( Int32, Nil ) ) self end end @@ -617,7 +617,6 @@ spawn name: "command_dispatch" do if local_commandmsg.is_a?( Tuple( String, FastIRC::Message ) ) && local_commandmsg[0].is_a?( String ) service = local_commandmsg[0] message : FastIRC::Message = local_commandmsg[1] - pp message ircchannel = message.params[0] unless service.empty? if config.bungmobott_listen && ! ircchannel.empty? @@ -730,6 +729,32 @@ spawn name: "command_dispatch" do end next end + if ( exec.func == "run" ) + if ( cmd = exec.arg[0]? ) && File.executable?( cmd ) + p = Process.new( + cmd, exec.arg[1..]?, output: STDOUT, error: STDERR, + env: { + "TEXT" => message.params[1], + "CHATUSER" => chatuser + } + ) + else + STDERR.puts( "WARNING: exec.func \"run\" called without argument" ) + end + end + if ( exec.func == "run_shell" ) + if ( cmd = exec.arg[0]? ) + p = Process.new( + cmd, exec.arg[1..]?, output: STDOUT, error: STDERR, shell: true, + env: { + "TEXT" => message.params[1], + "CHATUSER" => chatuser + } + ) + else + STDERR.puts( "WARNING: exec.func \"run_shell\" called without argument" ) + end + end STDERR.puts "WARNING: unhandled function for /#{commandregex}/: #{exec.func}" else STDOUT.print "DENIED: " @@ -1542,7 +1567,7 @@ if config.bungmobott_listen if ircservice == "twitch" client.puts "joining #{ircservice} \##{ircchannel}" twitchircipc.send( { "JOIN", ircchannel } ) - unless channelsubs[ { ircservice, ircchannel } ]? + unless channelsubs[ { ircservice, "#" + ircchannel } ]? channelsubs[ { ircservice, "#" + ircchannel } ] = Array( OpenSSL::SSL::Socket::Server ).new end channelsubs[ { ircservice, "#" + ircchannel } ].push( client ) @@ -1550,7 +1575,7 @@ if config.bungmobott_listen elsif ircservice == "gamesurge" client.puts "joining #{ircservice} \##{ircchannel}" ircipc.send( { "JOIN", ircchannel } ) - unless channelsubs[ { ircservice, ircchannel } ]? + unless channelsubs[ { ircservice, "#" + ircchannel } ]? channelsubs[ { ircservice, "#" + ircchannel } ] = Array( OpenSSL::SSL::Socket::Server ).new end channelsubs[ { ircservice, "#" + ircchannel } ].push( client ) |