muzang-plugins 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/muzang-plugins.rb +2 -0
- data/lib/muzang-plugins/.muzang-rubygems.rb.swp +0 -0
- data/lib/muzang-plugins/muzang-eval.rb +46 -41
- data/lib/muzang-plugins/muzang-google.rb +24 -0
- data/lib/muzang-plugins/muzang-grep.rb +107 -0
- data/lib/muzang-plugins/muzang-grep/wrttn_in.rb +28 -0
- data/lib/muzang-plugins/muzang-livereload.rb +16 -12
- data/lib/muzang-plugins/muzang-meme.rb +95 -84
- data/lib/muzang-plugins/muzang-motd.rb +18 -14
- data/lib/muzang-plugins/muzang-nerdpursuit.rb +79 -75
- data/lib/muzang-plugins/muzang-plusone.rb +40 -36
- data/lib/muzang-plugins/muzang-reddit.rb +29 -25
- data/lib/muzang-plugins/muzang-rubygems.rb +73 -55
- data/lib/muzang-plugins/muzang-soupirc.rb +16 -12
- data/lib/muzang-plugins/version.rb +1 -1
- data/muzang-plugins.gemspec +7 -3
- data/spec/livereload_spec.rb +18 -16
- data/spec/meme_spec.rb +59 -31
- data/spec/motd_spec.rb +13 -12
- data/spec/muzang-eval_spec.rb +32 -30
- data/spec/nerdpursuit_spec.rb +56 -54
- data/spec/plusone_spec.rb +43 -41
- data/spec/reddit_spec.rb +34 -32
- data/spec/rubygems_spec.rb +90 -60
- data/spec/soupirc_spec.rb +16 -14
- metadata +125 -27
@@ -1,21 +1,25 @@
|
|
1
1
|
require 'muzang/version'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Muzang
|
4
|
+
module Plugins
|
5
|
+
class Motd
|
6
|
+
include Muzang::Plugins::Helpers
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
def initialize(bot)
|
9
|
+
@bot = bot
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def call(connection, message)
|
13
|
+
on_join(connection, message) do
|
14
|
+
connection.msg(message.channel, "Muzang | Version: #{Muzang::VERSION} | Plugins: #{plugins}")
|
15
|
+
end
|
16
|
+
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def plugins
|
19
|
+
list = ""
|
20
|
+
@bot.plugins.each{|plugin, instance| list << "*#{plugin}* "}
|
21
|
+
list
|
22
|
+
end
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
@@ -1,93 +1,97 @@
|
|
1
1
|
require "json"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Muzang
|
4
|
+
module Plugins
|
5
|
+
class NerdPursuit
|
6
|
+
include Muzang::Plugins::Helpers
|
5
7
|
|
6
|
-
|
8
|
+
attr_accessor :questions, :quiz_time
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def initialize(bot)
|
11
|
+
@bot = bot
|
12
|
+
@quiz_time = false
|
13
|
+
@answers = {}
|
14
|
+
create_database("nerd_pursuit.yml", Array.new, :questions)
|
15
|
+
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
def all_questions
|
18
|
+
names = Dir["#{File.dirname(__FILE__)}/muzang-nerdpursuit/questions/**/*.json"]
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def quiz!(&block)
|
22
|
+
@quiz_time = true
|
23
|
+
current_question # load current question
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
def end_quiz!
|
27
|
+
@quiz_time = false
|
28
|
+
@current_question = nil
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
def current_question
|
32
|
+
if @current_question
|
33
|
+
@current_question
|
34
|
+
else
|
35
|
+
begin
|
36
|
+
sample_question = (all_questions - questions).sample
|
37
|
+
questions << sample_question
|
38
|
+
save
|
39
|
+
@current_question = ::JSON.parse(File.open(sample_question).read)["question"]
|
40
|
+
end while(!valid?(@current_question))
|
41
|
+
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
+
@current_question
|
44
|
+
end
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
def valid?(question)
|
47
|
+
if question
|
48
|
+
question["category"] and question["text"] and question["right_answer"]
|
49
|
+
else
|
50
|
+
false
|
51
|
+
end
|
52
|
+
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
def find_winner
|
55
|
+
@winner = @answers.reject do |_, answer|
|
56
|
+
answer[:answer] != current_question["right_answer"][1..1]
|
57
|
+
end.sort_by do |_,answer|
|
58
|
+
answer[:time]
|
59
|
+
end
|
60
|
+
end
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
62
|
+
def period(time)
|
63
|
+
time # need for speed up tests
|
64
|
+
end
|
63
65
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
66
|
+
def call(connection, message)
|
67
|
+
on_channel(message) do
|
68
|
+
match(message, /^!quiz$/) do
|
69
|
+
quiz!
|
70
|
+
connection.msg(message.channel, "Quiz time!")
|
71
|
+
EM.add_timer(period(1)) { connection.msg(message.channel, "Category: #{current_question["category"]}") }
|
72
|
+
EM.add_timer(period(2)) { connection.msg(message.channel, "Question: #{current_question["text"]}") }
|
73
|
+
4.times do |time|
|
74
|
+
EM.add_timer(period(2+time+1)) { connection.msg(message.channel, "Answer #{time+1}: #{current_question["a#{time+1}"]}") }
|
75
|
+
end
|
76
|
+
EM.add_timer(period(40)) do
|
77
|
+
connection.msg(message.channel, "Right answer: #{current_question["right_answer"][1..1]}")
|
78
|
+
@winner = find_winner
|
79
|
+
if @winner.first && @winner.first.first
|
80
|
+
connection.msg(message.channel, "The winner is... #{@winner.first.first}")
|
81
|
+
end
|
82
|
+
@answers = {}
|
83
|
+
@winner = nil
|
84
|
+
end_quiz!
|
85
|
+
end
|
79
86
|
end
|
80
|
-
@answers = {}
|
81
|
-
@winner = nil
|
82
|
-
end_quiz!
|
83
|
-
end
|
84
|
-
end
|
85
87
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
match(message, /\d/) do |match|
|
89
|
+
answer = match[0]
|
90
|
+
if @quiz_time
|
91
|
+
unless @answers[message.nick]
|
92
|
+
@answers[message.nick] = { :answer => answer, :time => Time.now }
|
93
|
+
end
|
94
|
+
end
|
91
95
|
end
|
92
96
|
end
|
93
97
|
end
|
@@ -1,50 +1,54 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'yaml'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module Muzang
|
5
|
+
module Plugins
|
6
|
+
class PlusOne
|
7
|
+
include Muzang::Plugins::Helpers
|
6
8
|
|
7
|
-
|
9
|
+
attr_accessor :config, :stats
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(connection, message)
|
15
|
-
on_channel(message) do
|
16
|
-
match(message, /^([^\s]*) \+1/) do |plus_for|
|
17
|
-
plus_for = plus_for[1]
|
18
|
-
plus_for.gsub!(":","")
|
19
|
-
if filter(plus_for, message.nick)
|
20
|
-
connection.msg(message.channel, "#{message.nick} write in PHP") and return
|
21
|
-
end
|
22
|
-
|
23
|
-
connection.msg(message.channel, "#{message.nick} gave +1 for *#{plus_for}*")
|
24
|
-
@stats[plus_for] ||= 0
|
25
|
-
@stats[plus_for] += 1
|
26
|
-
save
|
11
|
+
def initialize(bot)
|
12
|
+
@bot = bot
|
13
|
+
create_database("stats.yml", Hash.new, :stats)
|
27
14
|
end
|
28
15
|
|
29
|
-
|
30
|
-
|
16
|
+
def call(connection, message)
|
17
|
+
on_channel(message) do
|
18
|
+
match(message, /^([^\s]*) \+1/) do |plus_for|
|
19
|
+
plus_for = plus_for[1]
|
20
|
+
plus_for.gsub!(":","")
|
21
|
+
if filter(plus_for, message.nick)
|
22
|
+
connection.msg(message.channel, "#{message.nick} write in PHP") and return
|
23
|
+
end
|
24
|
+
|
25
|
+
connection.msg(message.channel, "#{message.nick} gave +1 for *#{plus_for}*")
|
26
|
+
@stats[plus_for] ||= 0
|
27
|
+
@stats[plus_for] += 1
|
28
|
+
save
|
29
|
+
end
|
30
|
+
|
31
|
+
match(message, /^!stats$/) do
|
32
|
+
connection.msg(message.channel, print)
|
33
|
+
end
|
34
|
+
end
|
31
35
|
end
|
32
|
-
end
|
33
|
-
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
def print
|
38
|
+
message = ""
|
39
|
+
stat = @stats.sort_by { |points| -points[1] }
|
40
|
+
stat.each do |s|
|
41
|
+
message << "*#{s[0]}* #{s[1]} | " if s[1] > 0
|
42
|
+
end
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
+
message
|
45
|
+
end
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
def filter(plus_for, nick)
|
48
|
+
if plus_for == nick || @stats[nick] == nil
|
49
|
+
return true
|
50
|
+
end
|
51
|
+
end
|
48
52
|
end
|
49
53
|
end
|
50
54
|
end
|
@@ -2,37 +2,41 @@ require "em-http-request"
|
|
2
2
|
require "rss/1.0"
|
3
3
|
require "rss/2.0"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module Muzang
|
6
|
+
module Plugins
|
7
|
+
class Reddit
|
8
|
+
include Muzang::Plugins::Helpers
|
9
|
+
attr_accessor :last_update
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def initialize(bot)
|
12
|
+
@bot = bot
|
13
|
+
create_database("last_update.yml", Time.now, :last_update)
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def call(connection, message)
|
17
|
+
on_join(connection, message) do
|
18
|
+
EventMachine::add_periodic_timer(period) do
|
19
|
+
http = EventMachine::HttpRequest.new('http://www.reddit.com/r/ruby/.rss').get
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
http.callback {
|
22
|
+
rss = RSS::Parser.parse(http.response, false)
|
23
|
+
rss.items.each do |item|
|
24
|
+
connection.msg(message.channel, "#{item.title} | #{item.link}") if item.date > @last_update
|
25
|
+
end
|
26
|
+
save(rss)
|
27
|
+
}
|
23
28
|
end
|
24
|
-
|
25
|
-
}
|
29
|
+
end
|
26
30
|
end
|
27
|
-
end
|
28
|
-
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
def save(rss)
|
33
|
+
@last_update = rss.items.max_by{|i|i.date}.date
|
34
|
+
file = File.open(@config + "/last_update.yml", "w"){|f| f.write YAML::dump(@last_update)}
|
35
|
+
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
+
def period
|
38
|
+
30
|
39
|
+
end
|
40
|
+
end
|
37
41
|
end
|
38
42
|
end
|
@@ -2,75 +2,93 @@ require "em-http-request"
|
|
2
2
|
require "json"
|
3
3
|
require "pstore"
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
module Muzang
|
6
|
+
module Plugins
|
7
|
+
class RubyGems
|
8
|
+
include Muzang::Plugins::Helpers
|
7
9
|
|
8
|
-
|
10
|
+
attr_accessor :last_gem, :store
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def call(connection, message)
|
19
|
-
match(message, /^watch! (.*?)$/) do |match|
|
20
|
-
@current_gem = match[1]
|
21
|
-
|
22
|
-
@store.transaction do
|
23
|
-
unless @store[:gems][@current_gem]
|
24
|
-
@store[:gems][match[1]] = {:name => @current_gem}
|
25
|
-
@new_gem = true
|
12
|
+
def initialize(bot)
|
13
|
+
@bot = bot
|
14
|
+
@store = PStore.new("#{ENV["HOME"]}/.muzang/muzang.rubygems")
|
15
|
+
@store.transaction do
|
16
|
+
@store[:gems] ||= {}
|
26
17
|
end
|
27
18
|
end
|
28
19
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@store
|
35
|
-
@store[:gems][
|
20
|
+
def call(connection, message)
|
21
|
+
match(message, /^!watch (.*?)$/) do |match|
|
22
|
+
@current_gem = match[1]
|
23
|
+
|
24
|
+
@store.transaction do
|
25
|
+
unless @store[:gems][@current_gem]
|
26
|
+
@store[:gems][match[1]] = {:name => @current_gem}
|
27
|
+
@new_gem = true
|
36
28
|
end
|
37
|
-
connection.msg(message.channel, "I added gem #{@current_gem} to watchlist")
|
38
|
-
connection.msg(message.channel, "Current version: #{@current_gem} (#{gem["version"]})")
|
39
|
-
@new_gem = false
|
40
|
-
rescue Exception
|
41
|
-
connection.msg(message.channel, "Gem name is incorrect")
|
42
|
-
@store.transaction{@store[:gems].delete(@current_gem)}
|
43
29
|
end
|
44
|
-
}
|
45
|
-
else
|
46
|
-
connection.msg(message.channel, "Gem #{@current_gem} is already observed")
|
47
|
-
end
|
48
|
-
end
|
49
30
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
http.callback {
|
56
|
-
iter.next
|
57
|
-
begin
|
58
|
-
current_gem = JSON.parse(http.response)
|
59
|
-
if Gem::Version.new(gem[:version]) < Gem::Version.new(current_gem["version"])
|
31
|
+
if @new_gem
|
32
|
+
http = EventMachine::HttpRequest.new("http://rubygems.org/api/v1/gems/#{@current_gem}.json").get
|
33
|
+
http.callback {
|
34
|
+
begin
|
35
|
+
gem = JSON.parse(http.response)
|
60
36
|
@store.transaction do
|
61
|
-
@store[:gems][
|
37
|
+
@store[:gems][@current_gem][:version] = gem["version"]
|
62
38
|
end
|
63
|
-
connection.msg(message.channel, "
|
39
|
+
connection.msg(message.channel, "I added gem #{@current_gem} to watchlist")
|
40
|
+
connection.msg(message.channel, "Current version: #{@current_gem} (#{gem["version"]})")
|
41
|
+
@new_gem = false
|
42
|
+
rescue Exception
|
43
|
+
connection.msg(message.channel, "Gem name is incorrect")
|
44
|
+
@store.transaction{@store[:gems].delete(@current_gem)}
|
64
45
|
end
|
65
|
-
|
46
|
+
}
|
47
|
+
else
|
48
|
+
connection.msg(message.channel, "Gem #{@current_gem} is already observed")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
match(message, /^!unwatch (.*?)$/) do |match|
|
53
|
+
@store.transaction do
|
54
|
+
if @store[:gems].delete(match[1])
|
55
|
+
connection.msg(message.channel, "I removed gem #{match[1]} from watchlist")
|
66
56
|
end
|
67
|
-
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
match(message, /^!cojapacze$/) do
|
61
|
+
@store.transaction do
|
62
|
+
connection.msg(message.channel, "#{@store[:gems].keys.join(', ')}")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
on_join(connection, message) do
|
67
|
+
EventMachine.add_periodic_timer(period) do
|
68
|
+
gems = @store.transaction{@store[:gems].values}
|
69
|
+
EM::Iterator.new(gems, 1).each do |gem, iter|
|
70
|
+
http = EventMachine::HttpRequest.new("http://rubygems.org/api/v1/gems/#{gem[:name]}.json").get
|
71
|
+
http.callback {
|
72
|
+
iter.next
|
73
|
+
begin
|
74
|
+
current_gem = JSON.parse(http.response)
|
75
|
+
if Gem::Version.new(gem[:version]) < Gem::Version.new(current_gem["version"])
|
76
|
+
@store.transaction do
|
77
|
+
@store[:gems][gem[:name]][:version] = current_gem["version"]
|
78
|
+
end
|
79
|
+
connection.msg(message.channel, "New version #{gem[:name]} (#{current_gem["version"]})")
|
80
|
+
end
|
81
|
+
rescue
|
82
|
+
end
|
83
|
+
}
|
84
|
+
end
|
85
|
+
end
|
68
86
|
end
|
69
87
|
end
|
70
|
-
end
|
71
|
-
end
|
72
88
|
|
73
|
-
|
74
|
-
|
89
|
+
def period
|
90
|
+
30
|
91
|
+
end
|
92
|
+
end
|
75
93
|
end
|
76
94
|
end
|