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