Class: Cinch::IRC

Inherits:
Object
  • Object
show all
Defined in:
lib/cinch/plugins/encinch/extend.rb

Instance Method Summary collapse

Instance Method Details

#encinch_sendObject

alias instead of modify directly



6
# File 'lib/cinch/plugins/encinch/extend.rb', line 6

alias :encinch_send :send

#send(msg) ⇒ void

This method returns an undefined value.

Send a message to the server.

Parameters:

  • msg (String)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cinch/plugins/encinch/extend.rb', line 11

def send(msg)
  if msg.match(/(PRIVMSG|NOTICE)/) && !msg.match(/\+OK (\S+)/)
    _, _, target, message = *msg.match(/(\S+) (\S+) :(.*)/m)
    target.downcase!

    unless message.empty?
      # retrieve bot options
      options = @bot.config.shared[:encinch].storage.data

      # ignore if target is in the 'uncrypted' array
      unless options[:uncrypted].include?(target)

        # match ctcp? and action messages
        if matched = message.match(/\001ACTION\s(.+)\001/)
          message = matched[-1]
        elsif message =~ /\001.+\001/
          return encinch_send(msg)
        end

        # key exists
        if key = (options[:encrypt][target] || options[:encrypt][:default])

          encrypted = Cinch::Plugins::EnCinch::Encryption.new(key).encrypt(message)
          msg.sub!(message, encrypted)

        else
          return if options[:drop]
        end
      end
    end
  end

  encinch_send(msg)
end