kris 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kris.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 - 2013 Tomohiro TAIRA
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,120 @@
1
+ Kris
2
+ ================================================================================
3
+
4
+ IRC bot library - Pluggable, and very simple
5
+
6
+ [![Gem Version](https://badge.fury.io/rb/kris.png)](http://badge.fury.io/rb/kris)
7
+ [![Dependency Status](https://gemnasium.com/Tomohiro/kris.png)](https://gemnasium.com/Tomohiro/kris)
8
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/Tomohiro/kris)
9
+ [![endorse](http://api.coderwall.com/tomohiro/endorsecount.png)](http://coderwall.com/tomohiro)
10
+
11
+
12
+ ---
13
+
14
+
15
+ Requirements
16
+ --------------------------------------------------------------------------------
17
+
18
+ - Ruby 1.9.3 or lator
19
+ - Zircon
20
+
21
+
22
+ Getting started
23
+ --------------------------------------------------------------------------------
24
+
25
+
26
+ ### Install the kris
27
+
28
+ #### RubyGems.org
29
+
30
+ gem install kris
31
+
32
+
33
+ #### Bundler
34
+
35
+ Edit a `Gemfile`
36
+
37
+ gem 'kris', :git => 'git://github.com/Tomohiro/kris.git'
38
+
39
+
40
+ Install
41
+
42
+ $ bundle install --path vendor/bundle
43
+
44
+
45
+ ### Bot project directory structure
46
+
47
+ my-bot-project
48
+ |-- Gemfile
49
+ |-- MyBot
50
+ `-- plugin
51
+ |-- reply.rb
52
+ `-- crawler.rb
53
+
54
+
55
+ #### Bootstrap Bot
56
+
57
+ $ vi my-bot-project/MyBot
58
+
59
+ ```ruby
60
+ #!/usr/bin/env ruby
61
+
62
+ require 'kris'
63
+
64
+ Kris::Session.new(
65
+ server: 'chat.freenode.net',
66
+ port: 6667,
67
+ channel: '#my-bot-channel',
68
+ nickname: 'MyBot',
69
+ username: 'MyBot',
70
+ realname: 'MyBot'
71
+ ).start
72
+ ```
73
+
74
+
75
+ ### Plugin example
76
+
77
+ Response
78
+
79
+ ```ruby
80
+ class Reply < Kris::Plugin
81
+ def response(message)
82
+ case message.body.downcase
83
+ when /hello/
84
+ reply(message.to, message.from, 'Hello!')
85
+ end
86
+ end
87
+ end
88
+ ```
89
+
90
+ Notification
91
+
92
+ ```ruby
93
+ class Crawler < Kris::Plugin
94
+ def notify
95
+ crawl_datas do |new_data|
96
+ notice('#notify-channel', new_data)
97
+ end
98
+ end
99
+
100
+ private
101
+ def crawl_datas
102
+ # do something
103
+ end
104
+ end
105
+ ```
106
+
107
+
108
+ ### Run
109
+
110
+ $ bundle exec ruby MyBot
111
+
112
+
113
+
114
+
115
+ LICENSE
116
+ --------------------------------------------------------------------------------
117
+
118
+ &copy; 2012 - 2013 Tomohiro TAIRA.
119
+ This project is licensed under the MIT license.
120
+ See LICENSE for details.
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gem 'kris', :git => 'git://github.com/Tomohiro/kris.git'
@@ -0,0 +1,7 @@
1
+ # IRC Bot
2
+
3
+ ### Start
4
+
5
+ $ cd kris/example/mybot
6
+ $ bundle install --path vendor/bundle
7
+ $ bundle exec ./bot
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'kris'
4
+
5
+ bot = Kris::Session.new(
6
+ :server => 'irc.freenode.net',
7
+ :port => 6667,
8
+ :channel => '#MyChannel',
9
+ :username => 'ExampleBot',
10
+ :nickname => 'ExampleBot',
11
+ :realname => 'ExampleBot'
12
+ )
13
+
14
+ bot.start
@@ -0,0 +1,8 @@
1
+ class Reply < Kris::Plugin
2
+ def response(message)
3
+ case message.body.downcase
4
+ when /hello/
5
+ reply(message.to, message.from, 'Hello!')
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kris/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'kris'
8
+ gem.version = Kris::VERSION
9
+ gem.authors = ['Tomohiro, TAIRA']
10
+ gem.email = ['tomohiro.t@gmail.com']
11
+ gem.description = 'IRC bot'
12
+ gem.summary = 'IRC bot'
13
+ gem.homepage = 'https://github.com/Tomohiro/kris'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_runtime_dependency 'zircon'
21
+ end
@@ -0,0 +1,7 @@
1
+ require 'kris/version'
2
+ require 'logger'
3
+
4
+ module Kris
5
+ autoload :Session, 'kris/session'
6
+ autoload :Plugin, 'kris/plugin'
7
+ end
@@ -0,0 +1,55 @@
1
+ module Kris
2
+ class Plugin
3
+ class << self
4
+ def autoload(robot)
5
+ Dir.glob(File.expand_path('./plugin/*.rb')).each do |file|
6
+ require file
7
+ klass = eval(filename_classify(File.basename(file, '.rb'))).new(robot)
8
+ yield klass
9
+ end
10
+ end
11
+
12
+ def filename_classify(filename)
13
+ filename.split('_').map(&:capitalize).join
14
+ end
15
+ end
16
+
17
+ def initialize(robot)
18
+ @robot = robot
19
+ end
20
+
21
+ def boot
22
+ @robot.on_privmsg do |message|
23
+ response(message)
24
+ end
25
+
26
+ Thread.start do
27
+ loop do
28
+ notify
29
+ sleep 1
30
+ end
31
+ end
32
+ end
33
+
34
+ protected
35
+ # do nothing.
36
+ # override this method.
37
+ def response(message); end
38
+
39
+ # do nothing.
40
+ # override this method.
41
+ def notify; end
42
+
43
+ def notice(channel, message)
44
+ @robot.notice(channel, ":#{message}")
45
+ end
46
+
47
+ def privmsg(channel, message)
48
+ @robot.privmsg(channel, ":#{message}")
49
+ end
50
+
51
+ def reply(channel, reply_to, message)
52
+ privmsg(channel, "#{reply_to}: #{message}")
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,26 @@
1
+ require 'zircon'
2
+ require 'kris/zircon/message'
3
+
4
+ module Kris
5
+ class Session
6
+ def initialize(config)
7
+ @logger = Logger.new(STDOUT)
8
+ @robot = Zircon.new(config)
9
+ end
10
+
11
+ def start
12
+ @logger.info('Booting Kris...')
13
+
14
+ Plugin.autoload(@robot) do |plugin|
15
+ @logger.info("#{plugin.class} loaded.")
16
+ plugin.boot
17
+ end
18
+
19
+ @robot.run!
20
+ rescue => e
21
+ @logger.error(e)
22
+ ensure
23
+ @robot.part
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Kris
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,7 @@
1
+ class Zircon
2
+ class Message
3
+ def body
4
+ params[1].force_encoding('UTF-8')
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kris
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tomohiro, TAIRA
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: zircon
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: IRC bot
31
+ email:
32
+ - tomohiro.t@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - example/mybot/Gemfile
43
+ - example/mybot/README.markdown
44
+ - example/mybot/bot
45
+ - example/mybot/plugin/reply.rb
46
+ - kris.gemspec
47
+ - lib/kris.rb
48
+ - lib/kris/plugin.rb
49
+ - lib/kris/session.rb
50
+ - lib/kris/version.rb
51
+ - lib/kris/zircon/message.rb
52
+ homepage: https://github.com/Tomohiro/kris
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.23
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: IRC bot
76
+ test_files: []