muzang 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,48 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ #.DS_Store
31
+
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+
36
+ # For emacs:
37
+ #*~
38
+ #\#*
39
+ #.\#*
40
+
41
+ # For vim:
42
+ #*.swp
43
+
44
+ # For redcar:
45
+ #.redcar
46
+
47
+ # For rubinius:
48
+ #*.rbc
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - ruby-head
4
+ - jruby
5
+ - rbx
6
+ - rbx-2.0
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "em-ventually", "~> 0.1.2"
7
+ gem "rspec", "~> 2.6.0"
8
+ gem "jeweler", "~> 1.6.3"
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ muzang (0.0.1)
5
+ coffeemaker (~> 0.0.1.beta.3)
6
+ em-http-request (~> 0.3.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activesupport (3.1.1)
12
+ multi_json (~> 1.0)
13
+ addressable (2.2.6)
14
+ callsite (0.0.11)
15
+ coffeemaker (0.0.1.beta.3)
16
+ activesupport
17
+ eventmachine (~> 1.0.0.beta.3)
18
+ diff-lcs (1.1.3)
19
+ em-http-request (0.3.0)
20
+ addressable (>= 2.0.0)
21
+ escape_utils
22
+ eventmachine (>= 0.12.9)
23
+ em-ventually (0.1.2)
24
+ callsite (~> 0.0.5)
25
+ eventmachine
26
+ escape_utils (0.2.4)
27
+ eventmachine (1.0.0.beta.4)
28
+ git (1.2.5)
29
+ jeweler (1.6.4)
30
+ bundler (~> 1.0)
31
+ git (>= 1.2.5)
32
+ rake
33
+ multi_json (1.0.3)
34
+ rake (0.9.2.2)
35
+ rspec (2.6.0)
36
+ rspec-core (~> 2.6.0)
37
+ rspec-expectations (~> 2.6.0)
38
+ rspec-mocks (~> 2.6.0)
39
+ rspec-core (2.6.4)
40
+ rspec-expectations (2.6.0)
41
+ diff-lcs (~> 1.1.2)
42
+ rspec-mocks (2.6.0)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ em-ventually (~> 0.1.2)
49
+ jeweler (~> 1.6.3)
50
+ muzang!
51
+ rspec (~> 2.6.0)
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,61 @@
1
+ muzang
2
+ ========
3
+
4
+ IRC bot for #drug.pl channel
5
+
6
+ [![BuildStatus](http://travis-ci.org/LTe/muzang.png)](http://github.com/LTe/muzang)
7
+
8
+ Plugin
9
+ ======
10
+
11
+ ```ruby
12
+ class PluginName
13
+ def initialize(bot)
14
+ end
15
+
16
+ def call(connection, message)
17
+ end
18
+ end
19
+ ```
20
+
21
+ *connection* - you can use methods from Coffeemaker::Commands
22
+
23
+ message
24
+
25
+ ```ruby
26
+ # example message
27
+ {
28
+ :command => "PRIVMSG",
29
+ :user => "LTe",
30
+ :nick => "LTe",
31
+ :host => "localhost",
32
+ :message => "Hi there!",
33
+ :channel => "#test"
34
+ }
35
+ ```
36
+
37
+ After that just execute .register_plugin before bot start
38
+
39
+ ```ruby
40
+ @bot = Muzang::Bot.new
41
+ @bot.register_plugin(PluginName)
42
+ @bot.start
43
+ ```
44
+
45
+ Contributing to muzang
46
+ ========================
47
+
48
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
49
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
50
+ * Fork the project
51
+ * Start a feature/bugfix branch
52
+ * Commit and push until you are happy with your contribution
53
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
54
+ * 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.
55
+
56
+ Copyright
57
+ =========
58
+
59
+ Copyright (c) 2011 Piotr Niełacny. See LICENSE.txt for
60
+ further details.
61
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.rspec_opts = ['-fd -c']
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ task :default => :spec
data/lib/muzang.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'muzang/bot'
2
+ require 'muzang/helpers'
3
+ require 'muzang/version'
data/lib/muzang/bot.rb ADDED
@@ -0,0 +1,50 @@
1
+ require 'muzang'
2
+ require 'coffeemaker/bot'
3
+ require 'active_support/inflector/inflections'
4
+ require 'active_support/inflector/methods'
5
+
6
+ module Muzang
7
+ class Bot
8
+ attr_accessor :bot, :connection, :plugins, :channels
9
+
10
+ def initialize(options = {})
11
+ @options = default_options.merge(options)
12
+ @channels = @options.delete(:channels)
13
+ @plugins = {}
14
+ @bot = Coffeemaker::Bot.new(@options)
15
+
16
+ @bot.irc.tap do |connection|
17
+ connection.on_message = Proc.new do |m|
18
+ @plugins.each do |plugin, instance|
19
+ instance.call(connection, m) rescue nil
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ def start
26
+ @bot.start { |irc| @channels.each { |channel| irc.join(channel) } }
27
+ end
28
+
29
+ def register_plugin(plugin)
30
+ klass = case plugin
31
+ when Class
32
+ plugin
33
+ when String, Symbol
34
+ klass_name = ActiveSupport::Inflector.classify(plugin.to_s)
35
+ klass = ActiveSupport::Inflector.constantize(klass_name)
36
+ end
37
+ @plugins[klass] = klass.new(self)
38
+ end
39
+
40
+ private
41
+ def default_options
42
+ {
43
+ irc_host: 'localhost',
44
+ irc_port: 6667,
45
+ nick: 'DRUG-bot',
46
+ channels: ['#test']
47
+ }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,39 @@
1
+ module Muzang
2
+ module Plugin
3
+ module Helpers
4
+ DEFAULT_MATCH_OPTIONS = { position: 1 }
5
+
6
+ def on_channel?(message)
7
+ message.channel
8
+ end
9
+
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
13
+ end
14
+
15
+ def on_join?(connection, message)
16
+ message.command == :join && message.nick == connection.nick
17
+ end
18
+
19
+ def create_database(file, container, variable)
20
+ unless File.exist?(@config = ENV["HOME"] + "/.muzang")
21
+ FileUtils.mkdir @config
22
+ end
23
+
24
+ unless File.exist? @config + "/#{file}"
25
+ db = YAML.dump container
26
+ File.open(@config + "/#{file}", "w"){|f| f.write(db)}
27
+ end
28
+
29
+ send(:"#{variable}=", YAML.load(File.open(@config + "/#{file}", "r").read))
30
+
31
+ unless self.respond_to?(:save)
32
+ self.class.send(:define_method, :save) do
33
+ File.open(@config + "/#{file}", "w"){|f| f.write YAML.dump(send(variable))}
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Muzang
2
+ VERSION = "1.0.0"
3
+ end
data/muzang.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'muzang/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "muzang"
7
+ s.version = Muzang::VERSION
8
+ s.authors = ["Piotr Niełacny", "Paweł Pacana"]
9
+ s.email = ["piotr.nielacny@gmail.com", "pawel.pacana@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Dolnoslaska Ruby User Group IRC bot}
12
+ s.description = %q{IRC bot with easy plugin managment}
13
+
14
+ s.rubyforge_project = "muzang"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "em-http-request", "~> 0.3.0"
22
+ s.add_runtime_dependency "coffeemaker", "~> 0.0.1.beta.3"
23
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Muzang" do
4
+ before do
5
+ @muzang = Muzang::Bot.new
6
+ @muzang.bot.stub(:start) do
7
+ Class.new{attr_accessor :on_message}.new
8
+ end
9
+ end
10
+
11
+ it "should have empty plugins map" do
12
+ @muzang = Muzang::Bot.new
13
+ @muzang.plugins.should == {}
14
+ end
15
+
16
+ it "should register plugin" do
17
+ @muzang.register_plugin(DummyPlugin)
18
+ @muzang.plugins.has_key?(DummyPlugin).should be_true
19
+ @muzang.plugins[DummyPlugin].is_a?(DummyPlugin).should be_true
20
+ end
21
+
22
+ it "should create plugins proc" do
23
+ @muzang.start
24
+ @muzang.bot.irc.on_message.is_a?(Proc).should be_true
25
+ end
26
+
27
+ it "should execute call on plugin instance" do
28
+ @muzang.register_plugin(DummyPlugin)
29
+ @plugin_instance = @muzang.plugins[DummyPlugin]
30
+ @plugin_instance.should_receive(:call).once
31
+ @muzang.start
32
+ @muzang.bot.irc.on_message.call
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'muzang'
5
+ require 'em-ventually/rspec'
6
+ require 'ostruct'
7
+
8
+ # Requires supporting files with custom matchers and macros, etc,
9
+ # in ./support/ and its subdirectories.
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+ end
@@ -0,0 +1,15 @@
1
+ class ConnectionMock
2
+ attr_accessor :message_count, :messages, :options, :nick
3
+
4
+ def initialize(options = {})
5
+ @message_count = 0
6
+ options.each do |k, v|
7
+ send(:"#{k}=", v)
8
+ end
9
+ end
10
+
11
+ def msg(where, message)
12
+ @message_count += 1
13
+ (@messages ||= []) << message
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ class DummyPlugin
2
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: muzang
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Piotr Niełacny
9
+ - Paweł Pacana
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-11-15 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: em-http-request
17
+ requirement: &70093127265740 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 0.3.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70093127265740
26
+ - !ruby/object:Gem::Dependency
27
+ name: coffeemaker
28
+ requirement: &70093127264960 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.1.beta.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70093127264960
37
+ description: IRC bot with easy plugin managment
38
+ email:
39
+ - piotr.nielacny@gmail.com
40
+ - pawel.pacana@gmail.com
41
+ executables: []
42
+ extensions: []
43
+ extra_rdoc_files: []
44
+ files:
45
+ - .gitignore
46
+ - .travis.yml
47
+ - Gemfile
48
+ - Gemfile.lock
49
+ - LICENSE.txt
50
+ - README.md
51
+ - Rakefile
52
+ - lib/muzang.rb
53
+ - lib/muzang/bot.rb
54
+ - lib/muzang/helpers.rb
55
+ - lib/muzang/version.rb
56
+ - muzang.gemspec
57
+ - spec/muzang_spec.rb
58
+ - spec/spec_helper.rb
59
+ - spec/support/connection_mock.rb
60
+ - spec/support/dummy-plugin.rb
61
+ homepage: ''
62
+ licenses: []
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project: muzang
81
+ rubygems_version: 1.8.10
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Dolnoslaska Ruby User Group IRC bot
85
+ test_files: []