muzang-plugins 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -39,7 +39,7 @@ class PluginsClass
39
39
  connnection.msg(message.channel, "Pong: #{message.message}")
40
40
 
41
41
  match(message, /^bot/) do |match|
42
- contributed.msg(message.channel, "Match! #{match[0]}"
42
+ connnection.msg(message.channel, "Match! #{match[0]}"
43
43
  end
44
44
  end
45
45
  end
@@ -1,19 +1,24 @@
1
1
  require "em-http-request"
2
2
  require "json"
3
+ require "memetron"
3
4
 
4
5
  class Meme
5
6
  include Muzang::Plugins::Helpers
6
7
 
8
+
9
+
7
10
  MEMES = {
8
- "idont" => { :image_id => 2485, :generator => 74 },
9
- "yuno" => { :image_id => 166088, :generator => 2 },
10
- "orly" => { :image_id => 117049, :generator => 920 },
11
- "suc" => { :image_id => 1031, :generator => 121 },
12
- "all" => { :image_id => 1121885, :generator => 6013 }
11
+ dos_equis: { image_id: 2485, generator: 74 },
12
+ y_u_no?: { image_id: 166088, generator: 2 },
13
+ bear_grylls: { image_id: 89714, generator: 92 },
14
+ fry: { image_id: 84688, generator: 305 },
15
+ orly: { image_id: 117049, generator: 920 },
16
+ all: { image_id: 1121885, generator: 6013 }
13
17
  }
14
18
 
15
19
  def initialize(bot)
16
- @bot = bot
20
+ @bot = bot
21
+ @matcher = Memetron::Matcher.new
17
22
  end
18
23
 
19
24
  def call(connection, message)
@@ -22,7 +27,7 @@ class Meme
22
27
  connection.msg("#{@bot.channels.first}", "Available memes: #{MEMES.keys.join(" ")}")
23
28
  end
24
29
  message.message.match(/^meme (.*?) "(.*?)"( "(.*?)")?$/) do |m|
25
- if meme_ids = MEMES[m[1]]
30
+ if meme_ids = MEMES[m[1].to_sym]
26
31
  @generator = meme_ids[:generator]
27
32
  @image_id = meme_ids[:image_id]
28
33
  else
@@ -31,21 +36,57 @@ class Meme
31
36
 
32
37
  @text0 = m[2]
33
38
  @text1 = m[4]
34
-
35
- http = EventMachine::HttpRequest.new('http://version1.api.memegenerator.net/Instance_Create')
36
- .get(:query => {:username => 'drug-bot',
37
- :password => 'drug-bot',
38
- :languageCode => 'en',
39
- :generatorID => @generator,
40
- :imageID => @image_id,
41
- :text0 => @text0,
42
- :text1 => @text1})
43
-
44
- http.callback {
45
- meme = JSON.parse(http.response)
46
- url = "http://version1.api.memegenerator.net#{meme['result']['instanceImageUrl']}"
47
- connection.msg("#{@bot.channels.first}", "Meme: #{url}")
48
- }
39
+
40
+ create_instance(connection)
49
41
  end
42
+
43
+ on_channel(message) do
44
+ if meme = @matcher.match_and_parse(message.message)
45
+ @generator = MEMES[meme.first][:generator]
46
+ @image_id = MEMES[meme.first][:image_id]
47
+
48
+ case meme.first
49
+ when :dos_equis
50
+ @text0 = "I don't always #{meme[1][0]}"
51
+ @text1 = "but when I do #{meme[1][1]}"
52
+ when :y_u_no?
53
+ @text0 = "Y U NO"
54
+ @text1 = meme[1][1]
55
+ when :bear_grylls
56
+ @text0 = meme[1][0]
57
+ @text1 = "better drink my own piss"
58
+ when :fry
59
+ @text0 = "not sure if #{meme[1][1]}"
60
+ @text1 = "or #{meme[1][2]}"
61
+ when :orly
62
+ @text0 = meme[1][0]
63
+ @text1 = "ORLY?"
64
+ when :all
65
+ @text0 = meme[1][0]
66
+ @text1 = "all the things!"
67
+ else
68
+ @text0 = meme[1][0]
69
+ @text1 = meme[1][1]
70
+ end
71
+ create_instance(connection)
72
+ end
73
+ end
74
+ end
75
+
76
+ def create_instance(connection)
77
+ http = EventMachine::HttpRequest.new('http://version1.api.memegenerator.net/Instance_Create')
78
+ .get(:query => {:username => 'drug-bot',
79
+ :password => 'drug-bot',
80
+ :languageCode => 'en',
81
+ :generatorID => @generator,
82
+ :imageID => @image_id,
83
+ :text0 => @text0,
84
+ :text1 => @text1})
85
+
86
+ http.callback {
87
+ meme = JSON.parse(http.response)
88
+ url = "http://version1.api.memegenerator.net#{meme['result']['instanceImageUrl']}"
89
+ connection.msg("#{@bot.channels.first}", "Meme: #{url}")
90
+ }
50
91
  end
51
- end
92
+ end
@@ -1,5 +1,5 @@
1
1
  module Muzang
2
2
  module Plugins
3
- VERSION = "1.1.1"
3
+ VERSION = "1.1.2"
4
4
  end
5
5
  end
@@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency "em-http-request"
19
19
  gem.add_dependency "muzang", "~> 1.0.0"
20
+ gem.add_dependency "memetron", "~> 0.1.1"
20
21
 
21
22
  gem.add_development_dependency "em-ventually", "~> 0.1.2"
22
23
  gem.add_development_dependency "rspec", "~> 2.6.0"
data/spec/meme_spec.rb CHANGED
@@ -25,7 +25,7 @@ describe "Meme" do
25
25
  end
26
26
 
27
27
  it "should create meme and send message" do
28
- @message.message = "meme yuno \"hi0\" \"hi1\""
28
+ @message.message = "meme y_u_no? \"hi0\" \"hi1\""
29
29
  EM.run do
30
30
  @meme.call(@connection, @message)
31
31
  eventually(1) { @connection.message_count }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muzang-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-07 00:00:00.000000000 Z
12
+ date: 2012-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: em-http-request
16
- requirement: &17221340 !ruby/object:Gem::Requirement
16
+ requirement: &23409700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *17221340
24
+ version_requirements: *23409700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: muzang
27
- requirement: &17242620 !ruby/object:Gem::Requirement
27
+ requirement: &23409200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,21 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *17242620
35
+ version_requirements: *23409200
36
+ - !ruby/object:Gem::Dependency
37
+ name: memetron
38
+ requirement: &23425080 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.1.1
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *23425080
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: em-ventually
38
- requirement: &17240840 !ruby/object:Gem::Requirement
49
+ requirement: &23424620 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ~>
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: 0.1.2
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *17240840
57
+ version_requirements: *23424620
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rspec
49
- requirement: &17238980 !ruby/object:Gem::Requirement
60
+ requirement: &23424160 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ~>
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: 2.6.0
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *17238980
68
+ version_requirements: *23424160
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: rake
60
- requirement: &17238380 !ruby/object:Gem::Requirement
71
+ requirement: &23423780 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,7 +76,7 @@ dependencies:
65
76
  version: '0'
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *17238380
79
+ version_requirements: *23423780
69
80
  description: Plugins for Muzang IRC bot
70
81
  email:
71
82
  - piotr.nielacny@gmail.com
@@ -273,3 +284,4 @@ signing_key:
273
284
  specification_version: 3
274
285
  summary: Basic plugins for Muzang IRC bot
275
286
  test_files: []
287
+ has_rdoc: