Add drunkness meter to annna. - annna - Annna the nice friendly bot. | |
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
--- | |
commit ff1268c8d3e66b7fabf657c6d6e1943fa080b414 | |
parent 6403fdb39588b891fea517ebef3447d067fdc57a | |
Author: Annna Robert-Houdin <[email protected]> | |
Date: Mon, 31 Jul 2023 21:49:15 +0200 | |
Add drunkness meter to annna. | |
Diffstat: | |
M annna-message-common | 12 ++++++++++++ | |
A autocorrect | 38 +++++++++++++++++++++++++++++… | |
A drunk-meter | 30 ++++++++++++++++++++++++++++++ | |
3 files changed, 80 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/annna-message-common b/annna-message-common | |
@@ -506,6 +506,18 @@ case "${text}" in | |
# Emulate https://threats.kaspersky.com/en/threat/IRC-Worm.DOS.Septic/ | |
annna-say -s "${server}" -c "${channel}" "${user}, Your word is my com… | |
;; | |
+"${ircuser}, how drunk is "*) | |
+ { | |
+ drunknick="$(printf "%s\n" "${text}" \ | |
+ | sed 's,.*how drunk is \(.*\),\1,' \ | |
+ | tr -d '?')" | |
+ drunkness="$(drunk-meter "${ircbase}/${server}/${channel}/out"… | |
+ if [ -n "${drunkness}" ]; | |
+ then | |
+ annna-say -s "${server}" -c "${channel}" "${user}, ${d… | |
+ fi | |
+ } & | |
+ ;; | |
"${ircuser}, weather at "*) | |
{ | |
weatherplace="$(printf "%s\n" "${text}" \ | |
diff --git a/autocorrect b/autocorrect | |
@@ -0,0 +1,38 @@ | |
+#!/usr/bin/env python | |
+# coding=utf-8 | |
+ | |
+import os | |
+import sys | |
+import getopt | |
+import io | |
+from autocorrect import Speller | |
+ | |
+def usage(app): | |
+ app = os.path.basename(app) | |
+ print("usage: %s [-h] str..." % (app), file=sys.stderr) | |
+ sys.exit(1) | |
+ | |
+def main(args): | |
+ try: | |
+ opts, largs = getopt.getopt(args[1:], "h") | |
+ except getopt.GetoptError as err: | |
+ print(str(err)) | |
+ usage(args[0]) | |
+ | |
+ for o, a in opts: | |
+ if o == "-h": | |
+ usage(args[0]) | |
+ else: | |
+ assert False, "unhandled option" | |
+ | |
+ if len(largs) < 1: | |
+ usage(args[0]) | |
+ | |
+ spell = Speller() | |
+ print("%s" % (spell(" ".join(largs)))) | |
+ | |
+ return 0 | |
+ | |
+if __name__ == "__main__": | |
+ sys.exit(main(sys.argv)) | |
+ | |
diff --git a/drunk-meter b/drunk-meter | |
@@ -0,0 +1,30 @@ | |
+#!/bin/sh | |
+ | |
+export PATH="$HOME/bin:$PATH" | |
+ | |
+if [ $# -lt 2 ]; | |
+then | |
+ printf "usage: %s chanpath nick\n" "$(basename "$0")" >&2 | |
+ exit 1 | |
+fi | |
+ | |
+chanpath="$1" | |
+nickname="$2" | |
+ | |
+if [ ! -e "${chanpath}" ]; | |
+then | |
+ exit 1 | |
+fi | |
+ | |
+grep " <${nickname}> " "${chanpath}" \ | |
+ | tail -n 10 \ | |
+| { | |
+ while read -r line; | |
+ do | |
+ printf "%s" $(levenshtein-distance "${line}" \ | |
+ "$(autocorrect "${line}")"); | |
+ printf " + "; | |
+ done; | |
+ printf "0\n"; | |
+} | bc | |
+ |