ruben 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2012 - 2013 Eric Weinstein
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
@@ -0,0 +1,59 @@
1
+ Ruben
2
+ =====
3
+
4
+ ###Description
5
+
6
+ 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
+
8
+ ###Dependencies
9
+
10
+ * Ruby 1.9.3+
11
+ * Rake 10.0.3+
12
+ * RSpec 2.12.2+
13
+
14
+ ###Installation
15
+
16
+ Ruben isn't quite finished, so he hasn't been pushed to RubyGems. If you want to get your own copy of Ruben, you can clone the repo:
17
+
18
+ $ git clone https://github.com/ericqweinstein/ruben.git
19
+
20
+ In the `ruben/` directory, run his (admittedly sparse) tests:
21
+
22
+ $ rake
23
+
24
+ Build the gem:
25
+
26
+ $ gem build ruben.gemspec
27
+
28
+ And install it:
29
+
30
+ $ gem install ruben
31
+
32
+ ###Getting Started
33
+
34
+ Ruben comes with a `bin/ruben` executable, so you can run him with
35
+
36
+ $ ruben <server> <port> <channel> <nick>
37
+
38
+ Ruben takes a server name, port number, channel name, and nick as command line arguments. For example, if you type:
39
+
40
+ $ ruben irc.freenode.net 6667 test_chan ruben_
41
+
42
+ You should see:
43
+
44
+ $ >> USER ruben 0 * :Ruben
45
+ $ >> NICK ruben_
46
+ $ >> JOIN #test_chan
47
+
48
+ ...
49
+
50
+ And so on.
51
+
52
+ ###Adding Scripts
53
+
54
+ You can extend Ruben's functionality by adding scripts to `/scripts`, like so:
55
+
56
+ Listener.new(/Regexp/, "response string")
57
+
58
+ Ruben's listeners hear every incoming IRC message. If a listener's Regexp matches the inbound message, Ruben will respond with the associated text string.
59
+
@@ -0,0 +1,7 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require_relative "../lib/robot"
4
+
5
+ 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/"
11
+ end
12
+
13
+ # Ensure Ruben leaves politely when ^C-ed
14
+ trap("INT") { ruben.quit }
15
+
16
+ ruben.run
17
+
@@ -0,0 +1,28 @@
1
+ require "socket"
2
+ require_relative "robot/channel"
3
+ require_relative "robot/listener"
4
+
5
+ class Robot
6
+ include Channel
7
+
8
+ attr_reader :channel, :socket, :nick
9
+ attr_accessor :listeners
10
+
11
+ def initialize(server, port, channel, nick)
12
+ @socket = TCPSocket.open(server, port)
13
+ @channel = channel
14
+ @nick = nick
15
+ @listeners = Listener.all_listeners
16
+ end
17
+
18
+ def run
19
+ send "USER ruben 0 * :Ruben"
20
+ send "NICK #{@nick}"
21
+ send "JOIN ##{@channel}"
22
+
23
+ until @socket.eof? do
24
+ listen
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,43 @@
1
+ require_relative "listener"
2
+
3
+ # Load scripts
4
+ Dir[File.dirname(__FILE__) + "/scripts/*.rb"].each { |script| require script }
5
+
6
+ module Channel
7
+
8
+ PARTING_MESSAGES = ["Goodbye!", "Peace!", "Later.", "I'm out!"]
9
+
10
+ def send(msg)
11
+ @socket.puts msg
12
+ puts "<< " << msg
13
+ end
14
+
15
+ def say(msg)
16
+ send "PRIVMSG ##{@channel} :#{msg}"
17
+ end
18
+
19
+ def listen
20
+ @inbound = @socket.gets
21
+ puts ">> " << @inbound
22
+
23
+ # Stay connected to the server
24
+ if @inbound.match(/^PING (.*)$/)
25
+ pong = $1
26
+ send "PONG #{pong}"
27
+ end
28
+
29
+ # Respond to messages in the channel
30
+ @listeners.each do |listener|
31
+ if @inbound.match(listener.pattern)
32
+ say listener.response
33
+ end
34
+ end
35
+ end
36
+
37
+ def quit
38
+ say "#{PARTING_MESSAGES.sample}"
39
+ send "PART ##{@channel} :mic drop"
40
+ send "QUIT"
41
+ end
42
+ end
43
+
@@ -0,0 +1,16 @@
1
+ class Listener
2
+ attr_accessor :pattern, :response
3
+
4
+ @@listeners = []
5
+
6
+ def initialize(pattern, response)
7
+ @@listeners << self
8
+ @pattern = pattern
9
+ @response = response
10
+ end
11
+
12
+ def self.all_listeners
13
+ @@listeners
14
+ end
15
+ end
16
+
@@ -0,0 +1,4 @@
1
+ # Friendly robots are good robots
2
+
3
+ Listener.new(/:(?:hi|hello|hey)\s*,?\s*(?:ruben)/i, "Hello!")
4
+
@@ -0,0 +1,4 @@
1
+ # Polite robots are good robots
2
+
3
+ Listener.new(/:(?:thanks|ty|thank\s*you),?\s*(?:ruben)/i, "You're welcome!")
4
+
@@ -0,0 +1,4 @@
1
+ # Teaching Ruben to tell time
2
+
3
+ Listener.new(/(?:what\s*time)/i, "Right now it's #{Time.now.localtime.strftime("%H:%M:%S %p")}.")
4
+
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruben
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eric Weinstein
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Ruben is an IRC chat bot written in Ruby. He is inspired, in part, by
15
+ Hubot, his CoffeeScript brother from another mother.
16
+ email:
17
+ - eric.q.weinstein@gmail.com
18
+ executables:
19
+ - ruben
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - bin/ruben
24
+ - lib/robot/channel.rb
25
+ - lib/robot/listener.rb
26
+ - lib/robot/scripts/hello.rb
27
+ - lib/robot/scripts/politeness.rb
28
+ - lib/robot/scripts/tell_time.rb
29
+ - lib/robot.rb
30
+ - LICENSE
31
+ - README.md
32
+ - Rakefile
33
+ homepage: http://github.com/ericqweinstein/ruben
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.24
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: An extensible IRC chat bot.
57
+ test_files: []
58
+ has_rdoc: