3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/vetinari/message_parser.rb', line 3
def parse(message, chantypes)
chantypes = chantypes.map { |c| Regexp.escape(c) }.join('|')
case message
when /^(?:\:\S+ )?(\d\d\d) /
number = $1.to_i
{:type => number, :params => $'}
when /^:(\S+)!(\S+)@(\S+) PRIVMSG ((?:#{chantypes})\S+) :/
{:type => :channel, :nick => $1, :user => $2, :host => $3, :channel => $4, :message => $'}
when /^:(\S+)!(\S+)@(\S+) PRIVMSG \S+ :/
{:type => :query, :nick => $1, :user => $2, :host => $3, :message => $'}
when /^:(\S+)!(\S+)@(\S+) JOIN :*(\S+)$/
{:type => :join, :nick => $1, :user => $2, :host => $3, :channel => $4}
when /^:(\S+)!(\S+)@(\S+) PART (\S+)/
{:type => :part, :nick => $1, :user => $2, :host => $3, :channel => $4, :message => $'.sub(/ :/, '')}
when /^:(\S+)!(\S+)@(\S+) QUIT/
{:type => :quit, :nick => $1, :user => $2, :host => $3, :message => $'.sub(/ :/, '')}
when /^:(\S+)!(\S+)@(\S+) MODE ((?:#{chantypes})\S+) ([+-]\S+)/
{:type => :channel_mode, :nick => $1, :user => $2, :host => $3, :channel => $4, :modes => $5, :params => $'.lstrip}
when /^:(\S+)!(\S+)@(\S+) NICK :/
{:type => :nick_change, :nick => $1, :user => $2, :host => $3, :new_nick => $'}
when /^:(\S+)!(\S+)@(\S+) KICK (\S+) (\S+) :/
{:type => :kick, :nick => $1, :user => $2, :host => $3, :channel => $4, :kickee => $5, :message => $'}
when /^:(\S+)!(\S+)@(\S+) TOPIC (\S+) :/
{:type => :topic, :nick => $1, :user => $2, :host => $3, :channel => $4, :topic => $'}
else
{}
end
end
|