Module: Bender::Spunk

Defined in:
lib/spunk.rb

Overview

Helpers methods for working with Spunk

Author

Michael Heijmans ([email protected])

Copyright

Copyright © 2013-2015 Michael Heijmans

License

MIT

Class Method Summary collapse

Class Method Details

.connect!Object

Sets up and connects the IRC bot


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spunk.rb', line 13

def self.connect!
  begin
    Bender.bot = ::Spunk::Bot.new(Bender::Spunk.options_from_config)
    Bender.bot.connect
    Bender.bot.authenticate
    sleep 5
    Bender::Spunk.connect_to_default_rooms
    return Bender.bot
  rescue SpunkException::BotException
    Bender.log.fatal "Couldn't establish a connection to #{opts[:hostname]}:#{opts[:port]}"
    puts "Couldn't establish a connection to #{opts[:hostname]}:#{opts[:port]}"
    exit 1
  end
end

.connect_to_default_roomsObject

Connects to the default rooms in Bender::Config


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/spunk.rb', line 46

def self.connect_to_default_rooms
  c = Bender::Config.instance
  if c.bot
    c.log.info "Joining default rooms" unless c.irc_rooms.empty?

    c.irc_rooms.each { |room|
      room = '#' + room unless room.match(/^\#/)
      c.log.debug "  joining #{room}"
      c.bot.join_room room
    }
  else
    c.log.error "Cannot connect to rooms - No bot found!"
    return false
  end
  return true
end

.options_from_configObject

Generates the options hash from Bender::Config to pass to Spunk::Bot


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/spunk.rb', line 29

def self.options_from_config
  c = Bender::Config.instance

  { invite_ok:         c.irc_accept_invites,
    username:          c.username,
    fullname:          c.fullname,
    nickname:          c.nickname,
    nickserv_password: c.nickserv_password,
    hostname:          c.irc_server,
    port:              c.irc_port,
    token:             c.irc_token,
    ssl:               c.irc_use_ssl,
    logger:            c.log,
  }
end