commit fabd57906b8a2047bc02648e538ec5654e31f363
parent 5ffc77924e4a00454e438351c01246be7cc5d69e
Author: mys <>
Date: Sun, 28 Feb 2021 01:18:07 +0100
Add morse by hhvn
Diffstat:
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
@@ -10,6 +10,8 @@ Get translation shell:
$ git clone https://github.com/soimort/translate-shell.git
```
+For morse encoding/decoding, install the bsd-games package.
+
Usage
-----
diff --git a/bot b/bot
@@ -5,9 +5,11 @@ source botenv
echo "NICK $nick" > $input
echo "USER $nick * * :$nick" >> $input
-echo $connect_command
-tail -f $input | $connect_command | while read res
+while true
do
- echo "$(date "+[%y:%m:%d %T]")$res" >> $log
- ./botreply "$res" >> $input
+ tail -f $input | $connect_command | while read res
+ do
+ echo "$(date "+[%y:%m:%d %T]")$res" >> $log
+ ./botreply "$(echo "$res" | tr -d '\r')" >> $input
+ done
done
diff --git a/botreply b/botreply
@@ -18,6 +18,16 @@ rot(){
done
}
+_morse(){
+ orig="$1"
+ morseonly=$(echo "$orig" | tr -dc '. \t\n-')
+ [ "$orig" = "$morseonly" ] && {
+ echo "$1" | morse -sd
+ } || {
+ echo "$1" | morse -s | tr '\n' ' ' | tr -s ' '
+ }
+}
+
case "$1" in
*"PING "*)
sed 's/.*\(:.*\)/PONG \1/' <<< $1
@@ -30,6 +40,12 @@ case "$1" in
echo "JOIN $channel"
echo "MODE $nick +B"
;;
+ *"PRIVMSG "*":$nick: :morse"*|*"PRIVMSG "*":$nick, :morse"*)
+ ret=$(_morse "$(echo "$1" | sed 's/.*:morse //')")
+ name=${1%%!*}
+ name=${name#:}
+ echo "$1" | awk -v "name=$name" -v "ret=$ret" '{print "PRIVMSG "$3" :"name": "ret}'
+ ;;
*"PRIVMSG "*":$nick: :rot"*|*"PRIVMSG "*":$nick, :rot"*)
num=$(echo "$1" | sed "s/.*:$nick[,:] :rot\([0-9]*\).*/\1/")
exp=$(echo "$1" | sed "s/.*:$nick[,:] :rot[0-9]* //")