blob: 4241126c9893a628185d0e039e860d430d5b8f19 (
plain)
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
|
#!/bin/bash
set -e
if [ $# -eq 2 ]; then
user="$(whoami)_$(hostname)"
channel="$1"
message="$2"
elif [ $# -eq 3 ]; then
user="$1"
channel="$2"
message="$3"
else
echo 'Need 2 or 3 arguments: (user) channel message.'
exit 1
fi
pid=''
clean_up() {
rm -rf --one-file-system "${tmp_dir}"
if [ -n "${pid}" ]; then
kill ${pid}
fi
}
tmp_dir="$(mktemp -d)"
trap clean_up EXIT
mkfifo "${tmp_dir}/input"
mkfifo "${tmp_dir}/output"
ncat irc.home.eckner.net 6667 < \
"${tmp_dir}/input" > \
"${tmp_dir}/output" &
pid=$!
(
printf '%s\n' 'NICK '"${user}" 'USER '"${user}"' 8 * : '"${user}"
while read -r s; do
echo "$s" >&2
if [[ "${s}" = *"MODES"* ]]; then
printf '%s\n' 'JOIN '"${channel}" 'PRIVMSG '"${channel}"' :'"${message}" 'QUIT'
fi
done \
< "${tmp_dir}/output"
) \
> "${tmp_dir}/input"
unset pid
|