raibo 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/bin/raibo +1 -1
- data/lib/raibo.rb +1 -0
- data/lib/raibo/bot.rb +33 -12
- data/lib/raibo/connection.rb +2 -11
- data/lib/raibo/dsl.rb +38 -0
- data/lib/raibo/version.rb +1 -1
- metadata +24 -32
data/.gitignore
CHANGED
data/bin/raibo
CHANGED
data/lib/raibo.rb
CHANGED
data/lib/raibo/bot.rb
CHANGED
@@ -1,27 +1,34 @@
|
|
1
1
|
module Raibo
|
2
2
|
class Bot
|
3
|
-
|
4
|
-
@handlers = []
|
3
|
+
attr_accessor :docs
|
5
4
|
|
5
|
+
def initialize(*args)
|
6
6
|
if args.first.is_a?(Raibo::Connection)
|
7
7
|
@connection = args.shift
|
8
8
|
else
|
9
9
|
@connection = Raibo::Connection.new(*args)
|
10
10
|
end
|
11
|
-
end
|
12
11
|
|
13
|
-
|
14
|
-
@handlers.push(handler || block)
|
12
|
+
reset
|
15
13
|
end
|
16
14
|
|
17
|
-
def
|
15
|
+
def reset
|
16
|
+
@handlers = []
|
17
|
+
@docs = []
|
18
|
+
@dsl = Raibo::DSL.new(self, @connection)
|
19
|
+
|
18
20
|
use do |msg|
|
19
|
-
if msg.body
|
20
|
-
|
21
|
+
if msg.body == '!help'
|
22
|
+
@bot.help
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
27
|
+
def use(handler=nil, &block)
|
28
|
+
@handlers.push(handler || block)
|
29
|
+
@docs.concat(handler.docs) if handler.respond_to?(:docs)
|
30
|
+
end
|
31
|
+
|
25
32
|
def run(async=false)
|
26
33
|
if async
|
27
34
|
@thread = Thread.new { run_sync }
|
@@ -40,6 +47,16 @@ module Raibo
|
|
40
47
|
@thread.alive? if @thread
|
41
48
|
end
|
42
49
|
|
50
|
+
def load_config_file(filename)
|
51
|
+
@dsl.instance_eval(IO.read(filename), filename)
|
52
|
+
end
|
53
|
+
|
54
|
+
def help
|
55
|
+
width = [15, @docs.map(&:first).map(&:length).max].max
|
56
|
+
|
57
|
+
@connection.say(*@docs.map { |cmd, desc| "%-#{width}s %s" % [cmd, desc] })
|
58
|
+
end
|
59
|
+
|
43
60
|
private
|
44
61
|
def run_sync
|
45
62
|
@connection.open
|
@@ -54,10 +71,14 @@ module Raibo
|
|
54
71
|
end
|
55
72
|
end
|
56
73
|
@handlers.each do |handler|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
74
|
+
begin
|
75
|
+
if handler.is_a?(Proc)
|
76
|
+
break if @dsl.instance_exec(message, &handler)
|
77
|
+
else
|
78
|
+
break if handler.call(@connection, message)
|
79
|
+
end
|
80
|
+
rescue Exception => e
|
81
|
+
@connection.say e.inspect
|
61
82
|
end
|
62
83
|
end
|
63
84
|
end
|
data/lib/raibo/connection.rb
CHANGED
@@ -57,8 +57,8 @@ module Raibo
|
|
57
57
|
send "PART #{channel}"
|
58
58
|
end
|
59
59
|
|
60
|
-
def say(
|
61
|
-
msg(@channel, msg)
|
60
|
+
def say(*msgs)
|
61
|
+
msgs.each { |msg| msg(@channel, msg) }
|
62
62
|
end
|
63
63
|
|
64
64
|
def msg(dest, msg)
|
@@ -69,14 +69,5 @@ module Raibo
|
|
69
69
|
puts "<-- #{str}" if @verbose
|
70
70
|
@connection.puts(str)
|
71
71
|
end
|
72
|
-
|
73
|
-
def exec_with_var_arity(*args, &block)
|
74
|
-
arity = block.arity
|
75
|
-
if arity <= 0
|
76
|
-
instance_eval(&block)
|
77
|
-
else
|
78
|
-
instance_exec(*args.take(block.arity), &block)
|
79
|
-
end
|
80
|
-
end
|
81
72
|
end
|
82
73
|
end
|
data/lib/raibo/dsl.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Raibo
|
2
|
+
class DSL
|
3
|
+
def initialize(bot, connection)
|
4
|
+
@bot = bot
|
5
|
+
@connection = connection
|
6
|
+
end
|
7
|
+
|
8
|
+
def use(handler=nil, &block)
|
9
|
+
@bot.use(handler, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def match(regexp, &block)
|
13
|
+
use do |msg|
|
14
|
+
if msg.body =~ regexp
|
15
|
+
exec_with_var_arity($~, msg, &block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def doc(cmd, desc='')
|
21
|
+
@bot.docs << [cmd, desc]
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(meth, *args, &block)
|
25
|
+
@connection.__send__(meth, *args, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def exec_with_var_arity(*args, &block)
|
30
|
+
arity = block.arity
|
31
|
+
if arity <= 0
|
32
|
+
instance_eval(&block)
|
33
|
+
else
|
34
|
+
instance_exec(*args.take(block.arity), &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/raibo/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,24 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: raibo
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.3
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Ryan Fitzgerald
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2011-07-17 00:00:00 -07:00
|
14
|
-
default_executable:
|
12
|
+
date: 2011-08-30 00:00:00.000000000Z
|
15
13
|
dependencies: []
|
16
|
-
|
17
|
-
|
18
|
-
email:
|
14
|
+
description: ''
|
15
|
+
email:
|
19
16
|
- rwfitzge@gmail.com
|
20
|
-
executables:
|
17
|
+
executables:
|
21
18
|
- raibo
|
22
19
|
extensions: []
|
23
|
-
|
24
20
|
extra_rdoc_files: []
|
25
|
-
|
26
|
-
files:
|
21
|
+
files:
|
27
22
|
- .gitignore
|
28
23
|
- Gemfile
|
29
24
|
- Rakefile
|
@@ -32,39 +27,36 @@ files:
|
|
32
27
|
- lib/raibo.rb
|
33
28
|
- lib/raibo/bot.rb
|
34
29
|
- lib/raibo/connection.rb
|
30
|
+
- lib/raibo/dsl.rb
|
35
31
|
- lib/raibo/message.rb
|
36
32
|
- lib/raibo/version.rb
|
37
33
|
- raibo.gemspec
|
38
34
|
- spec/message_spec.rb
|
39
35
|
- spec/spec_helper.rb
|
40
|
-
|
41
|
-
homepage: ""
|
36
|
+
homepage: ''
|
42
37
|
licenses: []
|
43
|
-
|
44
38
|
post_install_message:
|
45
39
|
rdoc_options: []
|
46
|
-
|
47
|
-
require_paths:
|
40
|
+
require_paths:
|
48
41
|
- lib
|
49
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
43
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
49
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version:
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
61
54
|
requirements: []
|
62
|
-
|
63
55
|
rubyforge_project: raibo
|
64
|
-
rubygems_version: 1.
|
56
|
+
rubygems_version: 1.8.6
|
65
57
|
signing_key:
|
66
58
|
specification_version: 3
|
67
59
|
summary: A simple IRC library
|
68
|
-
test_files:
|
60
|
+
test_files:
|
69
61
|
- spec/message_spec.rb
|
70
62
|
- spec/spec_helper.rb
|