Introduction
Introduction Statistics Contact Development Disclaimer Help
Add textsynth support to annna. - annna - Annna the nice friendly bot.
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6…
Log
Files
Refs
Tags
README
---
commit d974ca1bf2ea840a5f1c96dd7fe8768ec1c7626c
parent 465c44b267057ef7894954d7a4f0a75eb210fd05
Author: Annna Robert-Houdin <[email protected]>
Date: Wed, 6 May 2020 16:18:14 +0200
Add textsynth support to annna.
http://textsynth.org/
Diffstat:
M annna-start-services | 21 +++++++++++++++++++++
A textsynth-complete | 58 ++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+), 0 deletions(-)
---
diff --git a/annna-start-services b/annna-start-services
@@ -235,6 +235,27 @@ then
fi
annna-say -c '#bitreich-en' "${purl}"
;;
+ "${botname}, textsynth is "*)
+ word="$(printf "%s\n" "${text}" | cut -c 17- | sed 's,…
+ case "$word" in
+ *\?)
+ word="$(printf "%s\n" "${word}" | cut -c -"$((…
+ ;;
+ esac
+
+ # Do in background, because read is very slow.
+ {
+ dresult="$(textsynth-complete "${word}")"
+ if [ -n "${dresult}" ];
+ then
+ purl="$(printf "%s" "${dresult}" | /br…
+ else
+ purl="Textsynth did not answer."
+ fi
+ annna-say -c '#bitreich-en' "textsynth result:…
+ } &
+
+ ;;
"${botname}, are "*)
case "${text}" in
*" in love?")
diff --git a/textsynth-complete b/textsynth-complete
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3.6
+# coding=utf-8
+#
+# Copy me if you can.
+# by 20h
+#
+
+import os
+import sys
+import getopt
+import websocket
+
+def usage(app):
+ app = os.path.basename(app)
+ print("usage: %s [-h] [-b base] text to complete..." % (app),
+ file=sys.stderr)
+ sys.exit(1)
+
+def main(args):
+ try:
+ opts, largs = getopt.getopt(args[1:], "hb:")
+ except getopt.GetoptError as err:
+ print(str(err))
+ usage(args[0])
+
+ baseuri = "ws://163.172.76.10:8080"
+ for o, a in opts:
+ if o == "-h":
+ usage(args[0])
+ else:
+ assert False, "unhandled option"
+
+ if len(largs) < 1:
+ usage(args[0])
+ txtstr = " ".join(largs)
+ reqstr = "g,%s" % (txtstr)
+
+ try:
+ ws = websocket.WebSocket()
+ ws.connect(baseuri)
+ ws.send(reqstr)
+
+ rstr = ""
+ while 1:
+ r = ws.recv()
+ if len(r) == 0:
+ break
+ rstr += r
+ except:
+ return 1
+
+ print("%s\n" % (rstr))
+
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))
+
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.