Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Statistics
- include Cinch::Plugin
- listen_to :channel
- match /stats (.+)/
- def initialize(*args)
- super
- end
- def listen(m)
- synchronize(:listen) do
- if User.find_by_nick(m.user.nick).nil?
- User.create(nick: m.user.nick, word_count: m.message.scan(/[\w-]+/).size)
- else
- user = User.find_by_nick(m.user.nick)
- user.word_count = user.word_count + m.message.scan(/[\w-]+/).size
- user.save
- end
- end
- end
- def execute(m, nick)
- synchronize(:execute) do
- user = User.find_by_nick(nick)
- if user.nil?
- m.reply "Käyttäjää #{nick} ei löytynyt,,,"
- else
- m.reply "Käyttäjä #{nick} postannut #{user.word_count} kaunista sanaa"
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement