From 98de289ea1407f1e1f45cd81ae009de11be98d87 Mon Sep 17 00:00:00 2001 From: Darks Date: Wed, 11 Nov 2020 13:26:45 +0100 Subject: [PATCH] glados: added glados socket and example wrapper --- app/utils/glados.py | 39 +++++++++++++++++++++++++++++++++++++++ config.py | 3 +++ 2 files changed, 42 insertions(+) create mode 100644 app/utils/glados.py diff --git a/app/utils/glados.py b/app/utils/glados.py new file mode 100644 index 0000000..978fdf0 --- /dev/null +++ b/app/utils/glados.py @@ -0,0 +1,39 @@ +import socket +from config import V5Config + +BOLD = "\x02" +ITALIC = "\x1d" +UNDERLINE = "\x1f" +STRIKETHROUGH = "\x1e" + +NO_COLOR = "\x03" +WHITE = "\x0300" +BLACK = "\x0301" +BLUE = "\x0302" +GREEN = "\x0303" +RED = "\x0304" +BROWN = "\x0305" +MAGENTA = "\x0306" +ORANGE = "\x0307" +YELLOW = "\x0308" +LIGHT_GREEN = "\x0309" +CYAN = "\x0310" +LIGHT_CYAN = "\x0311" +LIGHT_BLUE = "\x0312" +PINK = "\x0313" +GREY = "\x0314" +LIGHT_GREY = "\x0315" + + +def say(msg, channels = ["#general"]): + """ GLaDOS will say on + Channel #* means all channels where GLaDOS listens to + Raw messages follow this partern: + #channel1 #channel2: message""" + sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) + msg = ":".join([" ".join(channels), msg]) + sock.sendto(msg.encode(),(V5Config.GLADOS_HOST, V5Config.GLADOS_PORT)) + +def new_topic(topic): + """ Example wrapper for glados.say """ + say(f"Le topic {BOLD}{topic.title}{BOLD} a été créé") diff --git a/config.py b/config.py index be5e06f..107ae7f 100644 --- a/config.py +++ b/config.py @@ -41,6 +41,9 @@ class DefaultConfig(object): ENABLE_EMAIL_CONFIRMATION = True # Send emails SEND_MAILS = True + # GLaDOS configuration + GLADOS_HOST = "127.0.0.1" + GLADOS_PORT = 5555 class V5Config(LocalConfig, DefaultConfig): # Values put here cannot be overidden with local_config