Module: Syndi::IRC::Std::Commands

Defined in:
lib/syndi/irc/std/commands.rb

Overview

A module which provides a number of methods for basic IRC commands, intended for inclusion in Syndi::IRC::Server.

Instance Method Summary collapse

Instance Method Details

#authenticate(method = :plain) ⇒ Object

Send initial AUTHENTICATE.



15
16
17
18
19
20
21
22
23
# File 'lib/syndi/irc/std/commands.rb', line 15

def authenticate method = :plain
  if method    == :plain
    snd 'AUTHENTICATE PLAIN'
    @supp.sasl_method = :plain
  elsif method == :dh_blowfish
    snd 'AUTHENTICATE DH-BLOWFISH'
    @supp.sasl_method = :dh_blowfish
  end
end

#cap_endObject

Send CAP END.



26
27
28
29
30
31
# File 'lib/syndi/irc/std/commands.rb', line 26

def cap_end
  # Stop any SASL-related timers
  @supp.sasl_id.each { |t| $m.clock.del t }
  # Send CAP END
  snd 'CAP END'
end

#disconnect(msg = 'Closing connection') ⇒ Object

Disconnect from the server.

Parameters:

  • msg (String) (defaults to: 'Closing connection')

    Reason for disconnect.



36
37
38
39
40
# File 'lib/syndi/irc/std/commands.rb', line 36

def disconnect msg = 'Closing connection'
  emit :irc, :disconnect, self, msg
  snd "QUIT :#{msg}"
  @socket = nil
end

#join(chan, key = nil) ⇒ Object

Join a channel on the server.

Parameters:

  • chan (String)

    Channel to join.

  • key (String) (defaults to: nil)

    Key to join, if necessary.



46
47
48
49
# File 'lib/syndi/irc/std/commands.rb', line 46

def join chan, key = nil
  snd "JOIN #{chan}#{key.nil? ? '' : key}"
  emit :irc, :send_join, self, chan, key
end

#nickname=(new) ⇒ Object

Note:

If the nickname is in use, the bot will append a hyphen and retry, repeating until success is achieved.

Send /NICK to change the bot's nickname on the server.

Parameters:

  • new (String)

    The new nickname.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/syndi/irc/std/commands.rb', line 57

def nickname= new

  if connected?
    @newnick = new
  else
    @nick = new
  end
      
  snd "NICK :#{new}"
  emit :irc, :send_nick, self, new
    
end

#pass(password) ⇒ Object

Supply server password.

Parameters:



73
# File 'lib/syndi/irc/std/commands.rb', line 73

def pass password; snd "PASS :#{password}"; end

#user(username, hostname = Socket.gethostname, server, realname) ⇒ Object

Send /USER.

Parameters:

  • username (String)

    The bot's username or ident.

  • hostname (String) (defaults to: Socket.gethostname)

    The bot's hostname.

  • server (String)

    Address of the remote server.

  • realname (String)

    The bot's real name or GECOS.



81
82
83
# File 'lib/syndi/irc/std/commands.rb', line 81

def user username, hostname=Socket.gethostname, server, realname
  snd "USER #{username} #{hostname} #{server} :#{realname}"
end

#whoObject

Request a /WHO on ourselves.



86
87
88
89
# File 'lib/syndi/irc/std/commands.rb', line 86

def who
  snd "WHO #@nick"
  emit :irc, :who_self, self
end