Class: Lita::Adapters::IRC

Inherits:
Adapter
  • Object
show all
Defined in:
lib/lita/adapters/irc.rb,
lib/lita/adapters/irc/cinch_plugin.rb

Defined Under Namespace

Classes: CinchPlugin

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(robot) ⇒ IRC

Returns a new instance of IRC.


13
14
15
16
17
18
19
20
21
# File 'lib/lita/adapters/irc.rb', line 13

def initialize(robot)
  super

  @cinch = Cinch::Bot.new
  normalize_config
  configure_cinch
  configure_logging
  register_plugin
end

Instance Attribute Details

#cinchObject (readonly)

Returns the value of attribute cinch


11
12
13
# File 'lib/lita/adapters/irc.rb', line 11

def cinch
  @cinch
end

Instance Method Details

#runObject


23
24
25
26
# File 'lib/lita/adapters/irc.rb', line 23

def run
  Lita.logger.info("Connecting to IRC.")
  cinch.start
end

#send_messages(target, strings) ⇒ Object


28
29
30
31
32
33
34
35
36
# File 'lib/lita/adapters/irc.rb', line 28

def send_messages(target, strings)
  if target.private_message?
    user = Cinch::User.new(target.user.name, cinch)
    strings.each { |s| user.msg(s) }
  else
    channel = Cinch::Channel.new(target.room, cinch)
    strings.each { |s| channel.msg(s) }
  end
end

#set_topic(target, topic) ⇒ Object


38
39
40
41
42
43
# File 'lib/lita/adapters/irc.rb', line 38

def set_topic(target, topic)
  room = target.room
  channel = Cinch::Channel.new(target.room, cinch)
  Lita.logger.debug("Setting topic for channel #{room}: #{topic}")
  channel.topic = topic
end

#shut_downObject


45
46
47
48
49
# File 'lib/lita/adapters/irc.rb', line 45

def shut_down
  Lita.logger.info("Disconnecting from IRC.")
  cinch.quit
  robot.trigger(:disconnected)
end