Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # record.py
- # records irc
- #Special Thanks to sargon for helping with some bugs
- import datetime
- import socket
- import string
- import os
- def GetTimeStamp():
- DT = datetime.datetime.now()
- return ("%s:%s:%s" % (DT.hour, DT.minute, DT.second))
- def GetNick(Domain):
- return Domain[1:Domain.find("!")]
- def CleanInput(Line):
- if not Line[1] in ["PRIVMSG", "JOIN", "PART", "QUIT"]: return ""
- else:
- if Line[1] == "JOIN": return ("[%s] %s has joined\n" % (GetTimeStamp(), GetNick(Line[0])))
- elif Line[1] == "PART": return ("[%s] %s has left\n" % (GetTimeStamp(), GetNick(Line[0])))
- elif Line[1] == "QUIT": return ("[%s] %s has left: %s\n" % (GetTimeStamp(), GetNick(Line[0]), ' '.join(Line[3:])))
- else:
- Line[3] = Line[3].replace(":", "")
- if Line[3] == (":" + chr(1) + "ACTION"):
- Line[-1] = Line[-1].replace("x01", "")
- return ("[%s] %s %s\n" % (GetTimeStamp(), GetNick(Line[0]), ' '.join(Line[4:])))
- else: return ("[%s] <%s> %s\n" % (GetTimeStamp(), GetNick(Line[0]), ' '.join(Line[3:])))
- User = {
- "Host" : "irc.quakenet.org",
- "Nick" : "Recorder-Dev",
- "Channel" : "#BotDevGroundZero",
- "Port" : 6667
- }
- if not os.path.exists("sessions"): os.makedirs("sessions")
- Socket = socket.socket()
- Socket.connect((User["Host"], User["Port"]))
- Socket.send("NICK %s\r\n" % User["Nick"])
- Socket.send("USER %s %s bla: %s\r\n" % (User["Nick"], User["Host"], User["Nick"]))
- ServerBuffer = ""
- DT = datetime.datetime.now()
- while True:
- Date = ("%s%s%s" % (DT.day, DT.month, DT.year))
- CurrentDir = "session" + Date
- if not os.path.exists("sessions/%s" % CurrentDir): os.makedirs("sessions/%s" % CurrentDir)
- Socket.send("JOIN %s\r\n" % User["Channel"])
- ServerBuffer = ServerBuffer + Socket.recv(1024)
- Temp = string.split(ServerBuffer, "\n")
- ServerBuffer = Temp.pop()
- File = open(("./sessions/%s/session%s.log" % (CurrentDir, DT.hour)), "a")
- for Line in Temp:
- Line = string.rstrip(Line)
- Line = string.split (Line)
- print Line
- File.write(CleanInput(Line))
- if Line[0] == "PING": Socket.send("PONG %s\r\n" % Line[1])
- File.close()
Advertisement
Add Comment
Please, Sign In to add comment