View difference between Paste ID: ZMSGK0Nm and FYjsnghS
SHOW: | | - or go back to the newest paste.
1
# record.py
2
# records irc
3
4
#Special Thanks to sargon for helping with some bugs
5
import datetime
6
import   socket
7
import   string
8
import       os
9
10
def GetTimeStamp():
11
    DT = datetime.datetime.now()
12
    return ("%s:%s:%s" % (DT.hour, DT.minute, DT.second))
13
14
def GetNick(Domain):
15
    return Domain[1:Domain.find("!")]
16
17
def CleanInput(Line):
18
    if not Line[1] in ["PRIVMSG", "JOIN", "PART", "QUIT"]: return ""
19
20
    else:
21
        if   Line[1] == "JOIN": return ("[%s] %s has joined\n"   % (GetTimeStamp(), GetNick(Line[0])))
22
        elif Line[1] == "PART": return ("[%s] %s has left\n"     % (GetTimeStamp(), GetNick(Line[0])))
23
        elif Line[1] == "QUIT": return ("[%s] %s has left: %s\n" % (GetTimeStamp(), GetNick(Line[0]), ' '.join(Line[3:])))
24
        else:
25
            Line[3] = Line[3].replace(":", "")
26
27
            if Line[3] == (":" + chr(1) + "ACTION"):
28
                Line[-1] = Line[-1].replace("x01", "")
29
                return ("[%s] %s %s\n" % (GetTimeStamp(), GetNick(Line[0]), ' '.join(Line[4:])))
30
31
            else: return ("[%s] <%s> %s\n" % (GetTimeStamp(), GetNick(Line[0]), ' '.join(Line[3:])))
32
33
User = {
34
    "Host"    : "irc.quakenet.org",
35-
    "Nick"    : "DTSRecorder-Dev",
35+
    "Nick"    : "Recorder-Dev",
36
    "Channel" : "#BotDevGroundZero",
37
    "Port"    : 6667
38
}
39
40
if not os.path.exists("sessions"): os.makedirs("sessions")
41
42
Socket = socket.socket()
43
44
Socket.connect((User["Host"], User["Port"]))
45
Socket.send("NICK %s\r\n" % User["Nick"])
46
Socket.send("USER %s %s bla: %s\r\n" % (User["Nick"], User["Host"], User["Nick"]))
47
48
ServerBuffer = ""
49
DT = datetime.datetime.now()
50
51
while True:
52
    Date       = ("%s%s%s" % (DT.day, DT.month, DT.year))
53
    CurrentDir = "session" + Date
54
55
    if not os.path.exists("sessions/%s" % CurrentDir): os.makedirs("sessions/%s" % CurrentDir)
56
57
    Socket.send("JOIN %s\r\n" % User["Channel"])
58
59
    ServerBuffer = ServerBuffer + Socket.recv(1024)
60
    Temp         = string.split(ServerBuffer, "\n")
61
    ServerBuffer = Temp.pop()
62
63
    File = open(("./sessions/%s/session%s.log" % (CurrentDir, DT.hour)), "a")
64
65
    for Line in Temp:
66
        Line = string.rstrip(Line)
67
        Line = string.split (Line)
68
69
        print Line
70
        File.write(CleanInput(Line))
71
72
        if   Line[0] == "PING": Socket.send("PONG %s\r\n" % Line[1])
73
74
    File.close()