class Lita::Adapters::IRC
Attributes
cinch[R]
Public Class Methods
new(robot)
click to toggle source
Calls superclass method
# File lib/lita/adapters/irc.rb, line 26 def initialize(robot) super @cinch = Cinch::Bot.new configure_cinch configure_logging register_plugin end
Public Instance Methods
join(room_id)
click to toggle source
# File lib/lita/adapters/irc.rb, line 40 def join(room_id) cinch.join(room_id) end
part(room_id)
click to toggle source
# File lib/lita/adapters/irc.rb, line 44 def part(room_id) cinch.part(room_id) end
run()
click to toggle source
# File lib/lita/adapters/irc.rb, line 35 def run Lita.logger.info("Connecting to IRC.") cinch.start end
send_messages(target, strings)
click to toggle source
# File lib/lita/adapters/irc.rb, line 48 def send_messages(target, strings) if target.private_message? send_messages_to_user(target, strings) else send_messages_to_channel(target, strings) end end
set_topic(target, topic)
click to toggle source
# File lib/lita/adapters/irc.rb, line 56 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_down()
click to toggle source
# File lib/lita/adapters/irc.rb, line 63 def shut_down Lita.logger.info("Disconnecting from IRC.") cinch.quit robot.trigger(:disconnected) end
Private Instance Methods
channels()
click to toggle source
# File lib/lita/adapters/irc.rb, line 71 def channels Array(robot.config.adapters.irc.channels) end
configure_cinch()
click to toggle source
# File lib/lita/adapters/irc.rb, line 75 def configure_cinch Lita.logger.debug("Configuring Cinch.") cinch.configure do |cinch_config| config.cinch.call(cinch_config) if config.cinch cinch_config.channels = channels cinch_config.server = config.server cinch_config.nick = robot.config.robot.name cinch_config.user = config.user if config.user cinch_config.password = config.password if config.password cinch_config.realname = config.realname if config.realname end end
configure_logging()
click to toggle source
# File lib/lita/adapters/irc.rb, line 91 def configure_logging if config.log_level cinch.loggers.level = config.log_level else cinch.loggers.clear end end
register_plugin()
click to toggle source
# File lib/lita/adapters/irc.rb, line 99 def register_plugin cinch.configure do |cinch_config| cinch_config.plugins.prefix = nil cinch_config.plugins.plugins ||= [] cinch_config.plugins.plugins += [CinchPlugin] cinch_config.plugins.options[CinchPlugin] = { robot: robot } end end
send_message_to_target(target, string)
click to toggle source
# File lib/lita/adapters/irc.rb, line 108 def send_message_to_target(target, string) string_without_action = string.gsub(/^\/me\s+/i, "") if string == string_without_action target.send(string) else target.action(string_without_action) end end
send_messages_to_channel(target, strings)
click to toggle source
# File lib/lita/adapters/irc.rb, line 118 def send_messages_to_channel(target, strings) channel = Cinch::Channel.new(target.room, cinch) strings.each { |string| send_message_to_target(channel, string) } end
send_messages_to_user(target, strings)
click to toggle source
# File lib/lita/adapters/irc.rb, line 123 def send_messages_to_user(target, strings) user = Cinch::User.new(target.user.name, cinch) strings.each { |string| send_message_to_target(user, string) } end