citadel-core/karen-v2
2022-05-16 07:19:50 +00:00

31 lines
819 B
Python
Executable File

#!/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()