kris 0.0.1 → 0.0.2
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/README.md +15 -15
- data/example/mybot/{README.markdown → README.md} +0 -0
- data/example/mybot/bot +1 -0
- data/example/mybot/plugin/reply.rb +1 -1
- data/kris.gemspec +4 -4
- data/lib/kris/plugin.rb +41 -22
- data/lib/kris/session.rb +25 -11
- data/lib/kris/version.rb +1 -1
- data/lib/kris/zircon/message.rb +4 -0
- data/lib/kris.rb +4 -3
- metadata +6 -6
data/README.md
CHANGED
|
@@ -5,8 +5,8 @@ IRC bot library - Pluggable, and very simple
|
|
|
5
5
|
|
|
6
6
|
[](http://badge.fury.io/rb/kris)
|
|
7
7
|
[](https://gemnasium.com/Tomohiro/kris)
|
|
8
|
+
[](http://stillmaintained.com/Tomohiro/kris)
|
|
8
9
|
[](https://codeclimate.com/github/Tomohiro/kris)
|
|
9
|
-
[](http://coderwall.com/tomohiro)
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
---
|
|
@@ -16,7 +16,6 @@ Requirements
|
|
|
16
16
|
--------------------------------------------------------------------------------
|
|
17
17
|
|
|
18
18
|
- Ruby 1.9.3 or lator
|
|
19
|
-
- Zircon
|
|
20
19
|
|
|
21
20
|
|
|
22
21
|
Getting started
|
|
@@ -49,7 +48,7 @@ Install
|
|
|
49
48
|
|-- MyBot
|
|
50
49
|
`-- plugin
|
|
51
50
|
|-- reply.rb
|
|
52
|
-
`--
|
|
51
|
+
`-- hello.rb
|
|
53
52
|
|
|
54
53
|
|
|
55
54
|
#### Bootstrap Bot
|
|
@@ -67,7 +66,10 @@ Kris::Session.new(
|
|
|
67
66
|
channel: '#my-bot-channel',
|
|
68
67
|
nickname: 'MyBot',
|
|
69
68
|
username: 'MyBot',
|
|
70
|
-
realname: 'MyBot'
|
|
69
|
+
realname: 'MyBot',
|
|
70
|
+
# Optional settings is below (Not Required)
|
|
71
|
+
channels: %(#foo #bar #baz), # If you want to join another channels with additional
|
|
72
|
+
plugin_path: '/home/kris/my-bot-plugins' # If you want to specify a defferent path
|
|
71
73
|
).start
|
|
72
74
|
```
|
|
73
75
|
|
|
@@ -78,29 +80,27 @@ Response
|
|
|
78
80
|
|
|
79
81
|
```ruby
|
|
80
82
|
class Reply < Kris::Plugin
|
|
81
|
-
def
|
|
83
|
+
def on_privmsg(message)
|
|
82
84
|
case message.body.downcase
|
|
83
85
|
when /hello/
|
|
84
86
|
reply(message.to, message.from, 'Hello!')
|
|
85
87
|
end
|
|
86
88
|
end
|
|
89
|
+
|
|
90
|
+
def on_topic(message)
|
|
91
|
+
notice(message.to, "Now topic is #{message.body}")
|
|
92
|
+
end
|
|
87
93
|
end
|
|
88
94
|
```
|
|
89
95
|
|
|
90
|
-
|
|
96
|
+
Scheduled notification
|
|
91
97
|
|
|
92
98
|
```ruby
|
|
93
|
-
class
|
|
99
|
+
class Hello < Kris::Plugin
|
|
94
100
|
def notify
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
end
|
|
101
|
+
sleep 300
|
|
102
|
+
notice('#notify-channel', 'Hello')
|
|
98
103
|
end
|
|
99
|
-
|
|
100
|
-
private
|
|
101
|
-
def crawl_datas
|
|
102
|
-
# do something
|
|
103
|
-
end
|
|
104
104
|
end
|
|
105
105
|
```
|
|
106
106
|
|
|
File without changes
|
data/example/mybot/bot
CHANGED
|
@@ -6,6 +6,7 @@ bot = Kris::Session.new(
|
|
|
6
6
|
:server => 'irc.freenode.net',
|
|
7
7
|
:port => 6667,
|
|
8
8
|
:channel => '#MyChannel',
|
|
9
|
+
# :channels => %w(#channel_1 #channel_2 #channel3) # If you want join multiple channels.
|
|
9
10
|
:username => 'ExampleBot',
|
|
10
11
|
:nickname => 'ExampleBot',
|
|
11
12
|
:realname => 'ExampleBot'
|
data/kris.gemspec
CHANGED
|
@@ -6,14 +6,14 @@ require 'kris/version'
|
|
|
6
6
|
Gem::Specification.new do |gem|
|
|
7
7
|
gem.name = 'kris'
|
|
8
8
|
gem.version = Kris::VERSION
|
|
9
|
-
gem.authors = ['Tomohiro
|
|
9
|
+
gem.authors = ['Tomohiro TAIRA']
|
|
10
10
|
gem.email = ['tomohiro.t@gmail.com']
|
|
11
|
-
gem.description = 'IRC bot'
|
|
12
|
-
gem.summary = 'IRC bot'
|
|
11
|
+
gem.description = 'IRC bot library - Pluggable, and very simple'
|
|
12
|
+
gem.summary = 'IRC bot library - Pluggable, and very simple'
|
|
13
13
|
gem.homepage = 'https://github.com/Tomohiro/kris'
|
|
14
14
|
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
|
16
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
18
18
|
gem.require_paths = ['lib']
|
|
19
19
|
|
data/lib/kris/plugin.rb
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
module Kris
|
|
2
2
|
class Plugin
|
|
3
3
|
class << self
|
|
4
|
-
def autoload(
|
|
5
|
-
|
|
4
|
+
def autoload(plugin_path = nil)
|
|
5
|
+
return unless plugin_path
|
|
6
|
+
|
|
7
|
+
plugin_files(plugin_path).each do |file|
|
|
6
8
|
require file
|
|
7
|
-
|
|
8
|
-
yield klass
|
|
9
|
+
yield eval(filename_classify(file))
|
|
9
10
|
end
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
def filename_classify(
|
|
13
|
-
|
|
13
|
+
def filename_classify(file)
|
|
14
|
+
File.basename(file, '.rb').split('_').map(&:capitalize).join
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def plugin_files(plugin_path)
|
|
18
|
+
Dir[File.join(File.expand_path(plugin_path), '*.rb')]
|
|
14
19
|
end
|
|
15
20
|
end
|
|
16
21
|
|
|
@@ -19,25 +24,17 @@ module Kris
|
|
|
19
24
|
end
|
|
20
25
|
|
|
21
26
|
def boot
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
Thread.start do
|
|
27
|
-
loop do
|
|
28
|
-
notify
|
|
29
|
-
sleep 1
|
|
30
|
-
end
|
|
31
|
-
end
|
|
27
|
+
load_callbacks
|
|
28
|
+
start_notification_scheduler
|
|
32
29
|
end
|
|
33
30
|
|
|
34
31
|
protected
|
|
35
|
-
#
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
# Call response method is for backwords compatibility
|
|
33
|
+
def on_privmsg(message)
|
|
34
|
+
response(message) if respond_to?(:response)
|
|
35
|
+
end
|
|
38
36
|
|
|
39
|
-
#
|
|
40
|
-
# override this method.
|
|
37
|
+
# Override this method if you want get scheduled notification.
|
|
41
38
|
def notify; end
|
|
42
39
|
|
|
43
40
|
def notice(channel, message)
|
|
@@ -49,7 +46,29 @@ module Kris
|
|
|
49
46
|
end
|
|
50
47
|
|
|
51
48
|
def reply(channel, reply_to, message)
|
|
52
|
-
privmsg(channel, "
|
|
49
|
+
@robot.privmsg(channel, ":#{reply_to}: #{message}")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
def load_callbacks
|
|
54
|
+
Zircon::COMMAND_NAMES.each do |command|
|
|
55
|
+
method_name = "on_#{command.downcase}"
|
|
56
|
+
next unless respond_to?(method_name)
|
|
57
|
+
|
|
58
|
+
@robot.send(method_name) do |message|
|
|
59
|
+
send(method_name, message)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def start_notification_scheduler
|
|
65
|
+
return unless respond_to?(:notify)
|
|
66
|
+
Thread.start do
|
|
67
|
+
loop do
|
|
68
|
+
notify
|
|
69
|
+
sleep 1
|
|
70
|
+
end
|
|
71
|
+
end
|
|
53
72
|
end
|
|
54
73
|
end
|
|
55
74
|
end
|
data/lib/kris/session.rb
CHANGED
|
@@ -2,25 +2,39 @@ require 'zircon'
|
|
|
2
2
|
require 'kris/zircon/message'
|
|
3
3
|
|
|
4
4
|
module Kris
|
|
5
|
-
class Session
|
|
5
|
+
class Session < Zircon
|
|
6
6
|
def initialize(config)
|
|
7
|
-
@logger
|
|
8
|
-
@
|
|
7
|
+
@logger = Logger.new(STDOUT)
|
|
8
|
+
@channels = config.fetch(:channels, nil)
|
|
9
|
+
@plugin_path = config.fetch(:plugin_path, './plugin')
|
|
10
|
+
super(config)
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def start
|
|
12
14
|
@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!
|
|
15
|
+
run!
|
|
20
16
|
rescue => e
|
|
21
17
|
@logger.error(e)
|
|
22
18
|
ensure
|
|
23
|
-
|
|
19
|
+
part
|
|
24
20
|
end
|
|
21
|
+
|
|
22
|
+
protected
|
|
23
|
+
def run!
|
|
24
|
+
Plugin.autoload(@plugin_path) do |plugin|
|
|
25
|
+
@logger.info("#{plugin} loaded.")
|
|
26
|
+
plugin.new(self).boot
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
login
|
|
30
|
+
join_to_channels(@channels) if @channels
|
|
31
|
+
wait_message
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def join_to_channels(channels)
|
|
35
|
+
channels.each do |channel|
|
|
36
|
+
join(channel)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
25
39
|
end
|
|
26
40
|
end
|
data/lib/kris/version.rb
CHANGED
data/lib/kris/zircon/message.rb
CHANGED
data/lib/kris.rb
CHANGED
metadata
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kris
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
|
-
- Tomohiro
|
|
8
|
+
- Tomohiro TAIRA
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
12
|
+
date: 2013-02-10 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: zircon
|
|
@@ -27,7 +27,7 @@ dependencies:
|
|
|
27
27
|
- - ! '>='
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
29
|
version: '0'
|
|
30
|
-
description: IRC bot
|
|
30
|
+
description: IRC bot library - Pluggable, and very simple
|
|
31
31
|
email:
|
|
32
32
|
- tomohiro.t@gmail.com
|
|
33
33
|
executables: []
|
|
@@ -40,7 +40,7 @@ files:
|
|
|
40
40
|
- README.md
|
|
41
41
|
- Rakefile
|
|
42
42
|
- example/mybot/Gemfile
|
|
43
|
-
- example/mybot/README.
|
|
43
|
+
- example/mybot/README.md
|
|
44
44
|
- example/mybot/bot
|
|
45
45
|
- example/mybot/plugin/reply.rb
|
|
46
46
|
- kris.gemspec
|
|
@@ -72,5 +72,5 @@ rubyforge_project:
|
|
|
72
72
|
rubygems_version: 1.8.23
|
|
73
73
|
signing_key:
|
|
74
74
|
specification_version: 3
|
|
75
|
-
summary: IRC bot
|
|
75
|
+
summary: IRC bot library - Pluggable, and very simple
|
|
76
76
|
test_files: []
|