Created
March 29, 2013 00:47
-
-
Save lukegb/5267980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
MUTED_GROUP = 8 | |
UNMUTED_GROUP = 7 | |
WHO_UID = 'uaec6gN9PL9qwP5y1NGGW3D95VA=' | |
#WHO_UID = 'BaP5bZRXx7OP59qJojvvHHxvx0w=' | |
HOST = '127.0.0.1' | |
PORT = 25639 | |
def wait_for_ok(s): | |
buff = b'' | |
while True: | |
d = s.recv(1024) | |
buff += d | |
ds = str(d) | |
print('<', ds) | |
if ds.find('error id=') != -1: | |
break | |
print('!') | |
return buff.split(b'\n\r') | |
def send(s, z): | |
print('>', z) | |
s.sendall(z) | |
def intb(b): | |
return bytes(str(b), 'utf-8') | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((HOST, PORT)) | |
send(s, b'clientnotifyregister schandlerid=1 event=notifychannelgroupclientlist\r\n') | |
wait_for_ok(s) | |
send(s, b'clientnotifyregister schandlerid=1 event=notifyclientdbidfromuid\r\n') | |
wait_for_ok(s) | |
send(s, b'clientgetdbidfromuid cluid=' + bytes(WHO_UID, 'utf-8') + b'\r\n') | |
z = wait_for_ok(s) | |
WHO_CLDBID = -1 | |
for ln in z: | |
if ln.startswith(b'notifyclientdbidfromuid'): | |
WHO_CLDBID = int(ln[ln.find(b'cldbid=') + len(b'cldbid='):]) | |
break | |
if WHO_CLDBID == -1: | |
print("WAT") | |
else: | |
send(s, b'channelgroupclientlist cldbid=' + intb(WHO_CLDBID) + b'\r\n') | |
z = wait_for_ok(s) | |
current_group = -1 | |
for ln in z: | |
if ln.startswith(b'notifychannelgroupclientlist'): | |
current_group = int(ln[ln.find(b'cgid=') + len(b'cgid='):]) | |
break | |
if current_group == -1: | |
current_group = MUTED_GROUP | |
print("Currently in group:", current_group) | |
new_group = MUTED_GROUP if current_group != MUTED_GROUP else UNMUTED_GROUP | |
print("Setting group to:", new_group) | |
send(s, b'setclientchannelgroup cgid=' + intb(new_group) + b' cid=1 cldbid=' + intb(WHO_CLDBID) + b'\r\n') | |
wait_for_ok(s) | |
send(s, b'quit\r\n') | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awesome