Sha256: a4ba5d9dda7dc48027ded4772e83436f9c433a79be88a8944e25418ebc8eb9df

Contents?: true

Size: 1.63 KB

Versions: 7

Compression:

Stored size: 1.63 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/, 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"
        end
      end

      def show_commands(m)
        # @matchers.each.with_index(1) do |matcher, i|
          # m.reply "#{"%02d" % i} #{matcher}"
        # end
      end

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
octospy-0.0.8 lib/cinch/plugins/octospy.rb
octospy-0.0.7 lib/cinch/plugins/octospy.rb
octospy-0.0.6 lib/cinch/plugins/octospy.rb
octospy-0.0.5 lib/cinch/plugins/octospy.rb
octospy-0.0.4 lib/cinch/plugins/octospy.rb
octospy-0.0.3 lib/cinch/plugins/octospy.rb
octospy-0.0.2 lib/cinch/plugins/octospy.rb