Class: Muzang::Plugins::PlusOne
- Inherits:
-
Object
- Object
- Muzang::Plugins::PlusOne
- Includes:
- Helpers
- Defined in:
- lib/muzang-plugins/muzang-plusone.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#stats ⇒ Object
Returns the value of attribute stats.
Instance Method Summary collapse
- #call(connection, message) ⇒ Object
- #filter(plus_for, nick) ⇒ Object
-
#initialize(bot) ⇒ PlusOne
constructor
A new instance of PlusOne.
- #print ⇒ Object
Methods included from Helpers
#create_database, #match, #on_channel, #on_join
Constructor Details
#initialize(bot) ⇒ PlusOne
Returns a new instance of PlusOne.
11 12 13 14 |
# File 'lib/muzang-plugins/muzang-plusone.rb', line 11 def initialize(bot) @bot = bot create_database("stats.yml", Hash.new, :stats) end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/muzang-plugins/muzang-plusone.rb', line 9 def config @config end |
#stats ⇒ Object
Returns the value of attribute stats.
9 10 11 |
# File 'lib/muzang-plugins/muzang-plusone.rb', line 9 def stats @stats end |
Instance Method Details
#call(connection, message) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/muzang-plugins/muzang-plusone.rb', line 16 def call(connection, ) on_channel() do match(, /^([^\s]*) \+1/) do |plus_for| plus_for = plus_for[1] plus_for.gsub!(":","") if filter(plus_for, .nick) connection.msg(.channel, "#{.nick} write in PHP") and return end connection.msg(.channel, "#{.nick} gave +1 for *#{plus_for}*") @stats[plus_for] ||= 0 @stats[plus_for] += 1 save end match(, /^!stats$/) do connection.msg(.channel, print) end end end |
#filter(plus_for, nick) ⇒ Object
47 48 49 50 51 |
# File 'lib/muzang-plugins/muzang-plusone.rb', line 47 def filter(plus_for, nick) if plus_for == nick || @stats[nick] == nil return true end end |
#print ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/muzang-plugins/muzang-plusone.rb', line 37 def print = "" stat = @stats.sort_by { |points| -points[1] } stat.each do |s| << "*#{s[0]}* #{s[1]} | " if s[1] > 0 end end |