-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchannel.zsh
executable file
·98 lines (79 loc) · 2.07 KB
/
channel.zsh
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/zsh
: <<EOF
Copyright 2013 Lucas A. Dohring
Licensed under the EUPL, Version 1.1 or – as soon they
will be approved by the European Commission - subsequent
versions of the EUPL (the "Licence");
You may not use this work except in compliance with the
Licence.
You may obtain a copy of the Licence at:
http://ec.europa.eu/idabc/eupl
Unless required by applicable law or agreed to in
writing, software distributed under the Licence is
distributed on an "AS IS" basis,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied.
See the Licence for the specific language governing
permissions and limitations under the Licence.
EOF
function validateChannel() {
readonly channel=$1
if [[ ! "$channel" =~ $CHANRE ]]; then
echo ":$HOST 478 $NICK $channel :No such channel"
exit
fi
}
function JOIN() {
readonly channel=$1
validateChannel $channel
[[ -e "target/$channel" ]] || ./spawnChannel.zsh $NICK $channel &
echo "JOIN $NICK" > "target/$channel"
}
function PART() {
readonly channel=$1
validateChannel $channel
chanExist $channel
echo "PART $NICK" > "target/$channel"
}
function KICK() {
readonly channel=$1
validateChannel $channel
chanExist $channel
echo "KICK $NICK" > "target/$channel"
}
function MODE() {
readonly channel=$1
shift
validateChannel $channel
chanExist $channel
echo "MODE $NICK $@" > "target/$channel"
}
function TOPIC() {
readonly channel=$1
validateChannel $channel
if read topic < "channels/$channel/topic"; then
if [ -n "$topic" ]; then
echo ":$HOST 332 $NICK $CHANNEL :$topic"
else
echo ":$HOST 331 $NICK $CHANNEL :No topic set"
fi
else
echo :$HOST 403 $NICK $CHANNEL :No such channel
fi
}
function NAMES() {
readonly channel=$1
shift
validateChannel $channel
chanExist $channel
echo "NAMES $NICK $@" > "target/$channel"
}
function chanExist () {
readonly CHANNEL=$1
if [[ ! -e "target/$channel" ]]; then
echo :$HOST 403 $NICK $CHANNEL :No such channel
fi
}
readonly COMMAND=$1 NICK=$2
shift 2
$COMMAND $@