Add dalle emoji support to annna. - annna - Annna the nice friendly bot. HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/ DIR Log DIR Files DIR Refs DIR Tags DIR README --- DIR commit dc0e577401b734bc1513078f7af1d0f1b741dc46 DIR parent 3b6c6e5e060a71796cb0decdf0bdcbc6e2b37511 HTML Author: Annna Robert-Houdin <annna@bitreich.org> Date: Fri, 1 Jul 2022 19:56:28 +0200 Add dalle emoji support to annna. Diffstat: M annna-message-common | 31 ++++++++++++++++++++----------- A dalle-gen-emoji | 66 +++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 11 deletions(-) --- DIR diff --git a/annna-message-common b/annna-message-common @@ -992,6 +992,15 @@ then fi case "${text}" in +::*::) + { + emojiuri="$(dalle-gen-emoji "${text}")" + if [ -n "${emojiuri}" ]; + then + annna-say -s "${server}" -c "${channel}" "${emojiuri}" + fi + } & + ;; *\#nospoil*) ;; *rfc[0-9]*) @@ -1040,6 +1049,17 @@ else done fi +# Always keep the karma / shame last! +case "${text}" in +*"-shaming"*) + shametext="$(printf "%s\n" "${text}" | sed 's,.* \(.*-shaming\).*,\1,')" + shame "${shametext}" + ;; +*++|*--) + karma "${text}" + ;; +esac + # Membership Level. ismember=0 for member in $brmembers; @@ -1064,14 +1084,3 @@ case "${text}" in ;; esac -# Always keep the karma / shame last! -case "${text}" in -*"-shaming"*) - shametext="$(printf "%s\n" "${text}" | sed 's,.* \(.*-shaming\).*,\1,')" - shame "${shametext}" - ;; -*++|*--) - karma "${text}" - ;; -esac - DIR diff --git a/dalle-gen-emoji b/dalle-gen-emoji @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# coding=utf-8 +# +# Kiss me when you can. +# by annna +# + +import os +import os.path +import sys +import getopt +import requests +import base64 + +def usage(app): + app = os.path.basename(app) + print("usage: %s [-h] [::]some-emoji[:key=value...][::]" % (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]) + + emoji = " ".join(largs) + emoji = emoji.strip("::") + emoji = emoji.replace(":", " ").replace(",", " ").replace("=", " ").\ + replace(".", " ").replace("/", " ") + + emojifile = "%s.jpg" % (emoji.replace(" ", "-")) + + filebase = "/br/ai/dalle/dalle-results/" + emojiuribase = "gopher://bitreich.org/9/memecache/dalle/" + imguri = "http://127.0.0.1:32553/dalle" + jsonreq = {"text": emoji, "num_images": 1} + + filepath = "%s%s" % (filebase, emojifile) + if not os.path.exists(filepath): + try: + answer = requests.post(imguri, json=jsonreq) + except: + return 1 + + fd = open(filepath, "wb") + fd.write(base64.b64decode(answer.json()[0])) + fd.close() + + print("%s%s" % (emojiuribase, emojifile)) + + return 0 + +if __name__ == "__main__": + sys.exit(main(sys.argv)) +