/
events.rb
64 lines (52 loc) · 1.78 KB
/
events.rb
1
2
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
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
module MiniBot
module Events
def message(channel, sender, message)
end
def private_message(sender, message)
end
def user_joined(channel, nick)
end
def user_parted(channel, nick)
end
def user_action(channel, nick, message)
end
def invited(channel, nick)
end
def default(command_str)
end
def pinged
end
def topic_changed(channel, nick, topic)
end
def kicked(channel, nick, message)
end
def user_kicked(channel, kicker, kicked, message)
end
private
def dispatch(command)
if match = (/^:(\w+)!.+ PRIVMSG (#\w+) :([^\001].+)/.match command)
send :message, match[2], match[1], match[3]
elsif match = (/^:(\w+)!.+ JOIN :(#\w+)/.match command)
send :user_joined, match[2], match[1]
elsif match = (/^:(\w+)!.+ PART :(#\w+)/.match command)
send :user_parted, match[2], match[1]
elsif match = (/^:(\w+)!.+ PRIVMSG (#\w+) :\001ACTION (.+)\001/.match command)
send :user_action, match[2], match[1], match[3]
elsif match = (/^:(\w+)!.+ PRIVMSG #{@nick} :(.+)/.match command)
send :private_message, match[1], match[2]
elsif match = (/^:(\w+)!.+ INVITE \w+ :(#\w+)/.match command)
send :invited, match[2], match[1]
elsif match = (/^PING/.match command)
send :pinged
elsif match = (/^:(\w+)!.+ TOPIC (#\w+) :(.+)/.match command)
send :topic_changed, match[2], match[1], match[3]
elsif match = (/^:(\w+)!.+ KICK (#\w+) #{@nick} :(.+)/.match command)
send :kicked, match[2], match[1], match[3]
elsif match = (/^:(\w+)!.+ KICK (#\w+) (\w+) :(.+)/.match command)
send :user_kicked, match[2], match[1], match[3], match[4]
else
send :default, command
end
end
end
end