diff --git a/.gitignore b/.gitignore index 190b7c5..94b4eb5 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,4 @@ db/citadel-seed/* services/installed.json services/installed.yml +events/karen diff --git a/karen-client.js b/karen-client.js new file mode 100755 index 0000000..c691213 --- /dev/null +++ b/karen-client.js @@ -0,0 +1,51 @@ +#!/usr/bin/env node + +const net = require("net"); + +let connection; + +function initConnection() { + return new Promise((resolve) => { + connection = net.createConnection("events/karen", () => resolve()); + }); +} + +async function runCommand(command) { + await initConnection(); + return new Promise((resolve, reject) => { + const errorListener = (error) => { + reject(error); + }; + connection.on("error", errorListener); + + connection.write(command, () => { + connection.off("error", errorListener); + resolve(); + }); + }); +} + +const readline = require("readline/promises"); +const { stdin, stdout } = require("process"); + +async function main() { + const rl = readline.createInterface({ input: stdin, output: stdout }); + while (true) { + const userInput = await rl.question("> "); + if (userInput === "exit" || userInput === "quit") { + rl.close(); + break; + } else if (userInput === "help") { + console.log(`Available commands: +trigger: Execute a certain trigger + +help: Print this message +quit: Exit this client +exit: Same as quit`); + } + await runCommand(userInput); + console.log("Command executed"); + } +} + +main(); diff --git a/karen-v2 b/karen-v2 new file mode 100755 index 0000000..72b41d7 --- /dev/null +++ b/karen-v2 @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import socket +import os +import time +from collections import deque + +rootDir = os.path.dirname(os.path.abspath(__file__)) +os.chdir(rootDir) + +if os.path.exists("events/karen"): + os.remove("events/karen") + +server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) +server.bind("events/karen") + +while True: + server.listen(1) + conn, addr = server.accept() + datagram = conn.recv(1024) + if datagram: + instructions = datagram.decode("utf-8").strip().split() + cmd = instructions[0] + if(cmd == "trigger"): + trigger = instructions[1] + instructions.pop(0) + instructions.pop(0) + print("Executing trigger {} with arguments {}".format(trigger, " ".join(instructions))) + os.system("events/triggers/{} {}".format(trigger, " ".join(instructions))) + conn.close()