Module: EventMachine::IRC::Commands

Included in:
Client
Defined in:
lib/em-irc/commands.rb

Overview

Client commands

See Also:

Instance Method Summary collapse

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

See Also:



303
304
305
# File 'lib/em-irc/commands.rb', line 303

def away(message = nil)
  send_data("AWAY" + (message ? ":#{message}" : ""))
end

#channel_modeObject

TODO:

name conflict with user MODE message

Set channel mode

Raises:

  • (NotImplementedError)


97
98
99
# File 'lib/em-irc/commands.rb', line 97

def channel_mode
  raise NotImplementedError.new
end

#dieObject

Shutdown server

See Also:



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(message)
  send_data("ERROR :#{message}")
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

Parameters:

  • nickname (String)

    to invite

  • channel (String)

    to invite to

See Also:



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

See Also:



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

Examples:

client.join("#general")
client.join("#general", "fubar")  # join #general with fubar key
client.join(['#general', 'fubar'], "#foo")  # join multiple channels

Raises:

  • (ArgumentError)

See Also:



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

Examples:

client.kick('#general', 'jch')
client.kick('#general', '&bar', 'jch', 'wcc')

Parameters:

  • args (Multiple)

Raises:

  • (ArgumentError)

See Also:



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

See Also:



279
280
281
# File 'lib/em-irc/commands.rb', line 279

def kill(nickname, comment = "Connection killed")
  send_data("KILL #{nickname} :#{comment}".strip)
end

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

Parameters:

  • args (Multiple)

    list of channels if last argument is a hash, then :target can request which server generates response

See Also:



127
128
129
130
# File 'lib/em-irc/commands.rb', line 127

def list(*args)
  options = args.extract_options!
  send_data("LIST #{args.join(',')} #{options[: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

Raises:

  • (NotImplementedError)

See Also:



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

Parameters:

  • target (String) (defaults to: nil)

    server name or current server if nil

See Also:



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

Parameters:

  • args (Multiple)

    list of channels to list nicks if last argument is a hash, then :target can request which server generates response

See Also:



117
118
119
120
# File 'lib/em-irc/commands.rb', line 117

def names(*args)
  options = args.extract_options!
  send_data("NAMES #{args.join(',')} #{options[:target]}".strip)
end

#nick(nick = nil) ⇒ String

Set/get user nick

Returns:

  • (String)

    nick if no param

  • nil otherwise

See Also:



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

Parameters:

  • target (String)

    nick or channel name

  • message (String)

See Also:



167
168
169
# File 'lib/em-irc/commands.rb', line 167

def notice(target, message)
  send_data("NOTICE #{target} :#{message}")
end

#oper(name, password) ⇒ Object

Gain operator privledges

See Also:



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

Examples:

client.part('#general')
client.part('#general', '#foo')
client.part('#general', 'Bye all!')
client.part('#general', '#foo', 'Bye all!')

Raises:

  • (ArgumentError)

See Also:



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
  message = channel?(args.last) ? "Leaving..." : args.pop
  send_data("PART #{args.join(',')} :#{message}")
end

#part_allObject

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

See Also:



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

See Also:



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

Parameters:

  • target (String)

    nick or channel name

  • message (String)

See Also:



158
159
160
# File 'lib/em-irc/commands.rb', line 158

def privmsg(target, message)
  send_data("PRIVMSG #{target} :#{message}")
end

#quit(message = 'leaving') ⇒ Object

Terminate connection

See Also:



49
50
51
# File 'lib/em-irc/commands.rb', line 49

def quit(message = 'leaving')
  send_data("QUIT :#{message}")
end

#rehashObject

Force user to re-read config

See Also:



309
310
311
# File 'lib/em-irc/commands.rb', line 309

def rehash
  send_data("REHASH")
end

#restartObject

Restart server

See Also:



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

Raises:

  • (NotImplementedError)

See Also:



55
56
57
# File 'lib/em-irc/commands.rb', line 55

def squit(server, message = "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

See Also:



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

See Also:



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

Parameters:

  • topic (Mixed)

    String, nil non-blank string sets the topic blank string unsets the topic nil returns the current topic (default)

See Also:



107
108
109
110
# File 'lib/em-irc/commands.rb', line 107

def topic(channel, message = nil)
  message = message.nil? ? "" : ":#{message}"
  send_data("TOPIC #{channel} #{message}".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

See Also:



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

Raises:

  • (ArgumentError)

See Also:



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

See Also:



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

Parameters:

  • target (String) (defaults to: nil)

    server or current server if nil

See Also:



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

See Also:



339
340
341
# File 'lib/em-irc/commands.rb', line 339

def wallops(message)
  send_data("WALLOPS :#{message}")
end

#who(mask, mode = 'o') ⇒ Object

Get info about a user

See Also:



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

Parameters:

  • args (Multiple)

    if last arg is a hash, :target specifies which server to query

See Also:



256
257
258
259
260
# File 'lib/em-irc/commands.rb', line 256

def whois(*args)
  options = args.extract_options!
  target = options[:target] ? "#{options[:target]} " : ''
  send_data("WHOIS #{target}#{args.join(',')}")
end

#whowas(*args) ⇒ Object

Get user information that no longer exists (nick changed, etc)

Examples:

client.whowas('jch')
client.whowas('jch', 'foo')
client.whowas('jch', 'foo', :count => 5, :target => 'irc.net')

Parameters:

  • args (Multiple)

    list of nicknames

  • options (Hash)

See Also:



272
273
274
275
# File 'lib/em-irc/commands.rb', line 272

def whowas(*args)
  options = args.extract_options!
  send_data("WHOWAS #{args.join(',')} #{options[:count]} #{options[:target]}".strip)
end