summaryrefslogtreecommitdiff
path: root/crystal/tcpsocket.cr
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk+git@omgwallhack.org>2024-02-13 09:44:57 -0800
committerJoe Rayhawk <jrayhawk@fairlystable.org>2024-02-13 09:55:11 -0800
commit7aaf5b316e7b6453d5b945dfd63e3b3cd855b2bc (patch)
treec1e4ab2cb99ba8ade93c695279b2382f8167d727 /crystal/tcpsocket.cr
parentff166fb7da17f65b8b4e65df6b7e2fe0e879b46f (diff)
downloadtwitchtools-7aaf5b316e7b6453d5b945dfd63e3b3cd855b2bc.tar.gz
twitchtools-7aaf5b316e7b6453d5b945dfd63e3b3cd855b2bc.zip
crystal/tcpsocket: support "run" and "run_shell" functions
Diffstat (limited to 'crystal/tcpsocket.cr')
-rw-r--r--crystal/tcpsocket.cr33
1 files changed, 29 insertions, 4 deletions
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 )