-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathteleirc.sh
executable file
·84 lines (68 loc) · 1.27 KB
/
teleirc.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
80
81
82
83
84
#!/bin/bash
BOTNAME="teleirc"
CHANNEL="#laupheim"
# open connection to afternet
exec 3<>/dev/tcp/irc.afternet.org/6667
exec 4<>/dev/tcp/localhost/5544
function send_irc {
echo "SEND: $1"
echo $1 >&3
}
function send_tele {
echo "TO_TELE: $1"
echo $1 >&4
}
while read -r line <&3
do
echo "GOT: $line"
if [[ $line =~ ^PING\ : ]]
then
send_irc "PONG :${line:6}"
fi
rest=$line
from=${rest%% *}
rest=${rest#* }
cmd=${rest%% *}
rest=${rest#* }
target=${rest%% *}
rest=${rest#* }
echo "from: $from cmd: $cmd target: $target rest: $rest"
if [[ "$target" == "$BOTNAME" ]]
then
if [[ "$cmd" == "005" ]]
then
send_irc "JOIN $CHANNEL"
fi
elif [[ "$cmd" == "PRIVMSG" && "$target" == "$CHANNEL" ]]
then
text=${rest#:}
echo "--> $text"
if [[ "$text" =~ ^$BOTNAME:\ *quit ]]
then
send_irc "QUIT"
send_tele "dialog_list"
break
elif [[ "$text" =~ ^$BOTNAME: ]]
then
to_tele="${from%%!*}: ${text#$BOTNAME:}"
send_tele "msg @laupheim $to_tele"
fi
fi
done &
IRC_PID=$!
while read -r tele_line <&4
do
echo "GOT TELE: $tele_line"
done &
TELE_PID=$!
send_irc "USER $BOTNAME 0 * :$BOTNAME"
send_irc "NICK $BOTNAME"
wait $IRC_PID
kill $TELE_PID
# close connection to afternet
exec 3<&-
exec 3>&-
# close connection to telegram
exec 4<&-
exec 4>&-
exit