repo: fishbowl
action: blob
revision: 
path_from: fishbowl.py
revision_from: refs/heads/trunk:
path_to: 
revision_to: 
git.thebackupbox.net
fishbowl
git clone git://git.thebackupbox.net/fishbowl

blob of:

fishbowl

/ fishbowl.py

blob_plain of this file

refs/heads/trunk:/fishbowl.py

 #!/usr/bin/env python3

 import socket
 import queue
 import ssl

 stand_limit=3

 my_nick=b"fishbowl"
 my_chan=b"#fishbowl"

 s=socket.create_connection(("batou",6697))
 ss=ssl.wrap_socket(s)
 ss.send(b"NICK " + my_nick + b"\r\n")
 ss.send(b"USER f f f :f\r\n")
 q=queue.Queue()
 voiced=[]
 buf=b""
 connected=True
 while connected:
     i = ss.recv(4096)
     if i == "":
         connected=False
         #not breaking because we still want to process the data we have in the buffer.
     buf += i
     while b"\r\n" in buf:
         a=buf.split(b"\r\n")
         buf=b"\r\n".join(a[1:])
         line=a[0]
         b=line.split(b" ")
         if b[1] == b"004":
             ss.send(b"JOIN " + my_chan + b"\r\n")
             ss.send(b"MODE " + my_chan + b" +o " + my_nick + b"\r\n")
             ss.send(b"MODE " + my_chan + b" +m\r\n")
         if b[0] == b"PING":
             b[0]=b"PONG"
             ss.send(b" ".join(b) + b"\r\n")
         elif b[1] == b"PRIVMSG":
             nick=b[0].split(b"!")[0][1:]
             user=b[0].split(b"!")[1].split(b"@")[0]
             host=b[0].split(b"@")[1]
             print(b)
             if b[2] == my_chan or b[2] == my_nick:
                 if b[3] == b":stand":
                     if(nick in list(q.queue) ):
                         ss.send(b"NOTICE " + my_chan + b" :yo dawg, " + nick + b" tried to stand up while standing up.\r\n")
                     else:
                         q.put(nick)
                         ss.send(b"NOTICE " + my_chan + b" :" + nick + b" has stood up\r\n")
                 if b[3] == b":look":
                     ss.send(b"PRIVMSG " + my_chan + b" :" + b" ".join(list(q.queue)) + b"\r\n")
                 if b[3] == b":sit":
                     ss.send(b"MODE " + my_chan + b" -v " + nick + b"\r\n")
                     try:
                         voiced.remove(nick)
                     except:
                         pass #if people sit that somehow have voice but we didn't voice.... who cares?
         else:
             print(line);
         while len(voiced) < stand_limit and len(list(q.queue)) > 0:
             speaker=q.get()
             voiced.append(speaker)
             ss.send(b"MODE " + my_chan + b" +v " + speaker + b"\r\n")