cinchize 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. data/.gitignore +1 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +54 -0
  4. data/Rakefile +23 -0
  5. data/VERSION +1 -0
  6. data/bin/cinchize +7 -0
  7. data/lib/cinchize.rb +95 -0
  8. metadata +109 -0
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Victor Bergöö
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.rdoc ADDED
@@ -0,0 +1,54 @@
1
+ = cinchize
2
+
3
+ An early version of program which purpose is to daemonize Cinch ircbots from "simple" json config-files.
4
+
5
+ == Usage
6
+
7
+ Basic
8
+
9
+ cinchize start -- server
10
+
11
+ Specify a config file, if no file is specified the cinchize is looking for it in /etc/cinchize.json
12
+
13
+ cinchize start -- -f config.json server
14
+
15
+ Server is the name you call the a server config in the servers part of the config file, i.e. "freenode", "my_cute_bot", "quakenet" or similar.
16
+
17
+ == Config-file
18
+
19
+ All config options can be skipped and the bot will use the defaults, but it could always be nice to connect to a server that isn't localhost, right? Plugins can be skipped too, but then the bot wouldn't do anything other then just idle.
20
+
21
+ {
22
+ "options" : {
23
+ "dir" : "/path/to/pid/dir",
24
+ "dir_mode" : "normal",
25
+ "log_output" : true
26
+ },
27
+ "servers" : {
28
+ "freenode" : {
29
+ "server" : "irc.freenode.net",
30
+ "port" : 6667,
31
+ "nick" : "Cinchbot",
32
+ "channels" : ["#cinchbots"],
33
+ "plugins" : [
34
+ {
35
+ "module" : "plugin-module",
36
+ "class" : "Cinch::Plugins::User::SomePlugin",
37
+ "options" : { }
38
+ }
39
+ ]
40
+ }
41
+ }
42
+ }
43
+
44
+ === Options explained
45
+
46
+ dir: the save path, absolute or relative to either /var/run or to the current working directory
47
+
48
+ dir_mode: "system" to work from /var/run and "normal", to work from current working directory or from an absolute path
49
+
50
+ log_output: writes STDERR and STDOUT to a logfile in the same dir as the pid-file
51
+
52
+ == Copyright
53
+
54
+ Copyright (c) 2010 Victor Bergöö. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "cinchize"
10
+ gem.summary = %Q{Create dynamic Cinch IRC-bots and daemonize them}
11
+ gem.description = %Q{Create dynamic Cinch IRC-bots and daemonize them, without the need of writing any code}
12
+ gem.email = "victor.bergoo@gmail.com"
13
+ gem.homepage = "http://github.com/netfeed/cinchize"
14
+ gem.authors = ["Victor Bergöö"]
15
+ gem.add_dependency "cinch"
16
+ gem.add_dependency "daemons"
17
+ gem.add_dependency "json"
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/cinchize ADDED
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (c) 2010 Victor Bergöö
3
+ # This program is made available under the terms of the MIT License.
4
+
5
+ require File.expand_path('../../lib/cinchize', __FILE__)
6
+
7
+ Cinchize.run
data/lib/cinchize.rb ADDED
@@ -0,0 +1,95 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (c) 2010 Victor Bergöö
3
+ # This program is made available under the terms of the MIT License.
4
+
5
+ dir = File.dirname(__FILE__)
6
+ $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include? dir
7
+
8
+ require 'cinch'
9
+ require 'daemons'
10
+ require 'json'
11
+
12
+ module Cinchize
13
+ def self.run
14
+ daemon_options, ntw, plugins, plugin_options = config
15
+ Daemons.run_proc(daemon_options[:app_name], daemon_options) do
16
+ bot = Cinch::Bot.new do
17
+ configure do |c|
18
+ ntw.keys.each do |key|
19
+ c.send("#{key}=".to_sym, ntw[key])
20
+ end
21
+
22
+ c.plugins.plugins = plugins
23
+ c.plugins.options = plugin_options
24
+ end
25
+ end
26
+
27
+ bot.start
28
+ end
29
+ rescue ArgumentError => e
30
+ puts "Error: #{e}"
31
+ exit 1
32
+ end
33
+
34
+ def self.config
35
+ cmd_options = []
36
+
37
+ idx = ARGV.index "--"
38
+ unless idx.nil?
39
+ cmd_options = ARGV.dup.slice(idx+1..-1)
40
+ end
41
+
42
+ config_file = "/etc/cinchize.json"
43
+ unless cmd_options.index("-f").nil?
44
+ config_file = cmd_options[cmd_options.index("-f") + 1]
45
+ end
46
+
47
+ raise ArgumentError.new "the config file doesn't exist" unless File.exists? config_file
48
+ raise ArgumentError.new "needs a network" if cmd_options[-1].nil?
49
+
50
+ network = cmd_options[-1]
51
+
52
+ cfg = JSON.parse File.open(config_file, "r").read()
53
+
54
+ raise ArgumentError.new "there's no server config in the config file" unless cfg.has_key? "servers"
55
+ raise ArgumentError.new "the config file doesn't contain a config for #{network}" unless cfg["servers"].has_key? network
56
+
57
+ ntw = cfg["servers"][network]
58
+
59
+ plugins = []
60
+ plugin_options = {}
61
+
62
+ ntw.delete("plugins").each do |plugin|
63
+ begin
64
+ raise LoadError.new "the module can't be null" if plugin["module"].nil?
65
+ raise NameError.new "the class can't be null" if plugin["class"].nil?
66
+
67
+ require plugin["module"]
68
+
69
+ clazz = nil
70
+ plugin["class"].split("::").inject(Object) { |m,n| clazz = m.const_get(n) }
71
+ plugins << clazz
72
+
73
+ plugin_options[plugin["class"]] = plugin["options"] || {}
74
+ rescue LoadError => e
75
+ puts "error while loading the module: #{e}"
76
+ rescue NameError => e
77
+ puts "error while loading the class: #{e}"
78
+ end
79
+ end
80
+
81
+ raise ArgumentError.new "no plugins loaded" if plugins.size == 0
82
+
83
+ dir_mode = cfg["options"]["dir_mode"].nil? ? "normal" : cfg["options"]["dir_mode"]
84
+
85
+ cfg["options"] ||= {}
86
+ daemon_options = {
87
+ :dir_mode => dir_mode.to_sym,
88
+ :dir => cfg["options"]["dir"] || Dir.getwd,
89
+ :log_output => cfg["options"]["log_output"] || false,
90
+ :app_name => "cinchize_#{network}"
91
+ }
92
+
93
+ [daemon_options, ntw, plugins, plugin_options]
94
+ end
95
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinchize
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - "Victor Berg\xC3\xB6\xC3\xB6"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-24 00:00:00 +02:00
18
+ default_executable: cinchize
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: cinch
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: daemons
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :runtime
58
+ version_requirements: *id003
59
+ description: Create dynamic Cinch IRC-bots and daemonize them, without the need of writing any code
60
+ email: victor.bergoo@gmail.com
61
+ executables:
62
+ - cinchize
63
+ extensions: []
64
+
65
+ extra_rdoc_files:
66
+ - LICENSE
67
+ - README.rdoc
68
+ files:
69
+ - .gitignore
70
+ - LICENSE
71
+ - README.rdoc
72
+ - Rakefile
73
+ - VERSION
74
+ - bin/cinchize
75
+ - lib/cinchize.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/netfeed/cinchize
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --charset=UTF-8
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirements: []
102
+
103
+ rubyforge_project:
104
+ rubygems_version: 1.3.7
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Create dynamic Cinch IRC-bots and daemonize them
108
+ test_files: []
109
+