annna-say - annna - Annna the nice friendly bot. | |
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
--- | |
annna-say (1611B) | |
--- | |
1 #!/bin/sh | |
2 # | |
3 # annna-say -s irc.bitreich.org -c '#bitreich-en' Hello World! | |
4 # annna-say -c 'irc.bitreich.org/#bitreich-en' Hello World! | |
5 # | |
6 | |
7 if [ "$(basename "$0")" = "annna-cmd" ]; | |
8 then | |
9 outfile="out" | |
10 else | |
11 outfile="in" | |
12 fi | |
13 | |
14 export PATH="$PATH:/home/annna/bin" | |
15 | |
16 usage() { | |
17 printf "usage: %s [-h] [-i ircbase] [-s server] -c \"[server/]ch… | |
18 "$(basename "$1")" >&2 | |
19 exit 1 | |
20 } | |
21 | |
22 channels="" | |
23 server="irc.bitreich.org" | |
24 ircbase="/home/annna/irc" | |
25 | |
26 while getopts "hb:c:s:" opt; | |
27 do | |
28 case $opt in | |
29 b) | |
30 ircbase="$OPTARG" | |
31 ;; | |
32 c) | |
33 channels="$OPTARG" | |
34 ;; | |
35 s) | |
36 server="$OPTARG" | |
37 ;; | |
38 *) | |
39 usage $0 | |
40 ;; | |
41 esac | |
42 done | |
43 shift $(expr $OPTIND - 1) | |
44 | |
45 [ -z "$channels" ] && usage $0 | |
46 | |
47 # If annna is not alive, do not bother. | |
48 annna-alive || exit 0 | |
49 [ -e "${ircbase}/annna-is-sleeping" ] && exit 0 | |
50 | |
51 for c in $channels; | |
52 do | |
53 case "${c}" in | |
54 *"/"*) | |
55 cserver="$(printf "%s\n" "${c}" | cut -d'/' -f 1)" | |
56 cname="$(printf "%s\n" "${c}" | cut -d'/' -f 2)" | |
57 ;; | |
58 *) | |
59 cserver="${server}" | |
60 cname="${c}" | |
61 ;; | |
62 esac | |
63 | |
64 ircpath="${ircbase}/${cserver}/${cname}" | |
65 if [ -e "$ircpath/in" ]; | |
66 then | |
67 case "${outfile}" in | |
68 "in") | |
69 printf "%s\n" "$@" | fold -w 250 -s > "${ircpath… | |
70 ;; | |
71 "out") | |
72 printf "%s <%s> %s\n" "$(date +%s)" "annna-cmd" … | |
73 > "${ircpath}/${outfile}" | |
74 ;; | |
75 esac | |
76 else | |
77 ircpath="${ircbase}/${cserver}" | |
78 # Might be a user. Do not bother with outfile, he/she is… | |
79 printf "%s\n" "$@" \ | |
80 | fold -w 250 -s \ | |
81 | while read -r line; | |
82 do | |
83 printf "/j %s %s\n" "$c" "$line" > "${ircpath}/i… | |
84 done | |
85 fi | |
86 | |
87 done | |
88 | |
89 exit 0 | |
90 |