Sha256: dcdcb3b18cbe8512b0d077956d13566d7775d3f645a1420b32cf2ef8a459c0c7

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

require 'fileutils'
require 'yaml'

class PlusOne
  include Muzang::Plugins::Helpers

  attr_accessor :config, :stats

  def initialize(bot)
    @bot = bot
    create_database("stats.yml", Hash.new, :stats)
  end

  def call(connection, message)
    if on_channel?(message)
      if (plus_for = match?(message, :regexp => /^([^\s]*) \+1/, :position => 1))
        plus_for.gsub!(":","")
        if filter(plus_for, message.nick)
          connection.msg(message.channel, "#{message.nick} pisze w PHP") and return
        end

        connection.msg(message.channel, "#{message.nick} podarowal +1 dla *#{plus_for}*")
        @stats[plus_for] ||= 0
        @stats[plus_for]  += 1
        save
      end

      if match?(message, :regexp => /^!stats$/, :position => 0)
        connection.msg(message.channel, print)
      end
    end
  end

  def print
    message = ""
    stat = @stats.sort_by { |points| -points[1] }
    stat.each do |s|
      message << "*#{s[0]}* #{s[1]} | " if s[1] > 0
    end

    message
  end

  def filter(plus_for, nick)
    if plus_for == nick || @stats[nick] == nil
      return true
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
muzang-plugins-1.0.2 lib/muzang-plugins/muzang-plusone.rb
muzang-plugins-1.0.1 lib/muzang-plugins/muzang-plusone.rb
muzang-plugins-1.0.0 lib/muzang-plugins/muzang-plusone.rb