Module: EventMachine::IRC::Commands
- Included in:
- Client
- Defined in:
- lib/em-irc/commands.rb
Overview
Client commands
Instance Method Summary collapse
-
#admin(target = nil) ⇒ Object
Find info about admin of a given server.
-
#away(message = nil) ⇒ Object
Set user as away with optional message.
-
#channel_mode ⇒ Object
Set channel mode.
-
#die ⇒ Object
Shutdown server.
-
#error(message) ⇒ Object
Server serious or fatal error, or to terminate a connection on quit.
-
#info(target = nil) ⇒ Object
Describe server information.
-
#invite(nickname, channel) ⇒ Object
Invite a user to a channel.
-
#ison(*nicks) ⇒ Object
Efficient way to check if nicks are currently on.
-
#join(*args) ⇒ Object
Join a channel.
-
#kick(*args) ⇒ Object
Kick a user from a channel.
-
#kill(nickname, comment = "Connection killed") ⇒ Object
Terminate a connection by nickname.
-
#links(remote_server = nil, server_mask = nil) ⇒ Object
List all servernames.
-
#list(*args) ⇒ Object
List channels and topics.
-
#lusers(mask = nil, target = nil) ⇒ Object
List users.
-
#mode(nickname, setting) ⇒ Object
Set user mode.
-
#motd(target = nil) ⇒ Object
Get message of the day for a server or current server.
-
#names(*args) ⇒ Object
List all nicknames visible to user.
-
#nick(nick = nil) ⇒ String
Set/get user nick.
-
#notice(target, message) ⇒ Object
Send message to user or channel.
-
#oper(name, password) ⇒ Object
Gain operator privledges.
-
#part(*args) ⇒ Object
Leave a channel.
-
#part_all ⇒ Object
Part all channels.
-
#pass(password) ⇒ Object
Set connection password.
-
#ping(server, target = '') ⇒ Object
Test connection is alive.
-
#pong(*servers) ⇒ Object
Respond to a server ping.
-
#privmsg(target, message) ⇒ Object
(also: #message)
Send message to user or channel.
-
#quit(message = 'leaving') ⇒ Object
Terminate connection.
-
#rehash ⇒ Object
Force user to re-read config.
-
#restart ⇒ Object
Restart server.
-
#server_connect(target, port, remote = nil) ⇒ Object
Connect to another server.
-
#service(nickname, reserved, distribution, type) ⇒ Object
Register a new service.
-
#servlist(mask = nil, type = nil) ⇒ Object
(also: #server_list)
List services connected to network.
-
#squery(service, text) ⇒ Object
Send a message to a service.
-
#squit(server, message = "quiting") ⇒ Object
Disconnect server links.
-
#stats(query = nil, target = nil) ⇒ Object
Get stats for a server.
-
#summon(user, target = nil, channel = nil) ⇒ Object
Ask user to join IRC.
-
#time(target = nil) ⇒ Object
Get server local time.
-
#topic(channel, message = nil) ⇒ Object
Set/get topic.
-
#trace(target = nil) ⇒ Object
Find the route to a specific server.
-
#user(username, mode, realname) ⇒ Object
Set username, hostname, and realname.
-
#userhost(*nicks) ⇒ Object
Returns information about up to 5 nicknames.
-
#users(target = nil) ⇒ Object
List logged in users.
-
#version(target = nil) ⇒ Object
Get server version.
-
#wallops(message) ⇒ Object
(also: #broadcast)
Broadcast to all logged in users.
-
#who(mask, mode = 'o') ⇒ Object
Get info about a user.
-
#whois(*args) ⇒ Object
Get user information about a list of users.
-
#whowas(*args) ⇒ Object
Get user information that no longer exists (nick changed, etc).
Instance Method Details
#admin(target = nil) ⇒ Object
Find info about admin of a given server
223 224 225 |
# File 'lib/em-irc/commands.rb', line 223 def admin(target = nil) send_data("ADMIN #{target}".strip) end |
#away(message = nil) ⇒ Object
Set user as away with optional message
303 304 305 |
# File 'lib/em-irc/commands.rb', line 303 def away( = nil) send_data("AWAY" + ( ? ":#{}" : "")) end |
#channel_mode ⇒ Object
name conflict with user MODE message
Set channel mode
97 98 99 |
# File 'lib/em-irc/commands.rb', line 97 def channel_mode raise NotImplementedError.new end |
#die ⇒ Object
Shutdown server
315 316 317 |
# File 'lib/em-irc/commands.rb', line 315 def die send_data("DIE") end |
#error(message) ⇒ Object
Server serious or fatal error, or to terminate a connection on quit
297 298 299 |
# File 'lib/em-irc/commands.rb', line 297 def error() send_data("ERROR :#{}") end |
#info(target = nil) ⇒ Object
Describe server information
229 230 231 |
# File 'lib/em-irc/commands.rb', line 229 def info(target = nil) send_data("INFO #{target}".strip) end |
#invite(nickname, channel) ⇒ Object
Invite a user to a channel
137 138 139 |
# File 'lib/em-irc/commands.rb', line 137 def invite(nickname, channel) send_data("INVITE #{nickname} #{channel}") end |
#ison(*nicks) ⇒ Object
Efficient way to check if nicks are currently on
353 354 355 |
# File 'lib/em-irc/commands.rb', line 353 def ison(*nicks) send_data("ISON #{nicks.join(' ')}") end |
#join(*args) ⇒ Object
Join a channel
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/em-irc/commands.rb', line 65 def join(*args) raise ArgumentError.new("Not enough arguments") unless args.size > 0 channels, keys = [], [] args.map! {|arg| arg.is_a?(Array) ? arg : [arg, '']} args.sort! {|a,b| b[1].length <=> a[1].length} # key channels first args.each {|arg| channels << arg[0] keys << arg[1] if arg[1].length > 0 } send_data("JOIN #{channels.join(',')} #{keys.join(',')}".strip) end |
#kick(*args) ⇒ Object
Kick a user from a channel
147 148 149 150 151 152 |
# File 'lib/em-irc/commands.rb', line 147 def kick(*args) channels = args.select {|arg| channel?(arg)} nicks = args.select {|arg| !channel?(arg)} raise ArgumentError.new("Missing channels") if channels.empty? send_data("KICK #{channels.join(',')} #{nicks.join(',')}".strip) end |
#kill(nickname, comment = "Connection killed") ⇒ Object
Terminate a connection by nickname
279 280 281 |
# File 'lib/em-irc/commands.rb', line 279 def kill(nickname, comment = "Connection killed") send_data("KILL #{nickname} :#{comment}".strip) end |
#links(remote_server = nil, server_mask = nil) ⇒ Object
List all servernames
199 200 201 |
# File 'lib/em-irc/commands.rb', line 199 def links(remote_server = nil, server_mask = nil) send_data("LINKS #{remote_server} #{server_mask}".strip) end |
#list(*args) ⇒ Object
List channels and topics
127 128 129 130 |
# File 'lib/em-irc/commands.rb', line 127 def list(*args) = args. send_data("LIST #{args.join(',')} #{[:target]}".strip) end |
#lusers(mask = nil, target = nil) ⇒ Object
List users
180 181 182 |
# File 'lib/em-irc/commands.rb', line 180 def lusers(mask = nil, target = nil) send_data("LUSERS #{mask} #{target}".strip) end |
#mode(nickname, setting) ⇒ Object
Set user mode
38 39 40 |
# File 'lib/em-irc/commands.rb', line 38 def mode(nickname, setting) raise NotImplementedError.new end |
#motd(target = nil) ⇒ Object
Get message of the day for a server or current server
174 175 176 |
# File 'lib/em-irc/commands.rb', line 174 def motd(target = nil) send_data("MOTD #{target}".strip) end |
#names(*args) ⇒ Object
List all nicknames visible to user
117 118 119 120 |
# File 'lib/em-irc/commands.rb', line 117 def names(*args) = args. send_data("NAMES #{args.join(',')} #{[:target]}".strip) end |
#nick(nick = nil) ⇒ String
Set/get user nick
16 17 18 19 20 21 22 |
# File 'lib/em-irc/commands.rb', line 16 def nick(nick = nil) if nick send_data("NICK #{nick}") else @nick end end |
#notice(target, message) ⇒ Object
Send message to user or channel
167 168 169 |
# File 'lib/em-irc/commands.rb', line 167 def notice(target, ) send_data("NOTICE #{target} :#{}") end |
#oper(name, password) ⇒ Object
Gain operator privledges
32 33 34 |
# File 'lib/em-irc/commands.rb', line 32 def oper(name, password) send_data("OPER #{name} #{password}") end |
#part(*args) ⇒ Object
Leave a channel
89 90 91 92 93 |
# File 'lib/em-irc/commands.rb', line 89 def part(*args) raise ArgumentError.new("Not enough arguments") unless args.size > 0 = channel?(args.last) ? "Leaving..." : args.pop send_data("PART #{args.join(',')} :#{}") end |
#part_all ⇒ Object
Part all channels
78 79 80 |
# File 'lib/em-irc/commands.rb', line 78 def part_all join('0') end |
#pass(password) ⇒ Object
Set connection password
8 9 10 |
# File 'lib/em-irc/commands.rb', line 8 def pass(password) send_data("PASS #{password}") end |
#ping(server, target = '') ⇒ Object
Test connection is alive
285 286 287 |
# File 'lib/em-irc/commands.rb', line 285 def ping(server, target = '') send_data("PING #{server} #{target}".strip) end |
#pong(*servers) ⇒ Object
Respond to a server ping
291 292 293 |
# File 'lib/em-irc/commands.rb', line 291 def pong(*servers) send_data("PONG #{servers.join(' ')}") end |
#privmsg(target, message) ⇒ Object Also known as: message
Send message to user or channel
158 159 160 |
# File 'lib/em-irc/commands.rb', line 158 def privmsg(target, ) send_data("PRIVMSG #{target} :#{}") end |
#quit(message = 'leaving') ⇒ Object
Terminate connection
49 50 51 |
# File 'lib/em-irc/commands.rb', line 49 def quit( = 'leaving') send_data("QUIT :#{}") end |
#rehash ⇒ Object
Force user to re-read config
309 310 311 |
# File 'lib/em-irc/commands.rb', line 309 def rehash send_data("REHASH") end |
#restart ⇒ Object
Restart server
321 322 323 |
# File 'lib/em-irc/commands.rb', line 321 def restart send_data("RESTART") end |
#server_connect(target, port, remote = nil) ⇒ Object
Connect to another server
211 212 213 |
# File 'lib/em-irc/commands.rb', line 211 def server_connect(target, port, remote = nil) send_data("CONNECT #{target} #{port} #{remote}".strip) end |
#service(nickname, reserved, distribution, type) ⇒ Object
Register a new service
44 45 |
# File 'lib/em-irc/commands.rb', line 44 def service(nickname, reserved, distribution, type) end |
#servlist(mask = nil, type = nil) ⇒ Object Also known as: server_list
List services connected to network
235 236 237 |
# File 'lib/em-irc/commands.rb', line 235 def servlist(mask = nil, type = nil) send_data("SERVLIST #{mask} #{type}".strip) end |
#squery(service, text) ⇒ Object
Send a message to a service
242 243 244 |
# File 'lib/em-irc/commands.rb', line 242 def squery(service, text) send_data("SQUERY #{service} :#{text}") end |
#squit(server, message = "quiting") ⇒ Object
Disconnect server links
55 56 57 |
# File 'lib/em-irc/commands.rb', line 55 def squit(server, = "quiting") raise NotImplementedError.new end |
#stats(query = nil, target = nil) ⇒ Object
Get stats for a server
193 194 195 |
# File 'lib/em-irc/commands.rb', line 193 def stats(query = nil, target = nil) send_data("STATS #{query} #{target}".strip) end |
#summon(user, target = nil, channel = nil) ⇒ Object
Ask user to join IRC
327 328 329 |
# File 'lib/em-irc/commands.rb', line 327 def summon(user, target = nil, channel = nil) send_data("SUMMON #{user} #{target} #{channel}".strip) end |
#time(target = nil) ⇒ Object
Get server local time
205 206 207 |
# File 'lib/em-irc/commands.rb', line 205 def time(target = nil) send_data("TIME #{target}".strip) end |
#topic(channel, message = nil) ⇒ Object
Set/get topic
107 108 109 110 |
# File 'lib/em-irc/commands.rb', line 107 def topic(channel, = nil) = .nil? ? "" : ":#{}" send_data("TOPIC #{channel} #{}".strip) end |
#trace(target = nil) ⇒ Object
Find the route to a specific server
217 218 219 |
# File 'lib/em-irc/commands.rb', line 217 def trace(target = nil) send_data("TRACE #{target}".strip) end |
#user(username, mode, realname) ⇒ Object
Set username, hostname, and realname
26 27 28 |
# File 'lib/em-irc/commands.rb', line 26 def user(username, mode, realname) send_data("USER #{username} #{mode} * :#{realname}") end |
#userhost(*nicks) ⇒ Object
Returns information about up to 5 nicknames
346 347 348 349 |
# File 'lib/em-irc/commands.rb', line 346 def userhost(*nicks) raise ArgumentError.new("Wrong number of arguments") unless nicks.size > 0 && nicks.size <= 5 send_data("USERHOST #{nicks.join(' ')}") end |
#users(target = nil) ⇒ Object
List logged in users
333 334 335 |
# File 'lib/em-irc/commands.rb', line 333 def users(target = nil) send_data("USERS #{target}".strip) end |
#version(target = nil) ⇒ Object
Get server version
187 188 189 |
# File 'lib/em-irc/commands.rb', line 187 def version(target = nil) send_data("VERSION #{target}".strip) end |
#wallops(message) ⇒ Object Also known as: broadcast
Broadcast to all logged in users
339 340 341 |
# File 'lib/em-irc/commands.rb', line 339 def wallops() send_data("WALLOPS :#{}") end |
#who(mask, mode = 'o') ⇒ Object
Get info about a user
248 249 250 |
# File 'lib/em-irc/commands.rb', line 248 def who(mask, mode = 'o') send_data("WHO #{mask} #{mode}") end |
#whois(*args) ⇒ Object
Get user information about a list of users
256 257 258 259 260 |
# File 'lib/em-irc/commands.rb', line 256 def whois(*args) = args. target = [:target] ? "#{[:target]} " : '' send_data("WHOIS #{target}#{args.join(',')}") end |
#whowas(*args) ⇒ Object
Get user information that no longer exists (nick changed, etc)
272 273 274 275 |
# File 'lib/em-irc/commands.rb', line 272 def whowas(*args) = args. send_data("WHOWAS #{args.join(',')} #{[:count]} #{[:target]}".strip) end |