3 def format_logline(line, channel):
4 if len(line.tokens) > 2:
5 if line.tokens[1] == "JOIN":
6 return "-> " + line.sender + " (" + \
7 line.tokens[0][len(line.sender)+2:] + ") joins"
8 elif line.tokens[1] == "PART":
10 if len(line.tokens) > 3 and line.tokens[3][0] == ":":
11 msg = " (" + str.join(" ", line.tokens[3:])[1:] + ")"
12 return "<- " + line.sender + " parts" + msg
13 elif line.tokens[1] == "QUIT":
15 if len(line.tokens) > 2 and line.tokens[2][0] == ":":
16 msg = " (" + str.join(" ", line.tokens[2:])[1:] + ")"
17 return "<- " + line.sender + " quits server" + msg
18 elif line.tokens[1] == "NICK":
19 return "-- " + line.sender + " changes their name to " + line.receiver
20 elif len(line.tokens) > 3:
21 if line.tokens[1] in {"PRIVMSG", "NOTICE"}:
22 if line.tokens[3] == ":\u0001ACTION" and \
23 line.tokens[-1][-1] == "\u0001":
24 msg = str.join(" ", line.tokens[4:])[:-1]
25 if line.receiver == channel:
26 return " * " + line.sender + " " + msg
28 msg = str.join(" ", line.tokens[3:])[1:]
29 if line.receiver == channel:
30 return " <" + line.sender + "> " + msg
31 elif line.tokens[1] == "TOPIC":
32 msg = str.join(" ", line.tokens[3:])[1:]
33 if line.receiver == channel:
34 return "-- " + line.sender + " sets topic to: " + msg
35 elif line.tokens[1] == "KICK":
36 operands = line.tokens[2:]
38 for i in range(len(operands)):
40 if operands[i][0] == ":":
41 msg = " (" + str.join(" ", operands[i:])[1:] + ")"
44 pairs[operands[i - 1]] = operands[i]
46 return "-- " + line.sender + " kicks " + pairs[channel] + msg
47 elif line.tokens[1] == "MODE":
48 msg = str.join(" ", line.tokens[3:])
49 if line.receiver == channel:
50 return "-- " + line.sender + " sets channel mode " + msg