muzang-plugins 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - ruby-head
5
+
6
+ env:
7
+ - JRUBY_OPTS="--1.9"
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Piotr Niełacny
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,148 @@
1
+ muzang-plugins
2
+ ==============
3
+
4
+ Official plugins for [muzang](http://github.com/LTe/muzang)
5
+
6
+ [![BuildStatus](http://travis-ci.org/LTe/muzang-plugins.png)](http://github.com/LTe/muzang-plugins)
7
+
8
+ Helpers
9
+ =======
10
+
11
+ You can use helpers. Just include module.
12
+
13
+ ```ruby
14
+ class PluginClass
15
+ include Muzang::Plugins::Helpers
16
+ end
17
+ ```
18
+
19
+ After that you can use methods **on_channel**, **on_join**, **match**.
20
+
21
+ * on_join(connnection, message)
22
+ * on_channel(message)
23
+ * match(message, regexp)
24
+
25
+ ```ruby
26
+ class PluginsClass
27
+ include Muzang::Plugins::Helpers
28
+
29
+ def initialize(bot)
30
+ @bot = bot
31
+ end
32
+
33
+ def call(connnection, message)
34
+ on_join(connnection, message) do
35
+ connnection.msg(message.channel, "Hello guys!")
36
+ end
37
+
38
+ on_channel(message) do
39
+ connnection.msg(message.channel, "Pong: #{message.message}")
40
+
41
+ match(message, /^bot/) do |match|
42
+ contributed.msg(message.channel, "Match! #{match[0]}"
43
+ end
44
+ end
45
+ end
46
+ ```
47
+
48
+
49
+ Plugins
50
+ =======
51
+
52
+ ## Eval
53
+ Eval ruby code directly on IRC channel (with safe mode)
54
+
55
+ ```
56
+ <LTe> % 2+2
57
+ <Muzang> 4
58
+ ```
59
+
60
+ ## LiveReload
61
+ Reload plugins without reset bot
62
+
63
+ ```
64
+ <LTe> !reload
65
+ <Muzang> Reloading: PluginClass
66
+ ```
67
+
68
+ ## Meme
69
+ Create meme from IRC channel
70
+
71
+ ```
72
+ <LTe> meme
73
+ <Muzang> Type 'meme [name of meme] "Text0" "Text1"'
74
+ <Muzang> Available memes: idont yuno orly suc all
75
+ <LTe> meme yuno "Y U no" "Something"
76
+ <Muzang> http://memegenerator/image/directly/link
77
+ ```
78
+
79
+ ## Motd
80
+ Send message on join
81
+
82
+ ```
83
+ * muzangs has joined to #test
84
+ <Muzang> Muzang | Version: 1.0.1 | Plugins: *Motd*
85
+ ```
86
+
87
+ ## Nerdpursuit
88
+ Frontend for [nerdpursuit](https://github.com/Nerds/NerdPursuit)
89
+
90
+ ```
91
+ <LTe> !quiz
92
+ <Muzang> Quiz time!
93
+ <Muzang> Category: css
94
+ <Muzang> Question: What is the hexadecimal code for red?
95
+ <Muzang> Answer 1: ff0000
96
+ <Muzang> Answer 2: 00ff00
97
+ <Muzang> Answer 3: 0000ff
98
+ <Muzang> Answer 4: f0000f
99
+ <LTe> 1
100
+ <Muzang> Right answer: 1
101
+ <Muzang> The winner is... LTe
102
+ ```
103
+
104
+ ## Plusone
105
+ Fight for +1 on the channel
106
+
107
+ ```
108
+ <LTe> other_user: +1 for something
109
+ <Muzang> LTe gave +1 for *other_user*
110
+ <LTe> !stats
111
+ <Muzang> *LTe* 5 | *other_user* 1
112
+ ```
113
+
114
+ ## Reddit
115
+ Fetch rss for ruby stuff and print to channel
116
+
117
+ ```
118
+ <Muzang> GemStats.org - help the community by sharing your gem data | http://www.reddit.com/r/ruby/comments/kt7sq/gemstatsorg_help_the_community_by_sharing_your/
119
+ ```
120
+
121
+ ## RubyGems
122
+ Watch the gems and notify when new version comes out
123
+
124
+ ```
125
+ <LTe> watch! rails
126
+ <Muzang> I added gem rails to the observed
127
+ <Muzang> Current version: 3.1.1
128
+ ...
129
+ <Muzang> New version of rails (4.0.0)
130
+ ````
131
+
132
+ Contributing to muzang-plugins
133
+ ==============================
134
+
135
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
136
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
137
+ * Fork the project
138
+ * Start a feature/bugfix branch
139
+ * Commit and push until you are happy with your contribution
140
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
141
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
142
+
143
+ Copyright
144
+ =========
145
+
146
+ Copyright (c) 2011 Piotr Niełacny. See LICENSE.txt for
147
+ further details.
148
+
@@ -1,11 +1,11 @@
1
1
  require 'muzang-plugins/version'
2
2
  require 'muzang-plugins/helpers'
3
3
 
4
- autoload :Eval, 'muzang-plugins/muzang-eval'
5
- autoload :LiveReload, 'muzang-plugins/muzang-livereload'
6
- autoload :Meme, 'muzang-plugins/muzang-meme'
7
- autoload :Motd, 'muzang-plugins/muzang-motd'
8
- autoload :NerdPursuit, 'muzang-plugins/muzang-nerdpursuit'
9
- autoload :PlusOne, 'muzang-plugins/muzang-plusone'
10
- autoload :Reddit, 'muzang-plugins/muzang-reddit'
11
- autoload :RubyGems, 'muzang-plugins/muzang-rubygems'
4
+ require 'muzang-plugins/muzang-eval'
5
+ require 'muzang-plugins/muzang-livereload'
6
+ require 'muzang-plugins/muzang-meme'
7
+ require 'muzang-plugins/muzang-motd'
8
+ require 'muzang-plugins/muzang-nerdpursuit'
9
+ require 'muzang-plugins/muzang-plusone'
10
+ require 'muzang-plugins/muzang-reddit'
11
+ require 'muzang-plugins/muzang-rubygems'
@@ -1,19 +1,20 @@
1
1
  module Muzang
2
2
  module Plugins
3
3
  module Helpers
4
- DEFAULT_MATCH_OPTIONS = { position: 1 }
5
-
6
- def on_channel?(message)
7
- message.channel
4
+ def on_channel(message)
5
+ yield message.channel if message.channel
8
6
  end
9
7
 
10
- def match?(message, options = {})
11
- options = DEFAULT_MATCH_OPTIONS.merge(options)
12
- message.message.match(options[:regexp]) ? message.message.match(options[:regexp])[options[:position]] : false
8
+ def match(message, regexp)
9
+ message.message.match(regexp) do |match|
10
+ yield match
11
+ end
13
12
  end
14
13
 
15
- def on_join?(connection, message)
16
- message.command == :join && message.nick == connection.nick
14
+ def on_join(connection, message)
15
+ if message.command == :join && message.nick == connection.nick
16
+ yield
17
+ end
17
18
  end
18
19
 
19
20
  def create_database(file, container, variable)
@@ -36,4 +37,4 @@ module Muzang
36
37
  end
37
38
  end
38
39
  end
39
- end
40
+ end
@@ -33,10 +33,10 @@ class Eval
33
33
  end
34
34
 
35
35
  def call(connection, message)
36
- if on_channel?(message)
37
- if match?(message, :regexp => /^\% (.*)/, :position => 1)
36
+ on_channel(message) do
37
+ match(message, /^\% (.*)/) do |match|
38
38
  operation = proc do
39
- safe(message.message.match(/^\% (.*)/)[1])
39
+ safe(match[1])
40
40
  end
41
41
  callback = proc do |tuple|
42
42
  result, error = tuple
@@ -6,8 +6,8 @@ class LiveReload
6
6
  end
7
7
 
8
8
  def call(connection, message)
9
- if on_channel?(message)
10
- if match?(message, :regexp => /^!reload$/, :position => 0)
9
+ on_channel(message) do
10
+ match(message, /^!reload$/) do
11
11
  @bot.plugins.each do |plugin, instance|
12
12
  Kernel.load("muzang-plugins/muzang-#{plugin.to_s.downcase}.rb")
13
13
  instance = plugin.new(@bot)
@@ -8,8 +8,8 @@ class Motd
8
8
  end
9
9
 
10
10
  def call(connection, message)
11
- if on_join?(connection, message)
12
- connection.msg(message.channel, "DRUG-bot | Version: #{Muzang::VERSION} | Plugins: #{plugins}")
11
+ on_join(connection, message) do
12
+ connection.msg(message.channel, "Muzang | Version: #{Muzang::VERSION} | Plugins: #{plugins}")
13
13
  end
14
14
  end
15
15
 
@@ -62,8 +62,8 @@ class NerdPursuit
62
62
  end
63
63
 
64
64
  def call(connection, message)
65
- if on_channel?(message)
66
- if match?(message, :regexp => /^!quiz$/, :position => 0)
65
+ on_channel(message) do
66
+ match(message, /^!quiz$/) do
67
67
  quiz!
68
68
  connection.msg(message.channel, "Quiz time!")
69
69
  EM.add_timer(period(1)) { connection.msg(message.channel, "Category: #{current_question["category"]}") }
@@ -83,7 +83,8 @@ class NerdPursuit
83
83
  end
84
84
  end
85
85
 
86
- if(answer = match?(message, :regexp => /\d/, :position => 0))
86
+ match(message, /\d/) do |match|
87
+ answer = match[0]
87
88
  if @quiz_time
88
89
  unless @answers[message.nick]
89
90
  @answers[message.nick] = { :answer => answer, :time => Time.now }
@@ -12,8 +12,9 @@ class PlusOne
12
12
  end
13
13
 
14
14
  def call(connection, message)
15
- if on_channel?(message)
16
- if (plus_for = match?(message, :regexp => /^([^\s]*) \+1/, :position => 1))
15
+ on_channel(message) do
16
+ match(message, /^([^\s]*) \+1/) do |plus_for|
17
+ plus_for = plus_for[1]
17
18
  plus_for.gsub!(":","")
18
19
  if filter(plus_for, message.nick)
19
20
  connection.msg(message.channel, "#{message.nick} pisze w PHP") and return
@@ -25,7 +26,7 @@ class PlusOne
25
26
  save
26
27
  end
27
28
 
28
- if match?(message, :regexp => /^!stats$/, :position => 0)
29
+ match(message, /^!stats$/) do
29
30
  connection.msg(message.channel, print)
30
31
  end
31
32
  end
@@ -12,14 +12,10 @@ class Reddit
12
12
  end
13
13
 
14
14
  def call(connection, message)
15
- if on_join?(connection, message)
15
+ on_join(connection, message) do
16
16
  EventMachine::add_periodic_timer(period) do
17
17
  http = EventMachine::HttpRequest.new('http://www.reddit.com/r/ruby/.rss').get
18
18
 
19
- http.errback {
20
- # exceptioner
21
- }
22
-
23
19
  http.callback {
24
20
  rss = RSS::Parser.parse(http.response, false)
25
21
  rss.items.each do |item|
@@ -16,7 +16,7 @@ class RubyGems
16
16
  end
17
17
 
18
18
  def call(connection, message)
19
- message.message.match(/^watch! (.*?)$/) do |match|
19
+ match(message, /^watch! (.*?)$/) do |match|
20
20
  @current_gem = match[1]
21
21
 
22
22
  @store.transaction do
@@ -47,7 +47,7 @@ class RubyGems
47
47
  end
48
48
  end
49
49
 
50
- if on_join?(connection, message)
50
+ on_join(connection, message) do
51
51
  EventMachine.add_periodic_timer(period) do
52
52
  gems = @store.transaction{@store[:gems].values}
53
53
  EM::Iterator.new(gems, 1).each do |gem, iter|
@@ -1,5 +1,5 @@
1
1
  module Muzang
2
2
  module Plugins
3
- VERSION = "1.0.2"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -20,4 +20,5 @@ Gem::Specification.new do |gem|
20
20
 
21
21
  gem.add_development_dependency "em-ventually", "~> 0.1.2"
22
22
  gem.add_development_dependency "rspec", "~> 2.6.0"
23
+ gem.add_development_dependency "rake"
23
24
  end
data/spec/motd_spec.rb CHANGED
@@ -11,7 +11,7 @@ describe "Motd" do
11
11
  end
12
12
 
13
13
  it "should send message after join to channel" do
14
- @connection.should_receive(:msg).with("#test", "DRUG-bot | Version: #{Muzang::VERSION} | Plugins: *Motd* ")
14
+ @connection.should_receive(:msg).with("#test", "Muzang | Version: #{Muzang::VERSION} | Plugins: *Motd* ")
15
15
  @motd.call(@connection, @message)
16
16
  end
17
17
  end
data/spec/reddit_spec.rb CHANGED
@@ -28,10 +28,10 @@ describe "Reddit" do
28
28
  end
29
29
 
30
30
  it "should print only one message" do
31
- @reddit.last_update = Time.new(2011, 9, 29, 0, 47, 0)
31
+ @reddit.last_update = (DateTime.parse "Thu, 29 Sep 2011 00:47:00 +0200").to_time
32
32
  EM.run do
33
33
  @reddit.call(@connection, @message)
34
- eventually(1) { @connection.message_count }
34
+ eventually(1, :every => 0.1, :total => 20) { @connection.message_count }
35
35
  end
36
36
  end
37
37
 
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.0.2
4
+ version: 1.1.0
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: 2011-11-20 00:00:00.000000000Z
12
+ date: 2012-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: em-http-request
16
- requirement: &70039033906260 !ruby/object:Gem::Requirement
16
+ requirement: &11784540 !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: *70039033906260
24
+ version_requirements: *11784540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: muzang
27
- requirement: &70039033905340 !ruby/object:Gem::Requirement
27
+ requirement: &11782320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70039033905340
35
+ version_requirements: *11782320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: em-ventually
38
- requirement: &70039033904440 !ruby/object:Gem::Requirement
38
+ requirement: &11781020 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.1.2
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70039033904440
46
+ version_requirements: *11781020
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70039033903200 !ruby/object:Gem::Requirement
49
+ requirement: &11794360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,18 @@ dependencies:
54
54
  version: 2.6.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70039033903200
57
+ version_requirements: *11794360
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: &11791580 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *11791580
58
69
  description: Plugins for Muzang IRC bot
59
70
  email:
60
71
  - piotr.nielacny@gmail.com
@@ -63,7 +74,10 @@ extensions: []
63
74
  extra_rdoc_files: []
64
75
  files:
65
76
  - .gitignore
77
+ - .travis.yml
66
78
  - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
67
81
  - Rakefile
68
82
  - lib/muzang-plugins.rb
69
83
  - lib/muzang-plugins/helpers.rb