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,19 +1,23 @@
|
|
1
1
|
require "soup-client"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Muzang
|
4
|
+
module Plugins
|
5
|
+
class SoupIRC
|
6
|
+
include Muzang::Plugins::Helpers
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def initialize(bot, soup=nil)
|
9
|
+
@bot = bot
|
10
|
+
@soup = soup || File.open(ENV["HOME"] + "/.muzang/" + "soup").read.split(":") rescue nil
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def call(connection, message)
|
14
|
+
message.message.match(/^!soup (.*?)$/) do |m|
|
15
|
+
soup = Soup::Client.new(@soup.first, @soup.last.chomp)
|
16
|
+
soup.login
|
17
|
+
soup.new_image(m[1])
|
18
|
+
connection.msg(@bot.channels.first, "soup updated :) | http://#{@soup.first}.soup.io/")
|
19
|
+
end
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
data/muzang-plugins.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["piotr.nielacny@gmail.com"]
|
7
7
|
gem.description = %q{Plugins for Muzang IRC bot}
|
8
8
|
gem.summary = %q{Basic plugins for Muzang IRC bot}
|
9
|
-
gem.homepage = ""
|
9
|
+
gem.homepage = "https://github.com/LTe/muzang-plugins"
|
10
10
|
|
11
11
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
12
|
gem.files = `git ls-files`.split("\n")
|
@@ -15,10 +15,14 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Muzang::Plugins::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency "em-http-request"
|
19
|
-
gem.add_dependency "
|
18
|
+
gem.add_dependency "em-http-request", "0.3.0"
|
19
|
+
gem.add_dependency "eventmachine", "~> 1.0.0"
|
20
|
+
gem.add_dependency "muzang", "~> 1.1"
|
20
21
|
gem.add_dependency "memetron", "~> 0.1.1"
|
21
22
|
gem.add_dependency "soup-client"
|
23
|
+
gem.add_dependency "sqlite3"
|
24
|
+
gem.add_dependency "activerecord"
|
25
|
+
gem.add_dependency "pastie-api"
|
22
26
|
|
23
27
|
gem.add_development_dependency "em-ventually", "~> 0.1.2"
|
24
28
|
gem.add_development_dependency "rspec", "~> 2.6.0"
|
data/spec/livereload_spec.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'muzang-plugins/muzang-livereload'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
module Muzang::Plugins
|
5
|
+
describe "LiveReload" do
|
6
|
+
before(:each) do
|
7
|
+
@bot = stub
|
8
|
+
@livereload = LiveReload.new(@bot)
|
9
|
+
@bot.stub(:plugins => { LiveReload => @livereload })
|
10
|
+
@connection = stub(:msg => true)
|
11
|
+
Kernel.stub(:load)
|
12
|
+
@message = OpenStruct.new({:channel => "#test", :message => "!reload"})
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
it "should load plugins" do
|
16
|
+
Kernel.should_receive(:load).with('muzang-plugins/muzang-livereload.rb')
|
17
|
+
@livereload.call(@connection, @message)
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
it "should create new instance of plugin" do
|
21
|
+
LiveReload.should_receive(:new).with(@bot)
|
22
|
+
@livereload.call(@connection, @message)
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
data/spec/meme_spec.rb
CHANGED
@@ -1,43 +1,71 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'muzang-plugins/muzang-meme'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
module Muzang::Plugins
|
5
|
+
URL = "http://version1.api.memegenerator.net:80/Instance_Create?username=drug-bot&password=drug-bot&languageCode=en&generatorID=2&imageID=166088&text0=hi0&text1=hi1"
|
6
|
+
|
7
|
+
describe "Meme" do
|
8
|
+
let(:bot) { stub(:channels => ["#test"]) }
|
9
|
+
let(:meme) { Meme.new(bot) }
|
10
|
+
let(:connection) { ConnectionMock.new }
|
11
|
+
let(:url) { URL }
|
12
|
+
let(:file) { File.expand_path("../support/responses/meme.response", __FILE__) }
|
13
|
+
let(:message) { OpenStruct.new({:channel => "#test", :message => "meme", :nick => "LTe" }) }
|
14
|
+
|
15
|
+
before do
|
16
|
+
EventMachine::MockHttpRequest.pass_through_requests = false
|
17
|
+
EventMachine::MockHttpRequest.register_file(url, :get, file)
|
18
|
+
EventMachine::MockHttpRequest.activate!
|
19
|
+
end
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
it "should print pretty help" do
|
22
|
+
EM.run do
|
23
|
+
meme.call(connection, message)
|
24
|
+
eventually(true) do
|
25
|
+
connection.messages.include?("Type 'meme [name of meme] \"Text0\" \"Text1\"'") and
|
26
|
+
connection.messages.include?("Available memes: #{Meme::MEMES.keys.join(" ")}")
|
27
|
+
end
|
23
28
|
end
|
24
29
|
end
|
25
|
-
end
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
it "should create meme and send message" do
|
32
|
+
message.message = "meme y_u_no? \"hi0\" \"hi1\""
|
33
|
+
EM.run do
|
34
|
+
meme.call(connection, message)
|
35
|
+
eventually(1) { connection.message_count }
|
36
|
+
eventually(true) { connection.messages.include? "Meme: http://version1.api.memegenerator.net//cache/instances/400x/10/10725/10982714.jpg" }
|
37
|
+
end
|
33
38
|
end
|
34
|
-
end
|
35
39
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
it "should not create meme" do
|
41
|
+
message.message = "meme asdkasdj \"hi0\" \"hi1\""
|
42
|
+
EM.run do
|
43
|
+
meme.call(connection, message)
|
44
|
+
eventually(0) { connection.message_count }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
context "meme recognize" do
|
50
|
+
before { meme.stub(:create_instance) }
|
51
|
+
|
52
|
+
it "should recognize dos_equis meme" do
|
53
|
+
message.message = "I don't always create spec but when I do I do it with rspec"
|
54
|
+
EM.run do
|
55
|
+
meme.call(connection, message)
|
56
|
+
eventually(true) { meme.instance_variable_get(:@text0).should == "I don't always create spec" }
|
57
|
+
eventually(true) { meme.instance_variable_get(:@text0).should == "but when I do I do it with rspec" }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should recognize yuno meme" do
|
62
|
+
message.message = "LTe Y U NO create specs for it?"
|
63
|
+
EM.run do
|
64
|
+
meme.call(connection, message)
|
65
|
+
eventually(true) { meme.instance_variable_get(:@text0).should == "LTe Y U NO" }
|
66
|
+
eventually(true) { meme.instance_variable_get(:@text1).should == "create specs for it?" }
|
67
|
+
end
|
68
|
+
end
|
41
69
|
end
|
42
70
|
end
|
43
71
|
end
|
data/spec/motd_spec.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'muzang-plugins/muzang-motd'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
module Muzang::Plugins
|
5
|
+
describe "Motd" do
|
6
|
+
before do
|
7
|
+
@message = OpenStruct.new({ :command => :join, :channel => "#test", :nick => "DRUG-bot" })
|
8
|
+
@bot = stub
|
9
|
+
@motd = Motd.new(@bot)
|
10
|
+
@bot.stub(:plugins => { Motd => @motd })
|
11
|
+
@connection = stub(:msg => true, :nick => "DRUG-bot")
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
it "should send message after join to channel" do
|
15
|
+
@connection.should_receive(:msg).with("#test", "Muzang | Version: #{Muzang::VERSION} | Plugins: *Muzang::Plugins::Motd* ")
|
16
|
+
@motd.call(@connection, @message)
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
|
-
|
data/spec/muzang-eval_spec.rb
CHANGED
@@ -1,43 +1,45 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'muzang-plugins/muzang-eval'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module Muzang::Plugins
|
5
|
+
describe "Eval" do
|
6
|
+
before(:each) do
|
7
|
+
@bot = stub
|
8
|
+
@eval = Eval.new(@bot)
|
9
|
+
@connection = ConnectionMock.new
|
10
|
+
@message = OpenStruct.new({ :channel => "#test", :message => "% 1 + 1", :nick => "LTe" })
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
it "should eval ruby code" do
|
14
|
+
@message.message = "% 1 + 1"
|
15
|
+
EM.run do
|
16
|
+
@eval.call(@connection, @message)
|
17
|
+
eventually(true) { @connection.messages.include? "2" }
|
18
|
+
end
|
17
19
|
end
|
18
|
-
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
it "@codegram should give me a t-shirt" do
|
22
|
+
@message.message = "% \"@codegram\""
|
23
|
+
EM.run do
|
24
|
+
@eval.call(@connection, @message)
|
25
|
+
eventually(true) { @connection.messages.include? "@codegram" }
|
26
|
+
end
|
25
27
|
end
|
26
|
-
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
it "should not eval system method" do
|
30
|
+
@message.message = "% system('rm -rf /')"
|
31
|
+
EM.run do
|
32
|
+
@eval.call(@connection, @message)
|
33
|
+
eventually(true) { @connection.messages.include? "Error: Insecure operation - system" }
|
34
|
+
end
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
it "should not crash after raise Exception" do
|
38
|
+
@message.message = "% raise Exception"
|
39
|
+
EM.run do
|
40
|
+
@eval.call(@connection, @message)
|
41
|
+
eventually(true) { @connection.messages.include? "Error: Exception" }
|
42
|
+
end
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
data/spec/nerdpursuit_spec.rb
CHANGED
@@ -2,74 +2,76 @@ require 'spec_helper'
|
|
2
2
|
require 'muzang-plugins/muzang-nerdpursuit'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def period(time)
|
11
|
-
time / 1000.0
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "NerdPursuit" do
|
16
|
-
before(:each) do
|
17
|
-
@bot = stub
|
18
|
-
@nerdpursuit = NerdPursuit.new(@bot)
|
19
|
-
@connection = ConnectionMock.new
|
20
|
-
@cq = JSON.parse(File.open("#{File.expand_path("../../lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/matz.json", __FILE__)}").read)["question"]
|
21
|
-
@nerdpursuit.current_question = @cq
|
22
|
-
@message = OpenStruct.new({ :channel => "#test", :message => "!quiz", :nick => "LTe" })
|
23
|
-
end
|
5
|
+
module Muzang::Plugins
|
6
|
+
class NerdPursuit
|
7
|
+
def current_question=(other)
|
8
|
+
@current_question=other
|
9
|
+
end
|
24
10
|
|
25
|
-
|
26
|
-
|
27
|
-
|
11
|
+
def period(time)
|
12
|
+
time / 1000.0
|
13
|
+
end
|
28
14
|
end
|
29
15
|
|
30
|
-
|
31
|
-
|
32
|
-
@
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@connection.messages.include? "Answer 2: 12th July 2011" and
|
39
|
-
@connection.messages.include? "Answer 3: 12th June 2011" and
|
40
|
-
@connection.messages.include? "Answer 4: 12th June 2010"
|
41
|
-
end
|
16
|
+
describe "NerdPursuit" do
|
17
|
+
before(:each) do
|
18
|
+
@bot = stub
|
19
|
+
@nerdpursuit = NerdPursuit.new(@bot)
|
20
|
+
@connection = ConnectionMock.new
|
21
|
+
@cq = JSON.parse(File.open("#{File.expand_path("../../lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/matz.json", __FILE__)}").read)["question"]
|
22
|
+
@nerdpursuit.current_question = @cq
|
23
|
+
@message = OpenStruct.new({ :channel => "#test", :message => "!quiz", :nick => "LTe" })
|
42
24
|
end
|
43
|
-
end
|
44
25
|
|
45
|
-
|
46
|
-
EM.run do
|
47
|
-
@message_lte = @message.dup
|
48
|
-
@message_lte.message = "3"
|
26
|
+
it "should start quiz after !quiz message" do
|
49
27
|
@nerdpursuit.call(@connection, @message)
|
50
|
-
@nerdpursuit.
|
28
|
+
@nerdpursuit.quiz_time.should == true
|
29
|
+
end
|
51
30
|
|
52
|
-
|
53
|
-
|
54
|
-
@connection
|
31
|
+
it "should parse question and start quiz sequence" do
|
32
|
+
EM.run do
|
33
|
+
@nerdpursuit.call(@connection, @message)
|
34
|
+
eventually(true) do
|
35
|
+
@connection.messages.include? "Quiz time!" and
|
36
|
+
@connection.messages.include? "Category: ruby" and
|
37
|
+
@connection.messages.include? "Question: When Matz joined Heruku?" and
|
38
|
+
@connection.messages.include? "Answer 1: 12th June 2008" and
|
39
|
+
@connection.messages.include? "Answer 2: 12th July 2011" and
|
40
|
+
@connection.messages.include? "Answer 3: 12th June 2011" and
|
41
|
+
@connection.messages.include? "Answer 4: 12th June 2010"
|
42
|
+
end
|
55
43
|
end
|
56
44
|
end
|
57
|
-
end
|
58
45
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
@message.message = answer.to_s
|
46
|
+
it "should find winner" do
|
47
|
+
EM.run do
|
48
|
+
@message_lte = @message.dup
|
49
|
+
@message_lte.message = "3"
|
64
50
|
@nerdpursuit.call(@connection, @message)
|
51
|
+
@nerdpursuit.call(@connection, @message_lte)
|
52
|
+
|
53
|
+
eventually(true) do
|
54
|
+
@connection.messages.include? "The winner is... LTe" and
|
55
|
+
@connection.messages.include? "Right answer: 3"
|
56
|
+
end
|
65
57
|
end
|
66
|
-
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should not allow for many answers" do
|
61
|
+
EM.run do
|
67
62
|
@nerdpursuit.call(@connection, @message)
|
63
|
+
[1,2,3,4].each do |answer|
|
64
|
+
@message.message = answer.to_s
|
65
|
+
@nerdpursuit.call(@connection, @message)
|
66
|
+
end
|
67
|
+
@message.message = "3"; @message.nick = "PawelPacana"
|
68
|
+
@nerdpursuit.call(@connection, @message)
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
eventually(true) do
|
71
|
+
@connection.messages.include? "Right answer: 3" and
|
72
|
+
@connection.messages.include? "The winner is... PawelPacana" and
|
73
|
+
!@connection.messages.include? "The winner is... LTe"
|
74
|
+
end
|
73
75
|
end
|
74
76
|
end
|
75
77
|
end
|