-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommands.rb
77 lines (66 loc) · 1.94 KB
/
commands.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
71
72
73
74
75
76
77
module WebRic
# Commands that can be sent from the web client.
module Commands
# Parse and delegate incomming commands from web client
def parse_command(hash)
command = hash['command']
args = hash['args']
puts "Invalid command: command_#{command}".to_sym unless self.respond_to?("command_#{command}")
begin
self.method("command_#{command}".to_sym).call(args) if self.respond_to?("command_#{command}")
rescue
end
end
# Configure server, nick, etc, and connect.
def command_setup(args)
setup(args)
end
# Send private / channel message.
def command_privmsg(args)
channel=args['channel']
msg=args['message']
target = bot.Target(channel)
target.send(msg)
privmsg(channel,bot.nick,msg)
end
# handle /msg
def command_msg(args)
target,msg = args['args'].split(/\s/,2)
begin
bot.Target(target).send(msg)
rescue
systemmsg("error","No such channel or user, #{target}")
end
end
# Handle /me
def command_me(args)
channel=args['channel']
message=args['message']
target=bot.Target(channel)
target.action(message)
action(channel,bot.nick,message)
end
# Join a channel
def command_join(args)
return unless args['args']
args['args'].split(/[,\s]/).each { |channel|
bot.join(channel.strip) if channel.strip.start_with? "#" # join if actual channel
}
end
# Leave a channel
def command_part(args)
target=bot.Channel(args['args'])
target.part
end
# Send unknown IRC commands to IRC server
def command_raw(args)
end
# Get list of users in channel.
def command_names(args)
channel=args['channel']
target=bot.Channel(channel)
users = target.users.map { |u,m| "#{'@' if m.include? "o" }#{'+' if m.include? "v"}#{u}"}.sort
send_command("names",users: users)
end
end
end