Advertisement
Guest User

Cinch statistics

a guest
Nov 24th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.64 KB | None | 0 0
  1. class Statistics
  2.     include Cinch::Plugin
  3.     listen_to :channel
  4.     match /stats (.+)/
  5.  
  6.     def initialize(*args)
  7.         super
  8.     end
  9.  
  10.     def listen(m)
  11.         if User.find_by_nick(m.user.nick).nil?
  12.             User.create(nick: m.user.nick, word_count: m.message.scan(/[\w-]+/).size)
  13.         else
  14.             user = User.find_by_nick(m.user.nick)
  15.             user.word_count = user.word_count + m.message.scan(/[\w-]+/).size
  16.             user.save
  17.         end
  18.                
  19.     end
  20.  
  21.     def execute(m, nick)
  22.         user = User.find_by_nick(nick)
  23.         if user.nil?
  24.             m.reply "Käyttäjää #{nick} ei löytynyt,,,"
  25.         else
  26.             m.reply "Käyttäjä #{nick} postannut #{user.word_count} kaunista sanaa"
  27.         end
  28.            
  29.     end
  30.  
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement