Merge branch 'ChaosChemnitz' of github.com:ChaosChemnitz/CloudBot into ChaosChemnitz

This commit is contained in:
Florian Schlegel 2016-11-17 21:32:54 +01:00
commit c562a2c7ae
1 changed files with 45 additions and 0 deletions

View File

@ -6,6 +6,8 @@ import requests
import urllib
from subprocess import check_output
import json
import socket
import struct
def run_ecmd(cmd):
# baseuri = "http://netio.chch.lan.ffc/ecmd?"
@ -15,6 +17,49 @@ def run_ecmd(cmd):
req = requests.get("%s%s" % (baseuri, cmds))
return req.text.strip()
def run_udp(cmd):
ip="172.23.92.247"
port=49152
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# 10 ms timeout
s.settimeout(0.1)
s.sendto(cmd, (ip, port))
try:
rec = s.recvfrom(1024)[0]
except:
rec = ""
s.close()
print(rec)
return rec
# lamp_lounge handling
@hook.command("lamp_lounge", autohelp=True)
def cmd_lamp_lounge(inp, reply=None):
"""lamp_lounge color - set the lamp color"""
args = inp.split(" ")
if len(args) < 1:
reply("lamp_lounge color - set the lamp color")
return
if len(args[0]) != 6:
reply("lamp_lounge color - set the lamp color")
return
c = "a\x00\x03" + struct.pack('BBB', int(args[0][2:4], 16), int(args[0][0:2], 16), int(args[0][4:6], 16))
rep = run_udp(c)
if len(rep) < 3:
reply("Error: no reply")
return
if rep[0] == 'a':
reply("OK")
elif rep[0] == 'e':
reply("error: " + rep[3:])
else:
reply("fatal error")
# Lamp handling
@hook.command("lamp", autohelp=True)
def cmd_lamp(inp, reply=None):