Sha256: 1dc74e69734ff41c3e82bb316777dfcf939d307f343cb4a91cf608e5f4f4c3ef

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

require 'cinch/plugins/octospy/recording'
require 'cinch/plugins/octospy/job'

module Cinch
  module Plugins
    class Octospy
      include Cinch::Plugin
      include Octospy::Recording
      include Octospy::Job

      set :prefix, ->(m) { %r(^ ?#{Regexp.escape "#{m.bot.nick}"}:? ) }

      match(/hello|hi|hey/, method: :greet)
      match('ping', method: :pong)
      match('rename', method: :rename)
      match(/join (.+)/, method: :join)
      match(/part(?: (.+))?/, method: :part)
      match(/show status/, method: :show_status)
      match(/show commands|help/, method: :show_commands)

      listen_to :invite, method: :join_on_invite

      def greet(m)
        m.reply "hi #{m.user.nick}"
      end

      def pong(m)
        m.reply "#{m.user.nick}: pong"
      end

      def rename(m)
        @bot.nick += '_'
      end

      def join(m, channel)
        ch = "##{channel.gsub('#', '')}"
        Channel(ch).join
        m.reply "#{ch} joined!"
      end

      def part(m, channel)
        channel ||= m.channel
        if channel
          ch = "##{channel.gsub('#', '')}"
          Channel(ch).part
          m.reply "#{ch} parted!" unless ch == m.channel
        end
      end

      def show_status(m)
        @bot.channels.each.with_index(1) do |channel, i|
          number = ::Octospy::Recordable.channel(channel).repos.count
          m.reply "#{"%02d" % i} #{channel}: #{number} repo#{'s' unless number.zero?}"
        end
      end

      def show_commands(m)
        m.reply "#{m.bot.name}:"
        @handlers.each do |handler|
          pattern = handler.pattern.pattern
          command = case pattern.class.name
            when 'Regexp' then pattern.source unless pattern.source == ''
            when 'String' then pattern unless pattern.empty?
            end
          m.reply " #{command}" if command
        end
      end

      def join_on_invite(m)
        Channel(m.channel).join
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
octospy-0.2.0 lib/cinch/plugins/octospy.rb
octospy-0.1.1 lib/cinch/plugins/octospy.rb
octospy-0.1.0 lib/cinch/plugins/octospy.rb