2011-09-20 03:53:01 +00:00
|
|
|
#!/bin/rc
|
|
|
|
|
|
|
|
rfork ne
|
|
|
|
|
|
|
|
server=irc.freenode.net
|
|
|
|
port=6667
|
|
|
|
realname='<nil>'
|
|
|
|
target=''
|
|
|
|
netdir=()
|
|
|
|
nick=$user
|
|
|
|
pass=()
|
2014-12-28 07:38:21 +00:00
|
|
|
tls=0
|
2015-09-19 18:03:22 +00:00
|
|
|
serverpass=()
|
2011-09-20 03:53:01 +00:00
|
|
|
|
|
|
|
fn sighup {
|
|
|
|
exit 'hang up'
|
|
|
|
}
|
|
|
|
|
|
|
|
fn sigint sigterm {
|
|
|
|
if (! ~ $#netdir 0)
|
|
|
|
echo QUIT : Leaving... > $netdir/data
|
|
|
|
}
|
|
|
|
|
|
|
|
fn mshift {
|
|
|
|
shift
|
|
|
|
echo $*
|
|
|
|
}
|
|
|
|
|
|
|
|
fn etime {
|
|
|
|
date | awk '{print $4}' | awk -F ':' '{print "[" $1 ":" $2 "]"}'
|
|
|
|
}
|
|
|
|
|
|
|
|
fn work {
|
2015-09-19 18:03:22 +00:00
|
|
|
if(~ $#serverpass 1)
|
|
|
|
echo PASS $serverpass > $netdir/data
|
2011-09-20 03:53:01 +00:00
|
|
|
echo USER $user foo bar :$realname > $netdir/data
|
|
|
|
echo NICK $nick > $netdir/data
|
|
|
|
if (~ $#pass 1)
|
|
|
|
echo PRIVMSG 'nickserv :'identify $"pass > $netdir/data
|
2012-10-12 17:13:34 +00:00
|
|
|
if(! ~ $target ''){
|
2012-10-11 23:05:34 +00:00
|
|
|
title
|
|
|
|
echo JOIN $target > $netdir/data
|
|
|
|
}
|
2013-01-30 04:56:29 +00:00
|
|
|
if(~ $target *,*)
|
|
|
|
target = `{echo $target | awk -F',' '{print $NF}'}
|
2014-12-28 07:38:21 +00:00
|
|
|
while (cmd=`{read}) {
|
2014-11-07 17:51:16 +00:00
|
|
|
s=$status
|
|
|
|
if(~ $s *eof) {
|
2013-01-30 04:56:29 +00:00
|
|
|
echo QUIT : Leaving... > $netdir/data
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
msg=()
|
|
|
|
out=()
|
2011-09-20 03:53:01 +00:00
|
|
|
switch ($cmd(1)) {
|
|
|
|
case /!
|
|
|
|
eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :' $rc | tee $netdir/data
|
|
|
|
case /M
|
|
|
|
msg = (MODE `{mshift $cmd})
|
|
|
|
case /N
|
|
|
|
cmd = `{mshift $cmd}
|
|
|
|
if (! ~ $#cmd 0)
|
|
|
|
msg = (NOTICE $cmd(1) : `{mshift $cmd})
|
|
|
|
case /T
|
|
|
|
msg = (TOPIC `{mshift $cmd})
|
|
|
|
case /W
|
|
|
|
msg = (WHOIS `{mshift $cmd})
|
|
|
|
case /a
|
|
|
|
msg = (AWAY : `{mshift $cmd})
|
|
|
|
case /j
|
|
|
|
if (~ $#cmd 2) {
|
|
|
|
target=$cmd(2)
|
|
|
|
title
|
|
|
|
msg = (JOIN `{mshift $cmd})
|
2013-01-30 04:56:29 +00:00
|
|
|
if(~ $target *,*)
|
|
|
|
target = `{echo $target | awk -F',' '{print $NF}'}
|
2011-09-20 03:53:01 +00:00
|
|
|
}
|
|
|
|
case /l
|
|
|
|
msg = (LIST `{mshift $cmd})
|
|
|
|
case /m
|
|
|
|
cmd = `{mshift $cmd}
|
|
|
|
if (! ~ $#cmd 0) {
|
|
|
|
to = $cmd(1)
|
|
|
|
cmd = `{mshift $cmd}
|
|
|
|
out = '('^$to^') ⇐ '^$"cmd
|
|
|
|
msg = 'PRIVMSG '^$to^' :'^$"cmd
|
|
|
|
}
|
|
|
|
case /n
|
|
|
|
nick = `{mshift $cmd}
|
|
|
|
msg = (NICK $nick)
|
|
|
|
case /p
|
|
|
|
cmd = `{mshift $cmd}
|
|
|
|
if (! ~ $#cmd 0)
|
|
|
|
msg = (PART $cmd(1) : `{mshift $cmd})
|
|
|
|
case /q
|
|
|
|
msg = `{mshift $cmd}
|
|
|
|
case /t
|
|
|
|
target = `{mshift $cmd}
|
|
|
|
title
|
|
|
|
case /u
|
|
|
|
msg = (USERS `{mshift $cmd})
|
|
|
|
case /w
|
|
|
|
msg = (WHO `{mshift $cmd})
|
|
|
|
case /x
|
|
|
|
echo QUIT : Leaving... > $netdir/data
|
|
|
|
exit
|
2013-01-30 04:56:29 +00:00
|
|
|
case /*
|
|
|
|
echo unknown command
|
2011-09-20 03:53:01 +00:00
|
|
|
case *
|
|
|
|
msg = 'PRIVMSG '^$target^' :'^$"cmd
|
|
|
|
out = '('^$target^') ⇐ '^$"cmd
|
|
|
|
}
|
|
|
|
if (! ~ $#msg 0)
|
|
|
|
echo $msg > $netdir/data
|
|
|
|
if (! ~ $#out 0)
|
|
|
|
echo `{etime}^' '^$out
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn misc {
|
|
|
|
sed '
|
|
|
|
s/^://
|
|
|
|
s/!~?[a-zA-Z0-9_@\-|.{=\/:]+ /:/' |
|
|
|
|
awk -F ':' '
|
|
|
|
{
|
|
|
|
s = $2 " «" $1 "»\t" $3;
|
|
|
|
for(i = 4; i < NF+1; i++)
|
|
|
|
s = s ":" $i;
|
|
|
|
printf("%s\n", s);
|
|
|
|
}'
|
|
|
|
}
|
|
|
|
|
|
|
|
fn notice {
|
|
|
|
sed '
|
|
|
|
s/^NOTICE /:'^$server^':/
|
|
|
|
s/^://
|
|
|
|
s/!~?[a-zA-Z0-9_@\-|.{=\/]+ /:/' |
|
|
|
|
awk -F ':' '
|
|
|
|
{
|
|
|
|
s = "-" $1 "- ⇒\t" $3;
|
|
|
|
for(i = 4; i < NF+1; i++)
|
|
|
|
s = s ":" $i;
|
|
|
|
printf("%s\n", s);
|
|
|
|
}'
|
|
|
|
}
|
|
|
|
|
|
|
|
fn numeric {
|
|
|
|
sed 's/^:[a-zA-Z0-9_@\-|.!=#]+ //
|
|
|
|
s/ '^$nick^' //
|
|
|
|
s/^353= /*** Users on /
|
|
|
|
s/^[0-9][0-9][0-9] ?:?/*** /'
|
|
|
|
}
|
|
|
|
|
|
|
|
fn privmsg {
|
|
|
|
sed '
|
|
|
|
s/^:/«/
|
|
|
|
s/!~?[a-zA-Z0-9_@\-|.{=\/:]+ PRIVMSG /» ⇒ :/
|
|
|
|
s/#[a-zA-Z0-9_@\-|.#]+/(&)/' |
|
|
|
|
awk -F ':' '
|
|
|
|
{
|
|
|
|
s = $2 $1 $3;
|
|
|
|
for(i = 4; i < NF+1; i++)
|
|
|
|
s = s ":" $i;
|
|
|
|
printf("%s\n", s);
|
|
|
|
}'
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pretty {
|
2014-12-28 07:38:21 +00:00
|
|
|
while (line=`{read}) {
|
2011-09-20 03:53:01 +00:00
|
|
|
switch ($line) {
|
2013-01-30 04:56:29 +00:00
|
|
|
case *PRIVMSG*
|
|
|
|
line = `{echo -n $line | privmsg}
|
2011-09-20 03:53:01 +00:00
|
|
|
case *JOIN* *QUIT* *PART* *NICK*
|
|
|
|
line = `{echo -n $line | misc}
|
|
|
|
case *NOTICE*
|
|
|
|
line = `{echo -n $line | notice}
|
|
|
|
case *PING*
|
|
|
|
echo -n $line | sed 's/PING/PONG/' > $netdir/data
|
|
|
|
line = ()
|
|
|
|
case *
|
|
|
|
line = `{echo -n $line | numeric}
|
|
|
|
}
|
|
|
|
if (! ~ $#line 0)
|
|
|
|
echo `{etime} $line
|
|
|
|
}
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
fn title {
|
|
|
|
if (! ~ $#winid 0) {
|
|
|
|
if (test -f /mnt/acme/$winid/ctl)
|
|
|
|
echo name /$server/$target/-ircrc > /mnt/acme/$winid/ctl
|
|
|
|
}
|
|
|
|
if not
|
2013-05-29 09:37:30 +00:00
|
|
|
label $target@$server
|
2011-09-20 03:53:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (~ $1 -*) {
|
|
|
|
switch ($1) {
|
|
|
|
case -n
|
|
|
|
nick=$2
|
|
|
|
shift
|
|
|
|
case -p
|
|
|
|
port=$2
|
|
|
|
shift
|
2015-09-19 18:03:22 +00:00
|
|
|
case -P
|
|
|
|
serverpass=$2
|
|
|
|
shift
|
2011-09-20 03:53:01 +00:00
|
|
|
case -r
|
|
|
|
realname=$2
|
|
|
|
shift
|
|
|
|
case -t
|
|
|
|
target=$2
|
|
|
|
shift
|
2014-12-28 07:38:21 +00:00
|
|
|
case -T
|
|
|
|
tls=1
|
2011-09-20 03:53:01 +00:00
|
|
|
case -*
|
2015-09-19 18:03:22 +00:00
|
|
|
echo 'usage: ircrc [-p port] [-P server password] [-r realname] [-t target] [-n nick] [-T] [server]' >[1=2]
|
2011-09-20 03:53:01 +00:00
|
|
|
exit 'usage'
|
|
|
|
}
|
|
|
|
shift
|
|
|
|
}
|
|
|
|
|
|
|
|
if (~ $#* 1) {
|
|
|
|
switch ($1) {
|
|
|
|
case bitlbee
|
|
|
|
server=im.bitlbee.org
|
|
|
|
case oftc
|
|
|
|
server=irc.oftc.net
|
|
|
|
case *
|
|
|
|
server=$1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
title
|
|
|
|
userpass=`{auth/userpasswd 'server='^$server^' service=irc user='^$nick >[2]/dev/null}
|
2015-02-12 17:40:20 +00:00
|
|
|
if(~ $#userpass 2) {
|
2011-09-20 03:53:01 +00:00
|
|
|
nick=$userpass(1)
|
|
|
|
pass=$userpass(2)
|
|
|
|
}
|
|
|
|
|
2014-12-28 07:38:21 +00:00
|
|
|
p='/n/ircrc'
|
|
|
|
bind '#|' $p
|
|
|
|
echo connecting to tcp!$server!$port...
|
|
|
|
if(~ $tls 0){
|
|
|
|
aux/trampoline tcp!$server!$port <>$p/data1 >[1=0] &
|
2011-09-20 03:53:01 +00:00
|
|
|
}
|
2014-12-28 07:38:21 +00:00
|
|
|
if not {
|
|
|
|
tlsclient tcp!$server!$port <>$p/data1 >[1=0] &
|
|
|
|
}
|
|
|
|
netdir=$p
|
2017-06-02 15:10:52 +00:00
|
|
|
cat $netdir/data | tr -d '\x2\x8\xd\x1f' | pretty &
|
2014-12-28 07:38:21 +00:00
|
|
|
work
|
|
|
|
|