Make annna-say support multi-server. - annna - Annna the nice friendly bot. | |
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
--- | |
commit 9e3d9aaf73d82a832e49ab79588e70d2f5c2c1ff | |
parent f2073d06cdc3f2b9f39c74384e9d93e90c5cb968 | |
Author: Annna Robert-Houdin <[email protected]> | |
Date: Fri, 31 Dec 2021 12:39:41 +0100 | |
Make annna-say support multi-server. | |
There are two ways to change the server: | |
-s will permanently set the server. | |
server/#channel syntax for per-channel server setting. | |
Diffstat: | |
M annna-say | 23 ++++++++++++++++------- | |
1 file changed, 16 insertions(+), 7 deletions(-) | |
--- | |
diff --git a/annna-say b/annna-say | |
@@ -1,34 +1,32 @@ | |
#!/bin/sh | |
# | |
-# annna-say -c '#bitreich-en' Hello World! | |
+# annna-say -s irc.bitreich.org -c '#bitreich-en' Hello World! | |
+# annna-say -c 'irc.bitreich.org/#bitreich-en' Hello World! | |
# | |
export PATH="$PATH:/home/annna/bin" | |
usage() { | |
- printf "usage: %s [-h] [-i ircbase] [-s server] -c \"channel0 ... chan… | |
+ printf "usage: %s [-h] [-i ircbase] [-s server] -c \"[server/]channel0… | |
"$(basename "$1")" >&2 | |
exit 1 | |
} | |
channels="" | |
server="irc.bitreich.org" | |
-ircbase="/home/annna/irc/${server}" | |
-ircbaseset=0 | |
+ircbase="/home/annna/irc" | |
while getopts "hb:c:s:" opt; | |
do | |
case $opt in | |
b) | |
ircbase="$OPTARG" | |
- ircbaseset=1 | |
;; | |
c) | |
channels="$OPTARG" | |
;; | |
s) | |
server="$OPTARG" | |
- [ $ircbaseset -eq 0 ] && ircbase="/home/annna/irc/${server}" | |
;; | |
*) | |
usage $0 | |
@@ -44,7 +42,18 @@ annna-alive || exit 0 | |
for c in $channels; | |
do | |
- ircpath="${ircbase}/$c" | |
+ case "${c}" in | |
+ *"/"*) | |
+ cserver="$(printf "%s\n" "${c}" | cut -d'/' -f 1)" | |
+ cname="$(printf "%s\n" "${c}" | cut -d'/' -f 2)" | |
+ ;; | |
+ *) | |
+ cserver="${server}" | |
+ cname="${c}" | |
+ ;; | |
+ esac | |
+ | |
+ ircpath="${ircbase}/${cserver}/${cname}" | |
if [ -e "$ircpath/in" ]; | |
then |