ruben 1.0.1 → 1.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 +29 -15
- data/Rakefile +3 -4
- data/bin/ruben +33 -7
- data/lib/robot.rb +12 -6
- data/lib/robot/scripts/engage.rb +2 -2
- data/lib/robot/scripts/flip_coin.rb +11 -0
- data/lib/robot/scripts/hello.rb +2 -2
- data/lib/robot/scripts/politeness.rb +2 -2
- data/lib/robot/scripts/roll_dice.rb +10 -0
- data/lib/robot/scripts/tell_time.rb +2 -2
- metadata +5 -3
data/README.md
CHANGED
@@ -1,49 +1,63 @@
|
|
1
1
|
Ruben
|
2
2
|
=====
|
3
3
|
|
4
|
+
[](https://travis-ci.org/ericqweinstein/ruben)
|
5
|
+
|
4
6
|
###Description
|
5
7
|
|
6
8
|
Ruben is an IRC chat bot written in Ruby. He is inspired, in part, by [Hubot](http://hubot.github.com/), his CoffeeScript brother from another mother.
|
7
9
|
|
8
10
|
###Dependencies
|
9
11
|
|
10
|
-
* Ruby 1.9.3
|
11
|
-
* Rake 10.0.3
|
12
|
-
* RSpec 2.12.2
|
12
|
+
* Ruby 1.9.3 (not tested in Ruby 2.0)
|
13
|
+
* Rake 10.0.3 (for running tests)
|
14
|
+
* RSpec 2.12.2 (for running tests)
|
13
15
|
|
14
16
|
###Installation
|
15
17
|
|
16
|
-
|
18
|
+
Version 1.0.2 is available from RubyGems; you can get your version of Ruben by typing
|
17
19
|
|
18
|
-
|
20
|
+
```bash
|
21
|
+
$ gem install ruben
|
22
|
+
```
|
19
23
|
|
20
24
|
###Getting Started
|
21
25
|
|
22
26
|
Ruben comes with a `bin/ruben` executable, so you can run him with
|
23
27
|
|
24
|
-
|
28
|
+
```bash
|
29
|
+
$ ruben <server> <port> <channel> <nick>
|
30
|
+
```
|
25
31
|
|
26
32
|
Ruben takes a server name, port number, channel name, and nick as command line arguments. For example, if you type:
|
27
33
|
|
28
|
-
|
34
|
+
```bash
|
35
|
+
$ ruben irc.freenode.net 6667 test_chan ruben_
|
36
|
+
```
|
29
37
|
|
30
38
|
You should see:
|
31
39
|
|
32
|
-
|
33
|
-
|
34
|
-
|
40
|
+
```
|
41
|
+
$ >> USER ruben 0 * :Ruben
|
42
|
+
$ >> NICK ruben_
|
43
|
+
$ >> JOIN #test_chan
|
44
|
+
|
45
|
+
...
|
46
|
+
```
|
35
47
|
|
36
|
-
|
48
|
+
You can get Ruben's usage information by typing `ruben -h` or `ruben --help`.
|
37
49
|
|
38
50
|
###Adding Scripts
|
39
51
|
|
40
52
|
You can extend Ruben's functionality by adding scripts to `/scripts`. Each script should be a `.rb` file that instantiates a new `Listener` object, like so:
|
41
53
|
|
42
|
-
|
43
|
-
|
44
|
-
|
54
|
+
```ruby
|
55
|
+
thing_to_do lambda do
|
56
|
+
# Arcane magicks go here
|
57
|
+
end
|
45
58
|
|
46
|
-
|
59
|
+
Listener.new(/Regexp/, thing_to_do)
|
60
|
+
```
|
47
61
|
|
48
62
|
Ruben's listeners hear every incoming IRC message. If a listener's Regexp matches the inbound message, Ruben will call the associated lambda.
|
49
63
|
|
data/Rakefile
CHANGED
data/bin/ruben
CHANGED
@@ -1,17 +1,43 @@
|
|
1
1
|
#!/usr/bin/env ruby -w
|
2
2
|
|
3
|
+
require "optparse"
|
3
4
|
require_relative "../lib/robot"
|
4
5
|
|
6
|
+
options = {}
|
7
|
+
|
8
|
+
opt_parser = OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: ruben SERVER PORT CHANNEL NICK"
|
10
|
+
opts.separator ""
|
11
|
+
opts.separator "Running Ruben:"
|
12
|
+
opts.separator " SERVER is an IRC server (e.g. irc.freenode.net)."
|
13
|
+
opts.separator " PORT is the IRC port (e.g. 6667)."
|
14
|
+
opts.separator " CHANNEL is the IRC channel you want to join."
|
15
|
+
opts.separator " NICK is the nickname you want Ruben to use."
|
16
|
+
opts.separator ""
|
17
|
+
|
18
|
+
opts.on("-h", "--help", "Display this screen") do
|
19
|
+
puts opt_parser
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
begin opt_parser.parse!
|
25
|
+
rescue OptionParser::InvalidOption => e
|
26
|
+
abort("An error occurred: #{e}. Run ruben -h for help.")
|
27
|
+
end
|
28
|
+
|
5
29
|
begin
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
30
|
+
ruben = Robot.instance
|
31
|
+
ruben.server = ARGV[0]
|
32
|
+
ruben.port = ARGV[1]
|
33
|
+
ruben.channel = ARGV[2]
|
34
|
+
ruben.nick = ARGV[3]
|
35
|
+
rescue SocketError => e
|
36
|
+
puts "An error occurred: #{e}. Run ruben -h for help."
|
11
37
|
end
|
12
38
|
|
13
39
|
# Ensure Ruben leaves politely when ^C-ed
|
14
|
-
trap("INT") {
|
40
|
+
trap("INT") { ruben.quit }
|
15
41
|
|
16
|
-
|
42
|
+
ruben.run
|
17
43
|
|
data/lib/robot.rb
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
require "socket"
|
2
|
+
require "singleton"
|
2
3
|
require_relative "robot/channel"
|
3
4
|
require_relative "robot/listener"
|
4
5
|
|
5
6
|
class Robot
|
7
|
+
include Singleton
|
6
8
|
include Channel
|
7
9
|
|
8
|
-
attr_reader :
|
9
|
-
attr_accessor :listeners
|
10
|
+
attr_reader :socket
|
11
|
+
attr_accessor :server, :port, :channel, :nick, :listeners
|
10
12
|
|
11
|
-
def initialize
|
12
|
-
@socket = TCPSocket.open(server, port)
|
13
|
-
@channel = channel
|
14
|
-
@nick = nick
|
13
|
+
def initialize
|
15
14
|
@listeners = Listener.all_listeners
|
16
15
|
end
|
17
16
|
|
18
17
|
def run
|
18
|
+
begin
|
19
|
+
@socket = TCPSocket.open(server, port)
|
20
|
+
rescue
|
21
|
+
puts "An error occurred. Make sure to call Ruben with a valid server and port name."
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
|
19
25
|
send "USER ruben 0 * :Ruben"
|
20
26
|
send "NICK #{@nick}"
|
21
27
|
send "JOIN ##{@channel}"
|
data/lib/robot/scripts/engage.rb
CHANGED
data/lib/robot/scripts/hello.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
say_hello = lambda do
|
4
4
|
greetings = ["sup", "hey", "what up", "sup g"]
|
5
|
-
|
5
|
+
Robot.instance.say "#{greetings.sample}"
|
6
6
|
end
|
7
7
|
|
8
|
-
Listener.new(
|
8
|
+
Listener.new(/ :(?:hi|hello|hey)\s*,?\s*(?:ruben)/i, say_hello)
|
9
9
|
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
youre_welcome = lambda do
|
4
4
|
responses = ["no prob", "sure thing", "np boss"]
|
5
|
-
|
5
|
+
Robot.instance.say "#{responses.sample}"
|
6
6
|
end
|
7
7
|
|
8
|
-
Listener.new(
|
8
|
+
Listener.new(/ :(?:thanks|ty|thank\s*you),?\s*(?:ruben)/i, youre_welcome)
|
9
9
|
|
@@ -4,8 +4,8 @@ what_time = lambda do
|
|
4
4
|
current_hour = Time.now.localtime.strftime("%H").to_i
|
5
5
|
current_hour = current_hour > 12 ? current_hour - 12 : current_hour
|
6
6
|
|
7
|
-
|
7
|
+
Robot.instance.say "I dunno, around #{Time.now.localtime.strftime("#{current_hour}:%M %p")}"
|
8
8
|
end
|
9
9
|
|
10
|
-
Listener.new(/(?:what\s*time)/i, what_time)
|
10
|
+
Listener.new(/ :(?:what\s*time)/i, what_time)
|
11
11
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruben
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-11 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruben is an IRC chat bot written in Ruby. He is inspired, in part, by
|
15
15
|
Hubot, his CoffeeScript brother from another mother.
|
@@ -24,8 +24,10 @@ files:
|
|
24
24
|
- lib/robot/channel.rb
|
25
25
|
- lib/robot/listener.rb
|
26
26
|
- lib/robot/scripts/engage.rb
|
27
|
+
- lib/robot/scripts/flip_coin.rb
|
27
28
|
- lib/robot/scripts/hello.rb
|
28
29
|
- lib/robot/scripts/politeness.rb
|
30
|
+
- lib/robot/scripts/roll_dice.rb
|
29
31
|
- lib/robot/scripts/tell_time.rb
|
30
32
|
- lib/robot.rb
|
31
33
|
- LICENSE
|
@@ -51,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
53
|
version: '0'
|
52
54
|
requirements: []
|
53
55
|
rubyforge_project:
|
54
|
-
rubygems_version: 1.8.
|
56
|
+
rubygems_version: 1.8.25
|
55
57
|
signing_key:
|
56
58
|
specification_version: 3
|
57
59
|
summary: An extensible IRC chat bot.
|