13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/crazy_doll/message.rb', line 13
def self.parse(line)
new case line
when /\A:([^!]+)!([^@]+)@(\S+) PRIVMSG (\S+) :(.*)\z/ then
{
:from => parse_from($~),
:command => "PRIVMSG",
:to => $~[4],
:message => $~[5]
}
when /\APING :(.*)$/ then
{
:from => $~[1],
:to => $~[1],
:command => "PING"
}
when /\A:([^!]+)!([^@]+)@(\S+) NOTICE (\S+) :(.*)\z/ then
{
:from => parse_from($~),
:to => $~[4],
:message => $~[5],
:command => "NOTICE"
}
when /\A:([^!]+)!([^@]+)@(\S+) JOIN :(.*)\z/ then
{
:from => parse_from($~),
:user => $~[1],
:channel => $~[4],
:command => "JOIN"
}
when /\A:(\S+) 353 (\S+) = (\S+) :(.*)\z/ then
{
:from => $~[1],
:me => $~[2],
:channel => $~[3],
:users => $~[4].split(" "),
:command => 353
}
when /\A:([^!]+)!([^@]+)@(\S+) NICK :(.*)\z/ then
{
:from => parse_from($~),
:command => "NICK",
:new_nick => $~[4]
}
when /\A:([^!]+)!([^@]+)@(\S+) (\S+) (\S+) :(.*)\z/ then
{
:from => parse_from($~),
:command => $~[4],
:to => $~[5],
:message => $~[6]
}
when /\A:([^!]+)!([^@]+)@(\S+) (\S+) :(.*)\z/ then
{
:from => parse_from($~),
:command => $~[4],
:to => $~[1],
:message => $~[5]
}
when /\A:(\S+) (\S+) (\S+) (\S+) :(.*)\z/ then
{
:from => $~[1],
:command => $~[2],
:to => $~[3],
:extra => $~[4],
:message => $~[5]
}
when /\A:(\S+) (\S+) (\S+) :(.*)\z/
{
:from => $~[1],
:command => $~[2],
:to => $~[3],
:message => $~[4]
}
when /\A:(\S+) (\S+) (\S+) ([^:]+) :(.*)\z/ then
{
:from => $~[1],
:command => $~[2],
:to => $~[3],
:extras => $~[4].split(' '),
:message => $~[5]
}
else
{
:extras => line.split(' ')
}
end.update({ :source => line })
end
|