ruben 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,49 +1,63 @@
1
1
  Ruben
2
2
  =====
3
3
 
4
+ [![Build Status](https://travis-ci.org/ericqweinstein/ruben.png)](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
- Ruben's a little janky, but he works. Version 1.0.1 is available from RubyGems; you can get your version of Ruben by typing
18
+ Version 1.0.2 is available from RubyGems; you can get your version of Ruben by typing
17
19
 
18
- $ gem install ruben
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
- $ ruben <server> <port> <channel> <nick>
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
- $ ruben irc.freenode.net 6667 test_chan ruben_
34
+ ```bash
35
+ $ ruben irc.freenode.net 6667 test_chan ruben_
36
+ ```
29
37
 
30
38
  You should see:
31
39
 
32
- $ >> USER ruben 0 * :Ruben
33
- $ >> NICK ruben_
34
- $ >> JOIN #test_chan
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
- thing_to_do lambda do
43
- # Arcane magicks go here
44
- end
54
+ ```ruby
55
+ thing_to_do lambda do
56
+ # Arcane magicks go here
57
+ end
45
58
 
46
- Listener.new(/Regexp/, thing_to_do)
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
@@ -1,7 +1,6 @@
1
1
  require 'rake'
2
- require 'rspec/core/rake_task'
3
2
 
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
3
+ task :default do
4
+ sh "rspec"
5
+ end
7
6
 
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
- $ruben = Robot.new(ARGV[0], ARGV[1], ARGV[2], ARGV[3])
7
- rescue SocketError
8
- puts "-- Usage: ruben <server> <port> <channel> <nick>"
9
- puts "-- Error: Either \"#{ARGV[0]}\" is not a valid IRC network or \"#{ARGV[1]}\" is not a valid port number."
10
- puts "-- You can find help at http://www.irchelp.org/"
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") { $ruben.quit }
40
+ trap("INT") { ruben.quit }
15
41
 
16
- $ruben.run
42
+ ruben.run
17
43
 
@@ -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 :channel, :socket, :nick
9
- attr_accessor :listeners
10
+ attr_reader :socket
11
+ attr_accessor :server, :port, :channel, :nick, :listeners
10
12
 
11
- def initialize(server, port, channel, nick)
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}"
@@ -1,8 +1,8 @@
1
1
  # MAXIMUM WARP
2
2
 
3
3
  warp_factor = lambda do
4
- $ruben.say "WARP FACTOR #{rand(9) + 1}"
4
+ Robot.instance.say "WARP FACTOR #{rand(9) + 1}"
5
5
  end
6
6
 
7
- Listener.new(/\bengage\b/i, warp_factor)
7
+ Listener.new(/ :\bengage\b/i, warp_factor)
8
8
 
@@ -0,0 +1,11 @@
1
+ # Heads I win, tails you lose
2
+
3
+ flip_coin = lambda do
4
+ coin_flip = rand(2)
5
+ result = coin_flip == 1 ? "heads" : "tails"
6
+
7
+ Robot.instance.say "#{result}!"
8
+ end
9
+
10
+ Listener.new(/ :(?:(?:ruben)?,?\s*flip\s*(?:a)?\s*coin)/i, flip_coin)
11
+
@@ -2,8 +2,8 @@
2
2
 
3
3
  say_hello = lambda do
4
4
  greetings = ["sup", "hey", "what up", "sup g"]
5
- $ruben.say "#{greetings.sample}"
5
+ Robot.instance.say "#{greetings.sample}"
6
6
  end
7
7
 
8
- Listener.new(/:(?:hi|hello|hey)\s*,?\s*(?:ruben)/i, say_hello)
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
- $ruben.say "#{responses.sample}"
5
+ Robot.instance.say "#{responses.sample}"
6
6
  end
7
7
 
8
- Listener.new(/:(?:thanks|ty|thank\s*you),?\s*(?:ruben)/i, youre_welcome)
8
+ Listener.new(/ :(?:thanks|ty|thank\s*you),?\s*(?:ruben)/i, youre_welcome)
9
9
 
@@ -0,0 +1,10 @@
1
+ # Ruben's a gamblin' man
2
+
3
+ roll_dice = lambda do
4
+ lucky_number = rand(5) + 1
5
+
6
+ Robot.instance.say "you rolled a #{lucky_number}!"
7
+ end
8
+
9
+ Listener.new(/ :(?:(?:ruben)?,?\s*roll\s*(?:the)?\s*dice)/i, roll_dice)
10
+
@@ -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
- $ruben.say "I dunno, around #{Time.now.localtime.strftime("#{current_hour}:%M %p")}"
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.1
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-02-10 00:00:00.000000000 Z
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.24
56
+ rubygems_version: 1.8.25
55
57
  signing_key:
56
58
  specification_version: 3
57
59
  summary: An extensible IRC chat bot.