kris 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +120 -0
- data/Rakefile +1 -0
- data/example/mybot/Gemfile +3 -0
- data/example/mybot/README.markdown +7 -0
- data/example/mybot/bot +14 -0
- data/example/mybot/plugin/reply.rb +8 -0
- data/kris.gemspec +21 -0
- data/lib/kris.rb +7 -0
- data/lib/kris/plugin.rb +55 -0
- data/lib/kris/session.rb +26 -0
- data/lib/kris/version.rb +3 -0
- data/lib/kris/zircon/message.rb +7 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
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.
|
data/README.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
Kris
|
2
|
+
================================================================================
|
3
|
+
|
4
|
+
IRC bot library - Pluggable, and very simple
|
5
|
+
|
6
|
+
[](http://badge.fury.io/rb/kris)
|
7
|
+
[](https://gemnasium.com/Tomohiro/kris)
|
8
|
+
[](https://codeclimate.com/github/Tomohiro/kris)
|
9
|
+
[](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
|
+
© 2012 - 2013 Tomohiro TAIRA.
|
119
|
+
This project is licensed under the MIT license.
|
120
|
+
See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/example/mybot/bot
ADDED
@@ -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
|
data/kris.gemspec
ADDED
@@ -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
|
data/lib/kris.rb
ADDED
data/lib/kris/plugin.rb
ADDED
@@ -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
|
data/lib/kris/session.rb
ADDED
@@ -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
|
data/lib/kris/version.rb
ADDED
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: []
|