-
Notifications
You must be signed in to change notification settings - Fork 1
/
irc.sh
executable file
·79 lines (70 loc) · 1.28 KB
/
irc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
usage()
{
cat << EOF
usage: $0 options
Reads STDIN and outputs to specified channel [iplayer]
OPTIONS:
-h Show this message
-c Channel, defaults to \#iplayer
-u Spcific user in channel
-m Message to parse, use "%s" to place piped content
-n Dry Run, just echo commands
EOF
exit;
}
USER=false
CHANNEL=iplayer
MESSAGE=false
DATA=false
RC=~/.irssi/rc
TESTMODE=false
while getopts “:hc:u:m:n” OPTION
do
case $OPTION in
h)
usage
exit 1
;;
c)
CHANNEL=$OPTARG
;;
u)
USER=$OPTARG
;;
m)
MESSAGE=$OPTARG
;;
n)
TESTMODE=true
;;
?)
usage
exit
;;
esac
done
read DATA;
function send_cmd {
if [ $TESTMODE == true ]; then
TARGET=/tmp/irctest
else
TARGET=$RC
fi
echo $@ > $TARGET
if [ $TESTMODE == true ]; then
cat /tmp/irctest && rm /tmp/irctest
fi
}
if [ "$MESSAGE" != false ]; then
MSG=$(printf "$MESSAGE" $DATA);
else
MSG="$DATA"
fi
if [ $USER != false ]; then
send_cmd "/query $USER";
send_cmd "/msg $USER $MSG";
else
send_cmd "/join #$CHANNEL";
send_cmd "/msg #$CHANNEL $MSG";
fi