Skip to content

Instantly share code, notes, and snippets.

@kach
Created November 25, 2014 01:48
Show Gist options
  • Save kach/e3b81bd8c2e880155d62 to your computer and use it in GitHub Desktop.
Save kach/e3b81bd8c2e880155d62 to your computer and use it in GitHub Desktop.
import ssl
import socket
import time
import datetime
HOST = "irc.pdgn.co"
PORT = 6697
CHAN = "#study"
NICK = "Study_Bot"
STUDY_TIME = datetime.timedelta(0, 60*20)
FUN_TIME = datetime.timedelta(0, 60*5)
raw = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s = ssl.wrap_socket(raw)
s.connect((socket.gethostbyname("irc.pdgn.co"), 6697))
print s.recv(1024)
def send(x):
s.send(x+"\r\n")
def display(x):
send("PRIVMSG %s :%s"%(CHAN, x))
send("NICK %s"%(NICK))
send("USER %s 0 0 %s"%(NICK, NICK))
while True:
x = s.recv(1024)
print x,
if "You are connected" in x:
break
send("JOIN %s"%(CHAN))
NAMES = "hardmath123 JacobEdelman Tamini (ping hardmath123 to add you)"
#send("NAMES %s"%(CHAN))
#NAMES = s.recv().split("\r\n")[0].split(":")[2]
def pong():
send("PONG") # lord of the pings
def breathe():
pong()
time.sleep(3)
def now():
return datetime.datetime.now()
target = now()
while True:
try:
while now() < target:
breathe()
target = now() + STUDY_TIME
display("--- Study time until %s. Paging %s"%(target.strftime("**:%M %p"), NAMES))
while now() < target:
breathe()
target = now() + FUN_TIME
display("--- Fun time until %s. Paging %s"%(target.strftime("**:%M %p"), NAMES))
except KeyboardInterrupt:
send("PART %s :So long, and thanks for all the fish."%(CHAN))
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment