-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_modules.rb
70 lines (59 loc) · 1.83 KB
/
command_modules.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
65
66
67
68
69
70
@command_modules = {}
def register_command_module(event, *catch)
catch.each {|c| @command_modules[c] = event }
end
def is_command_module?(catch)
@command_modules[catch.sub(/^\//,'')]
end
def run_command_modules(cmd, args)
prefix, command = cmd[/^(\/)?(.+)/,1], $2
if @bind_mode and !prefix
handle_privmsg(@bind_mode,[cmd, *args])
else
modules = @command_modules.find_all{|k,v| command == k}
modules.each do |reg, event|
send(event, *args)
end
end
end
register_command_module :handle_raw, 'raw'
def handle_raw(*args)
log args.join(' '), @socket
end
register_command_module :handle_privmsg, 'privmsg', '>'
def handle_privmsg(target, *args)
log "PRIVMSG #{target = channel_name target} :#{args.join ' '}", @socket
log_m target, "<#{@nick}> #{args.join ' '}", @channel_f
end
register_command_module :handle_join, 'j', 'join'
def handle_join(channel, *args)
@channels.push channel
log "JOIN #{channel_name channel}", @socket
end
register_command_module :handle_part, 'p', 'part'
def handle_part(channel, *args)
@channels.delete channel
@channel_aliases.delete_if{|k,v| v == channel}
log "PART #{channel_name channel}", @socket
end
register_command_module :handle_action, 'me'
def handle_action(target, *args)
if @bind_mode
args.unshift target
target = @bind_mode
end
log "PRIVMSG #{channel_name target} :\001ACTION #{args.join ' '}\001", @socket
log_m target, "* #{@nick} #{args.join}", @channel_f
end
register_command_module :handle_alias, 'alias'
def handle_alias(new_name, old_name, *args)
@channel_aliases[new_name] = channel_name old_name
end
register_command_module :handle_bind, 'bind', '&', 'unbind'
def handle_bind(*args)
@bind_mode = channel_name args[0]
end
register_command_module :handle_nicklist, 'nicklist', 'names'
def handle_nicklist(*args)
log "NAMES #{channel_name args[0] ? args[0] : @bind_mode}", @socket
end