class Cinch::Plugins::EnCinch

Constants

VERSION

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/cinch/plugins/encinch/encinch.rb, line 7
def initialize(*)
  super
  config[:uncrypted] ||= Array.new
  config[:ignore]    ||= Array.new
  config[:encrypt]   ||= Hash.new

  shared[:encinch] = EnCinch::Storage.new(bot, config.dup)
end

Public Instance Methods

blowfish(key) click to toggle source
# File lib/cinch/plugins/encinch/encinch.rb, line 65
def blowfish(key)
  @fish = Encryption.new(key)
end
capture(m, message) click to toggle source
# File lib/cinch/plugins/encinch/encinch.rb, line 22
def capture(m, message)
  target = (m.channel? ? m.channel.name : m.user.nick).downcase

  options = shared[:encinch].storage.data

  return if options[:ignore].include?(target)
  return unless key = options[:encrypt][target] || options[:encrypt][:default]

  blowfish(key)

  message = strip(message)
  decrypted = decrypt(message)

  @fish = nil

  decrypted << '\u0001' if m.action?
  raw = modify_raw(m.raw, decrypted)

  dispatch(Message.new(raw, m.bot))
end
decrypt(message) click to toggle source
# File lib/cinch/plugins/encinch/encinch.rb, line 61
def decrypt(message)
  @fish.decrypt(message)
end
encrypt(message) click to toggle source
# File lib/cinch/plugins/encinch/encinch.rb, line 57
def encrypt(message)
  @fish.encrypt(message)
end
encrypted?(data) click to toggle source
# File lib/cinch/plugins/encinch/encinch.rb, line 69
def encrypted?(data)
  !!data.match(/\+OK \S+/)
end
key_exchange(m, key, cbc = false) click to toggle source
# File lib/cinch/plugins/encinch/encinch.rb, line 49
def key_exchange(m, key, cbc = false)
  return if m.channel?

  debug "captured key exchange event with key: #{m.message}"

  #TODO -- everything
end

Private Instance Methods

dispatch(msg) click to toggle source
# File lib/cinch/plugins/encinch/encinch.rb, line 74
def dispatch(msg)
  events = [[:catchall]]

  if ["PRIVMSG", "NOTICE"].include?(msg.command)
    events << [:ctcp] if msg.ctcp?

    if msg.channel?
      events << [:channel]
    else
      events << [:private]
    end

    if msg.command == "PRIVMSG"
      events << [:message]
    end

    if msg.action?
      events << [:action]
    end
  end

  meth = "on_#{msg.command.downcase}"
  __send__(meth, msg, events) if respond_to?(meth, true)

  events << [:error] if msg.error?

  events << [msg.command.downcase.intern]

  msg.events = events

  #if its still encrypted for whatever reason we will not be processing it again
  msg.events.each do |event, *args|
    msg.bot.handlers.dispatch(event, msg, *args)
  end unless encrypted?(msg.raw)
end
modify_raw(data, decrypted) click to toggle source

replace the encrypted message with the decrypted

# File lib/cinch/plugins/encinch/encinch.rb, line 118
def modify_raw(data, decrypted)
  data.sub(/\+OK \S+(\s+\S+)?/, decrypted)
end
strip(data) click to toggle source
# File lib/cinch/plugins/encinch/encinch.rb, line 110
def strip(data)
  data.sub(/\u0001$/, '')
end