-
Notifications
You must be signed in to change notification settings - Fork 2
/
word_count.rb
42 lines (37 loc) · 1.04 KB
/
word_count.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'yaml'
class WordCount < Citrus::Plugin
def initialize(*args)
super
@word_file = "word_count.yaml"
if File.exists?(@word_file)
@data = YAML.load_file(@word_file)
else
@data = {}
end
end
def on_privmsg(prefix, channel, message)
@config["replies"].each do |r|
if message =~ /(#{r["words"]})/ &&
(!r["channels"] || r["channels"].include?(channel))
@data[channel] = {} unless @data[channel]
@data["date"] = Date.today.to_s unless @data["date"]
if @data["date"] != Date.today.to_s
@data = {}
@data["date"] = Date.today.to_s
@data[channel] = {}
end
user = ""
if prefix =~ /!~(.+?)@/
user = $1
end
count = @data[channel][user].to_i || 0
count += 1
notice(channel, "もう#{user}のその発言#{count}回目だよ") if count > 3
@data[channel][user] = count
f = File.open(@word_file,'w+')
f.puts @data.to_yaml
f.close
end
end
end
end