Totally rework annna. - annna - Annna the nice friendly bot. | |
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
--- | |
commit b2265362d675a8e447860c0b77a9a4c1d3009992 | |
parent a63f21cd1ad027bdff057acf9ee6d44273f778fa | |
Author: Annna Robert-Houdin <[email protected]> | |
Date: Sat, 10 Feb 2018 11:38:10 +0000 | |
Totally rework annna. | |
* Cleanup annna-say usage. | |
* Make the start routine event-based. | |
* Rework services handling using entr. | |
Diffstat: | |
D annna-checker | 21 --------------------- | |
D annna-checker-dbg | 25 ------------------------- | |
M annna-say | 6 +++++- | |
D annna-shutdown | 10 ---------- | |
M annna-start | 56 +----------------------------… | |
A annna-start-checker | 21 +++++++++++++++++++++ | |
A annna-start-checker-dbg | 25 +++++++++++++++++++++++++ | |
A annna-start-main | 86 ++++++++++++++++++++++++++++++ | |
M annna-start-services | 103 ++++++++++++++++-------------… | |
M annna-stop | 7 ++++++- | |
M annna-stop-services | 2 +- | |
C annna-stop -> annna-stop-socat | 0 | |
12 files changed, 197 insertions(+), 165 deletions(-) | |
--- | |
diff --git a/annna-checker b/annna-checker | |
@@ -1,21 +0,0 @@ | |
-#!/bin/sh | |
-# | |
-# Watch for annna, she's worth it. | |
-# | |
- | |
-export PATH="$PATH:/home/annna/bin" | |
- | |
-while /bin/true; | |
-do | |
- # Is annna still in her world? | |
- pid="$(pgrep -U annna -x socat)" | |
- | |
- if [ -z "$pid" ]; | |
- then | |
- annna-stop-services >/dev/null 2>&1 | |
- annna-start >/dev/null 2>&1 | |
- fi | |
- | |
- sleep 5 | |
-done | |
- | |
diff --git a/annna-checker-dbg b/annna-checker-dbg | |
@@ -1,25 +0,0 @@ | |
-#!/bin/sh | |
-# | |
-# Watch for annna, she's worth it. | |
-# | |
- | |
-export PATH="$PATH:/home/annna/bin" | |
- | |
-logfile="/home/annna/output.log" | |
- | |
-while /bin/true; | |
-do | |
- # Is annna still in her world? | |
- pid="$(pgrep -U annna -x socat)" | |
- | |
- if [ -z "$pid" ]; | |
- then | |
- annna-stop-services >/dev/null 2>&1 | |
- annna-start 2>&1 \ | |
- | grep -v -e ' PRIVMSG ' -e ' JOIN ' -e ' PART ' \ | |
- >> "$logfile" | |
- fi | |
- | |
- sleep 5 | |
-done | |
- | |
diff --git a/annna-say b/annna-say | |
@@ -42,7 +42,11 @@ do | |
if [ -e "$ircpath/in" ]; | |
then | |
printf "%s\n" "$@" > "${ircpath}/in" | |
- fi | |
+ else | |
+ # Might be a user. | |
+ printf "/j %s %s\n" "$channel" "$@" > "${iibase}/in" | |
+ fi | |
+ | |
done | |
exit 0 | |
diff --git a/annna-shutdown b/annna-shutdown | |
@@ -1,10 +0,0 @@ | |
-#!/bin/sh | |
-# | |
-# Dare you to execute this script! You are cruel! | |
-# | |
- | |
-export PATH="$PATH:/home/annna/bin" | |
- | |
-annna-stop | |
-annna-stop-services | |
- | |
diff --git a/annna-start b/annna-start | |
@@ -2,59 +2,5 @@ | |
export PATH="$PATH:/home/annna/bin" | |
-# #bitreich is a forward to #bitreich-en. Annna does not need to join it. | |
-#channels="#bitreich #bitreich-con #bitreich-radio | |
-# #bitreich-scm #bitreich-en #bitreich-de" | |
-channels="#bitreich-con #bitreich-radio | |
- #bitreich-scm #bitreich-en #bitreich-de | |
- #bitreich-fr #bitreich-cooking" | |
- | |
-rm -rf $HOME/irc | |
-mkdir -p $HOME/irc | |
-cd $HOME/irc | |
-rm -f $HOME/freenode.sock | |
- | |
-# Connect | |
-socat openssl:chat.freenode.net:6697,keepalive,keepcnt=5,keepidle=1,keepintvl=… | |
- unix-l:$HOME/freenode.sock & | |
-while [ ! -e $HOME/freenode.sock ]; | |
-do | |
- sleep 0.5 | |
-done | |
- | |
-ii -s chat.freenode.net -u $HOME/freenode.sock -n annna -f "Annna Robert-Houdi… | |
- | |
-sleep 5 | |
- | |
-# Nickserv Auth | |
-ircuser="$(grep user $HOME/irc-credentials.txt | cut -d' ' -f 2)" | |
-ircpass="$(grep pass $HOME/irc-credentials.txt | cut -d' ' -f 2)" | |
-printf "/privmsg nickserv :identify %s %s\n" "${ircuser}" "${ircpass}" \ | |
- > chat.freenode.net/in | |
-sleep 0.5 | |
- | |
-# Join Channels | |
-for chan in ${channels}; | |
-do | |
- printf "/j %s\n" "${chan}" > chat.freenode.net/in | |
- sleep 0.5 | |
-done | |
- | |
-# Give permissions to certain channels. | |
-chmod o+rx $HOME/irc | |
-chmod o+rx $HOME/irc/chat.freenode.net | |
-## EN Channel | |
-chmod o+rx "$HOME/irc/chat.freenode.net/#bitreich-en" | |
-chmod o+w "$HOME/irc/chat.freenode.net/#bitreich-en/in" | |
-## SCM | |
-chmod o+rx "$HOME/irc/chat.freenode.net/#bitreich-scm" | |
-chmod o+w "$HOME/irc/chat.freenode.net/#bitreich-scm/in" | |
-## Radio | |
-chmod o+rx "$HOME/irc/chat.freenode.net/#bitreich-radio" | |
-chmod o+w "$HOME/irc/chat.freenode.net/#bitreich-radio/in" | |
- | |
-# Allow commands. | |
-sleep 6 | |
- | |
-annna-start-services | |
+annna-start-checker | |
diff --git a/annna-start-checker b/annna-start-checker | |
@@ -0,0 +1,21 @@ | |
+#!/bin/sh | |
+# | |
+# Watch for annna, she's worth it. | |
+# | |
+ | |
+export PATH="$PATH:/home/annna/bin" | |
+ | |
+while /bin/true; | |
+do | |
+ # Is annna still in her world? | |
+ pid="$(pgrep -U annna -x socat)" | |
+ | |
+ if [ -z "$pid" ]; | |
+ then | |
+ annna-stop-services >/dev/null 2>&1 | |
+ annna-start-main >/dev/null 2>&1 | |
+ fi | |
+ | |
+ sleep 5 | |
+done | |
+ | |
diff --git a/annna-start-checker-dbg b/annna-start-checker-dbg | |
@@ -0,0 +1,25 @@ | |
+#!/bin/sh | |
+# | |
+# Watch for annna, she's worth it. | |
+# | |
+ | |
+export PATH="$PATH:/home/annna/bin" | |
+ | |
+logfile="/home/annna/output.log" | |
+ | |
+while /bin/true; | |
+do | |
+ # Is annna still in her world? | |
+ pid="$(pgrep -U annna -x socat)" | |
+ | |
+ if [ -z "$pid" ]; | |
+ then | |
+ annna-stop-services >/dev/null 2>&1 | |
+ annna-start-main 2>&1 \ | |
+ | grep -v -e ' PRIVMSG ' -e ' JOIN ' -e ' PART ' \ | |
+ >> "$logfile" | |
+ fi | |
+ | |
+ sleep 5 | |
+done | |
+ | |
diff --git a/annna-start-main b/annna-start-main | |
@@ -0,0 +1,86 @@ | |
+#!/bin/sh | |
+ | |
+set -x | |
+ | |
+export PATH="$PATH:/home/annna/bin" | |
+ | |
+# #bitreich is a forward to #bitreich-en. Annna does not need to join it. | |
+#channels="#bitreich #bitreich-con #bitreich-radio | |
+# #bitreich-scm #bitreich-en #bitreich-de" | |
+channels="#bitreich-con #bitreich-radio | |
+ #bitreich-scm #bitreich-en #bitreich-de | |
+ #bitreich-fr #bitreich-cooking" | |
+ | |
+rm -rf $HOME/irc | |
+mkdir -p $HOME/irc | |
+cd $HOME/irc | |
+rm -f $HOME/freenode.sock | |
+ | |
+# Connect | |
+socat openssl:chat.freenode.net:6697,keepalive,keepcnt=5,keepidle=1,keepintvl=… | |
+ unix-l:$HOME/freenode.sock & | |
+while [ ! -e $HOME/freenode.sock ]; | |
+do | |
+ sleep 0.5 | |
+done | |
+ | |
+# Connection | |
+ii -s chat.freenode.net -u $HOME/freenode.sock -n annna \ | |
+ -f "Annna Robert-Houdin" & | |
+ | |
+## Waiting for the socket to be available. | |
+while [ ! -e $HOME/irc/chat.freenode.net/out ]; | |
+do | |
+ sleep 0.5 | |
+done | |
+ | |
+## Waiting for the motd to have ended so we can send something. | |
+while [ -z "$(grep "End of /MOTD command" $HOME/irc/chat.freenode.net/out)" ]; | |
+do | |
+ sleep 0.5 | |
+done | |
+ | |
+sleep 2 | |
+ | |
+# Nickserv | |
+ircuser="$(grep user $HOME/irc-credentials.txt | cut -d' ' -f 2)" | |
+ircpass="$(grep pass $HOME/irc-credentials.txt | cut -d' ' -f 2)" | |
+printf "/privmsg nickserv :identify %s %s\n" "${ircuser}" "${ircpass}" \ | |
+ > chat.freenode.net/in | |
+ | |
+## Check that nickserv is there. | |
+while [ ! -e $HOME/irc/chat.freenode.net/nickserv/out ]; | |
+do | |
+ sleep 0.5 | |
+done | |
+ | |
+## Waiting for us to be authenticated. | |
+while [ -z "$(grep "You are now identified for" \ | |
+ $HOME/irc/chat.freenode.net/nickserv/out)" ]; | |
+do | |
+ sleep 0.5 | |
+done | |
+ | |
+ | |
+# Channels | |
+for chan in ${channels}; | |
+do | |
+ printf "/j %s\n" "${chan}" > chat.freenode.net/in | |
+ | |
+ ## Make sure the pipes are there. | |
+ while [ ! -e "$HOME/irc/chat.freenode.net/${chan}/out" ]; | |
+ do | |
+ sleep 0.5 | |
+ done | |
+ | |
+ ## Make sure we are in the channel, for the services. | |
+ while [ -z "$(grep "${chan} End of /NAMES list" \ | |
+ $HOME/irc/chat.freenode.net/out)" ]; | |
+ do | |
+ sleep 0.5 | |
+ done | |
+done | |
+ | |
+# Services | |
+annna-start-services | |
+ | |
diff --git a/annna-start-services b/annna-start-services | |
@@ -4,63 +4,53 @@ | |
# If this gets too unmaintainable, consider adding some directory structure. | |
# | |
+# Bitreich members who are allowed to run certain commands. | |
brmembers="__20h__ Evil_Bob chripo posativ quinq stateless solene josuah" | |
botname="annna" | |
iibase="/home/annna/irc/chat.freenode.net" | |
-function annna_say { | |
- channel="$1" | |
- shift 1 | |
- | |
- [ $# -lt 1 ] && exit 1 | |
- | |
- if [ -e "${iibase}/${channel}/in" ]; | |
- then | |
- printf "%s\n" "$@" > "${iibase}/${channel}/in" | |
- # No spamming allowed. | |
- sleep 0.5 | |
- else | |
- # Might be a user. | |
- printf "/j %s %s\n" "$channel" "$@" > "${iibase}/in" | |
- fi | |
-} | |
- | |
-echo '12345 <unknown> a' > ${iibase}/#bitreich-radio/out | |
-sleep 1 | |
+ | |
+# Permissions | |
+chmod o+rx $HOME/irc | |
+chmod o+rx $HOME/irc/chat.freenode.net | |
+## EN Channel (this script) | |
+chmod o+rx "$HOME/irc/chat.freenode.net/#bitreich-en" | |
+chmod o+w "$HOME/irc/chat.freenode.net/#bitreich-en/in" | |
+## SCM (/scm/post-receive) | |
+chmod o+rx "$HOME/irc/chat.freenode.net/#bitreich-scm" | |
+chmod o+w "$HOME/irc/chat.freenode.net/#bitreich-scm/in" | |
+## Radio (/br/radio/playlist.sh + this script) | |
+chmod o+rx "$HOME/irc/chat.freenode.net/#bitreich-radio" | |
+chmod o+w "$HOME/irc/chat.freenode.net/#bitreich-radio/in" | |
+ | |
# bitreich-radio | |
{ | |
- #tail -f -n 1 "${iibase}/#bitreich-radio/out" \ | |
ls "${iibase}/#bitreich-radio/out" | entr tail -n 1 "${iibase}/#bitrei… | |
| sed -u 's,[0-9]* <\([^ >]*\)> \(.*\)$,\1\n\2,' \ | |
| { | |
while read user; | |
do | |
read text | |
- echo "$user" | |
- echo "$text" | |
- | |
[ "$user" = "${botname}" ] && continue | |
if [ "${text}" = "${botname}, next please" ]; | |
then | |
/br/bin/bitreich-radio-playlist-next | |
- annna_say "#bitreich-radio" "You are very kind ${user}… | |
+ annna-say "#bitreich-radio" "You are very kind ${user}… | |
continue; | |
fi | |
if [ "${text}" = "${botname}, please help" ]; | |
then | |
- annna_say "${user}" "»next please« gets the playlist… | |
- annna_say "${user}" "»please help« gives you this he… | |
+ annna-say "${user}" "»next please« gets the playlist… | |
+ annna-say "${user}" "»please help« gives you this he… | |
continue; | |
fi | |
done | |
} | |
} & | |
-echo '12345 <unknown> a' > ${iibase}/#bitreich-en/out | |
-sleep 1 | |
# bitreich-en | |
{ | |
ls "${iibase}/#bitreich-en/out" | entr tail -n 1 "${iibase}/#bitreich-… | |
@@ -80,31 +70,31 @@ sleep 1 | |
if [ "${text}" = "${botname}, can you show me the uptime pleas… | |
then | |
- annna_say "#bitreich-en" "$(hostname) uptime: $(uptime… | |
+ annna-say "#bitreich-en" "$(hostname) uptime: $(uptime… | |
continue; | |
fi | |
if [ "${text}" = "${botname}, please give me the count of onli… | |
then | |
- annna_say "#bitreich-en" "$(hostname): $(who -q | tail… | |
+ annna-say "#bitreich-en" "$(hostname): $(who -q | tail… | |
continue; | |
fi | |
if [ "${text}" = "${botname}, please roll a dice for me." ]; | |
then | |
- annna_say "#bitreich-en" "$((($RANDOM % 6) + 1))" | |
+ annna-say "#bitreich-en" "$((($RANDOM % 6) + 1))" | |
continue; | |
fi | |
if [ "${text}" = "${botname}, please tell me your favourite fl… | |
then | |
- annna_say "#bitreich-en" "My favourite flower is the b… | |
+ annna-say "#bitreich-en" "My favourite flower is the b… | |
continue; | |
fi | |
if [ "${text}" = "${botname}, please tell me your favourite co… | |
then | |
- annna_say "#bitreich-en" "My favourite color is yellow… | |
+ annna-say "#bitreich-en" "My favourite color is yellow… | |
continue; | |
fi | |
@@ -112,9 +102,9 @@ sleep 1 | |
then | |
if [ $(($RANDOM % 2)) -gt 0 ]; | |
then | |
- annna_say "#bitreich-en" "I am not that kind o… | |
+ annna-say "#bitreich-en" "I am not that kind o… | |
else | |
- annna_say "#bitreich-en" "Thank you! Let us da… | |
+ annna-say "#bitreich-en" "Thank you! Let us da… | |
fi | |
continue; | |
@@ -122,42 +112,53 @@ sleep 1 | |
if [ "${text}" = "${botname}, please tell me who is your favou… | |
then | |
- annna_say "#bitreich-en" "My favourite pleasure man is… | |
+ annna-say "#bitreich-en" "My favourite pleasure man is… | |
continue; | |
fi | |
if [ "${text}" = "${botname}, sudo make me a sandwich" ]; | |
then | |
- annna_say "#bitreich-en" "Humans are no objects." | |
+ annna-say "#bitreich-en" "Humans are no objects." | |
continue; | |
fi | |
if [ "${text}" = "${botname}, sudo please make me a sandwich" … | |
then | |
- annna_say "#bitreich-en" "Here is your sandwich." | |
+ annna-say "#bitreich-en" "Here is your sandwich." | |
continue; | |
fi | |
if [ "${text}" = "${botname}, please update the phlog index." … | |
then | |
- /home/annna/bin/phlog-index.sh > /dev/null 2>&1 | |
- annna_say "#bitreich-en" "Thank you for your kind requ… | |
+ phlog-index.sh > /dev/null 2>&1 | |
+ annna-say "#bitreich-en" "Thank you for your kind requ… | |
continue; | |
fi | |
if [ "${text}" = "${botname}, please help" ]; | |
then | |
- annna_say "${user}" "»can you show me the uptime plea… | |
- annna_say "${user}" "»please give me the count of onl… | |
- annna_say "${user}" "»please tell me your favourite f… | |
- annna_say "${user}" "»please tell me your favourite c… | |
- annna_say "${user}" "»please dance with me.«, ${user… | |
- annna_say "${user}" "»please update the phlog index.�… | |
- annna_say "${user}" "»sudo make me a sandwich«, ${us… | |
- annna_say "${user}" "»sudo please make me a sandwich�… | |
- annna_say "${user}" "»please tell me who is your favo… | |
- annna_say "${user}" "»please roll a dice for me.«, $… | |
- annna_say "${user}" "»please help« gives you this he… | |
+ # TODO: Add multiple line support to annna-say(1) with… | |
+ annna-say "${user}" "»can you show me the uptime plea… | |
+ sleep 0.5 | |
+ annna-say "${user}" "»please give me the count of onl… | |
+ sleep 0.5 | |
+ annna-say "${user}" "»please tell me your favourite f… | |
+ sleep 0.5 | |
+ annna-say "${user}" "»please tell me your favourite c… | |
+ sleep 0.5 | |
+ annna-say "${user}" "»please dance with me.«, ${user… | |
+ sleep 0.5 | |
+ annna-say "${user}" "»please update the phlog index.�… | |
+ sleep 0.5 | |
+ annna-say "${user}" "»sudo make me a sandwich«, ${us… | |
+ sleep 0.5 | |
+ annna-say "${user}" "»sudo please make me a sandwich�… | |
+ sleep 0.5 | |
+ annna-say "${user}" "»please tell me who is your favo… | |
+ sleep 0.5 | |
+ annna-say "${user}" "»please roll a dice for me.«, $… | |
+ sleep 0.5 | |
+ annna-say "${user}" "»please help« gives you this he… | |
continue; | |
fi | |
done | |
diff --git a/annna-stop b/annna-stop | |
@@ -1,6 +1,11 @@ | |
#!/bin/sh | |
+# | |
+# Dare you to execute this script! You are cruel! | |
+# | |
export PATH="$PATH:/home/annna/bin" | |
-pkill -KILL -U annna -x socat | |
+annna-stop-checker | |
+annna-stop-services | |
+annna-stop-socat | |
diff --git a/annna-stop-services b/annna-stop-services | |
@@ -1,4 +1,4 @@ | |
#!/bin/sh | |
-pkill -f "tail -f -n 1 /home/annna/irc.*" | |
+pkill -f "entr tail -n 1 /home/annna/irc.*" | |
diff --git a/annna-stop b/annna-stop-socat |