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.
@@ -1,19 +1,23 @@
1
1
  require "soup-client"
2
2
 
3
- class SoupIRC
4
- include Muzang::Plugins::Helpers
3
+ module Muzang
4
+ module Plugins
5
+ class SoupIRC
6
+ include Muzang::Plugins::Helpers
5
7
 
6
- def initialize(bot, soup)
7
- @bot = bot
8
- @soup = soup || File.open(ENV["HOME"] + "/.muzang/" + "soup").read.split(":") rescue nil
9
- end
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
- def call(connection, message)
12
- message.message.match(/^!soup (.*?)$/) do |m|
13
- soup = Soup::Client.new(@soup.first, @soup.last.chomp)
14
- soup.login
15
- soup.new_image(m[1])
16
- connection.msg(@bot.channels.first, "soup updated :) | http://#{@soup.first}.soup.io/")
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
@@ -1,5 +1,5 @@
1
1
  module Muzang
2
2
  module Plugins
3
- VERSION = "1.1.4"
3
+ VERSION = "1.1.5"
4
4
  end
5
5
  end
@@ -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 "muzang", "~> 1.0.0"
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"
@@ -1,23 +1,25 @@
1
1
  require 'spec_helper'
2
2
  require 'muzang-plugins/muzang-livereload'
3
3
 
4
- describe "LiveReload" do
5
- before(:each) do
6
- @bot = stub
7
- @livereload = LiveReload.new(@bot)
8
- @bot.stub(:plugins => { LiveReload => @livereload })
9
- @connection = stub(:msg => true)
10
- Kernel.stub(:load)
11
- @message = OpenStruct.new({:channel => "#test", :message => "!reload"})
12
- end
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
- it "should load plugins" do
15
- Kernel.should_receive(:load).with('muzang-plugins/muzang-livereload.rb')
16
- @livereload.call(@connection, @message)
17
- end
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
- it "should create new instance of plugin" do
20
- LiveReload.should_receive(:new).with(@bot)
21
- @livereload.call(@connection, @message)
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
@@ -1,43 +1,71 @@
1
1
  require 'spec_helper'
2
2
  require 'muzang-plugins/muzang-meme'
3
3
 
4
- describe "Meme" do
5
- before do
6
- @bot = stub(:channels => ["#test"])
7
- @meme = Meme.new(@bot)
8
- @connection = ConnectionMock.new
9
- @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"
10
- @file = File.expand_path("../support/responses/meme.response", __FILE__)
11
- EventMachine::MockHttpRequest.pass_through_requests = false
12
- EventMachine::MockHttpRequest.register_file(@url, :get, @file)
13
- EventMachine::MockHttpRequest.activate!
14
- @message = OpenStruct.new({:channel => "#test", :message => "meme", :nick => "LTe" })
15
- end
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
- it "should print pretty help" do
18
- EM.run do
19
- @meme.call(@connection, @message)
20
- eventually(true) do
21
- @connection.messages.include?("Type 'meme [name of meme] \"Text0\" \"Text1\"'") and
22
- @connection.messages.include?("Available memes: #{Meme::MEMES.keys.join(" ")}")
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
- it "should create meme and send message" do
28
- @message.message = "meme y_u_no? \"hi0\" \"hi1\""
29
- EM.run do
30
- @meme.call(@connection, @message)
31
- eventually(1) { @connection.message_count }
32
- eventually(true) { @connection.messages.include? "Meme: http://version1.api.memegenerator.net//cache/instances/400x/10/10725/10982714.jpg" }
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
- it "should not create meme" do
37
- @message.message = "meme asdkasdj \"hi0\" \"hi1\""
38
- EM.run do
39
- @meme.call(@connection, @message)
40
- eventually(0) { @connection.message_count }
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
@@ -1,18 +1,19 @@
1
1
  require 'spec_helper'
2
2
  require 'muzang-plugins/muzang-motd'
3
3
 
4
- describe "Motd" do
5
- before do
6
- @message = OpenStruct.new({ :command => :join, :channel => "#test", :nick => "DRUG-bot" })
7
- @bot = stub
8
- @motd = Motd.new(@bot)
9
- @bot.stub(:plugins => { Motd => @motd })
10
- @connection = stub(:msg => true, :nick => "DRUG-bot")
11
- end
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
- it "should send message after join to channel" do
14
- @connection.should_receive(:msg).with("#test", "Muzang | Version: #{Muzang::VERSION} | Plugins: *Motd* ")
15
- @motd.call(@connection, @message)
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
-
@@ -1,43 +1,45 @@
1
1
  require 'spec_helper'
2
2
  require 'muzang-plugins/muzang-eval'
3
3
 
4
- describe "Eval" do
5
- before(:each) do
6
- @bot = stub
7
- @eval = Eval.new(@bot)
8
- @connection = ConnectionMock.new
9
- @message = OpenStruct.new({ :channel => "#test", :message => "% 1 + 1", :nick => "LTe" })
10
- end
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
- it "should eval ruby code" do
13
- @message.message = "% 1 + 1"
14
- EM.run do
15
- @eval.call(@connection, @message)
16
- eventually(true) { @connection.messages.include? "2" }
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
- it "@codegram should give me a t-shirt" do
21
- @message.message = "% \"@codegram\""
22
- EM.run do
23
- @eval.call(@connection, @message)
24
- eventually(true) { @connection.messages.include? "@codegram" }
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
- it "should not eval system method" do
29
- @message.message = "% system('rm -rf /')"
30
- EM.run do
31
- @eval.call(@connection, @message)
32
- eventually(true) { @connection.messages.include? "Error: Insecure operation - system" }
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
- it "should not crash after raise Exception" do
37
- @message.message = "% raise Exception"
38
- EM.run do
39
- @eval.call(@connection, @message)
40
- eventually(true) { @connection.messages.include? "Error: Exception" }
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
@@ -2,74 +2,76 @@ require 'spec_helper'
2
2
  require 'muzang-plugins/muzang-nerdpursuit'
3
3
  require 'json'
4
4
 
5
- class NerdPursuit
6
- def current_question=(other)
7
- @current_question=other
8
- end
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
- it "should start quiz after !quiz message" do
26
- @nerdpursuit.call(@connection, @message)
27
- @nerdpursuit.quiz_time.should == true
11
+ def period(time)
12
+ time / 1000.0
13
+ end
28
14
  end
29
15
 
30
- it "should parse question and start quiz sequence" do
31
- EM.run do
32
- @nerdpursuit.call(@connection, @message)
33
- eventually(true) do
34
- @connection.messages.include? "Quiz time!" and
35
- @connection.messages.include? "Category: ruby" and
36
- @connection.messages.include? "Question: When Matz joined Heruku?" and
37
- @connection.messages.include? "Answer 1: 12th June 2008" and
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
- it "should find winner" do
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.call(@connection, @message_lte)
28
+ @nerdpursuit.quiz_time.should == true
29
+ end
51
30
 
52
- eventually(true) do
53
- @connection.messages.include? "The winner is... LTe" and
54
- @connection.messages.include? "Right answer: 3"
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
- it "should not allow for many answers" do
60
- EM.run do
61
- @nerdpursuit.call(@connection, @message)
62
- [1,2,3,4].each do |answer|
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
- @message.message = "3"; @message.nick = "PawelPacana"
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
- eventually(true) do
70
- @connection.messages.include? "Right answer: 3" and
71
- @connection.messages.include? "The winner is... PawelPacana" and
72
- !@connection.messages.include? "The winner is... LTe"
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