Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 105 lines (92 sloc) 4.284 kb
6afcbc0 tommyrot add parser support for LimeChat
authored
1 <?php
2
3 /**
a188b82 tommyrot make use of the new output class
authored
4 * Copyright (c) 2012-2015, Jos de Ruijter <jos@dutnie.nl>
6afcbc0 tommyrot add parser support for LimeChat
authored
5 */
6
7 /**
8 * Parse instructions for the LimeChat logfile format.
9 *
dc0f207 tommyrot big boring reformatting commit to please my IDE and OCD
authored
10 * Line Format Notes
11 * ---------------------------------------------------------------------------------------------------------------------
efd76dc tommyrot linebreaks and formatting
authored
12 * Normal NICK: MSG Skip empty lines.
13 * Nickchange NICK is now known as NICK
14 * Join NICK has joined (HOST)
15 * Part NICK has left (MSG) Part message may be empty due to normalization.
16 * Quit NICK has left IRC (MSG) Quit message may be empty due to normalization.
dc0f207 tommyrot big boring reformatting commit to please my IDE and OCD
authored
17 * IRC is literal.
efd76dc tommyrot linebreaks and formatting
authored
18 * Mode NICK has changed mode: +o-v NICK NICK Only check for combinations of ops (+o) and
dc0f207 tommyrot big boring reformatting commit to please my IDE and OCD
authored
19 * voices (+v).
efd76dc tommyrot linebreaks and formatting
authored
20 * Topic NICK has set topic: MSG Skip empty topics.
21 * Kick NICK has kicked NICK (MSG) Kick message may be empty due to normalization.
dc0f207 tommyrot big boring reformatting commit to please my IDE and OCD
authored
22 * ---------------------------------------------------------------------------------------------------------------------
6afcbc0 tommyrot add parser support for LimeChat
authored
23 *
24 * Notes:
25 * - normalize_line() scrubs all lines before passing them on to parse_line().
26 * - LimeChat uses the same syntax for actions as "normal" lines. This makes the two indistinguishable. Pretty dumb.
dc0f207 tommyrot big boring reformatting commit to please my IDE and OCD
authored
27 * - Given that nicks can't contain ":" the order of the regular expressions below is irrelevant (current order aims for
28 * best performance).
6afcbc0 tommyrot add parser support for LimeChat
authored
29 */
a188b82 tommyrot make use of the new output class
authored
30 class parser_limechat extends parser
6afcbc0 tommyrot add parser support for LimeChat
authored
31 {
32 /**
33 * Parse a line for various chat data.
34 */
35 protected function parse_line($line)
36 {
37 /**
38 * "Normal" lines.
39 */
40 if (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) (?<nick>\S+): (?<line>.+)$/', $line, $matches)) {
307a8af tommyrot prefix date to time at latest moment instead of first
authored
41 $this->set_normal($matches['time'], $matches['nick'], $matches['line']);
6afcbc0 tommyrot add parser support for LimeChat
authored
42
43 /**
44 * "Join" lines.
45 */
46 } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) (?<nick>\S+) has joined \(\S+\)$/', $line, $matches)) {
307a8af tommyrot prefix date to time at latest moment instead of first
authored
47 $this->set_join($matches['time'], $matches['nick']);
6afcbc0 tommyrot add parser support for LimeChat
authored
48
49 /**
50 * "Quit" lines.
51 */
52 } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) (?<nick>\S+) has left IRC \(.*\)$/', $line, $matches)) {
307a8af tommyrot prefix date to time at latest moment instead of first
authored
53 $this->set_quit($matches['time'], $matches['nick']);
6afcbc0 tommyrot add parser support for LimeChat
authored
54
55 /**
56 * "Mode" lines.
57 */
58 } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) (?<nick_performing>\S+) has changed mode: (?<modes>[-+][ov]+([-+][ov]+)?) (?<nicks_undergoing>\S+( \S+)*)$/', $line, $matches)) {
59 $modenum = 0;
dc0f207 tommyrot big boring reformatting commit to please my IDE and OCD
authored
60 $nicks_undergoing = explode(' ', $matches['nicks_undergoing']);
6afcbc0 tommyrot add parser support for LimeChat
authored
61
62 for ($i = 0, $j = strlen($matches['modes']); $i < $j; $i++) {
63 $mode = substr($matches['modes'], $i, 1);
64
3985e3e tommyrot move to strict comparisons
authored
65 if ($mode === '-' || $mode === '+') {
6afcbc0 tommyrot add parser support for LimeChat
authored
66 $modesign = $mode;
67 } else {
307a8af tommyrot prefix date to time at latest moment instead of first
authored
68 $this->set_mode($matches['time'], $matches['nick_performing'], $nicks_undergoing[$modenum], $modesign.$mode);
6afcbc0 tommyrot add parser support for LimeChat
authored
69 $modenum++;
70 }
71 }
72
73 /**
74 * "Nickchange" lines.
75 */
76 } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) (?<nick_performing>\S+) is now known as (?<nick_undergoing>\S+)$/', $line, $matches)) {
307a8af tommyrot prefix date to time at latest moment instead of first
authored
77 $this->set_nickchange($matches['time'], $matches['nick_performing'], $matches['nick_undergoing']);
6afcbc0 tommyrot add parser support for LimeChat
authored
78
79 /**
80 * "Part" lines.
81 */
82 } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) (?<nick>\S+) has left \(.*\)$/', $line, $matches)) {
307a8af tommyrot prefix date to time at latest moment instead of first
authored
83 $this->set_part($matches['time'], $matches['nick']);
6afcbc0 tommyrot add parser support for LimeChat
authored
84
85 /**
86 * "Topic" lines.
87 */
88 } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) (?<nick>\S+) has set topic: (?<line>.+)$/', $line, $matches)) {
307a8af tommyrot prefix date to time at latest moment instead of first
authored
89 $this->set_topic($matches['time'], $matches['nick'], $matches['line']);
6afcbc0 tommyrot add parser support for LimeChat
authored
90
91 /**
92 * "Kick" lines.
93 */
94 } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) (?<line>(?<nick_performing>\S+) has kicked (?<nick_undergoing>\S+) \(.*\))$/', $line, $matches)) {
307a8af tommyrot prefix date to time at latest moment instead of first
authored
95 $this->set_kick($matches['time'], $matches['nick_performing'], $matches['nick_undergoing'], $matches['line']);
6afcbc0 tommyrot add parser support for LimeChat
authored
96
97 /**
98 * Skip everything else.
99 */
3985e3e tommyrot move to strict comparisons
authored
100 } elseif ($line !== '') {
0e0a8f4 tommyrot simplify and be slightly more verbose in our output messages
authored
101 output::output('debug', __METHOD__.'(): skipping line '.$this->linenum.': \''.$line.'\'');
6afcbc0 tommyrot add parser support for LimeChat
authored
102 }
103 }
104 }
Something went wrong with that request. Please try again.