rubot 0.0.2 → 0.0.3

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.
@@ -0,0 +1,24 @@
1
+ require "rubygems"
2
+ require "fileutils"
3
+
4
+ unless ARGV[0]
5
+ puts "usage is: rubot <project_name>"
6
+ exit!
7
+ end
8
+
9
+ if Dir.exist? ARGV[0]
10
+ puts "directory '#{ARGV[0]}' already exists"
11
+ exit
12
+ end
13
+
14
+ # there has to be a better way to do this
15
+ # why does gem documentation suck so back? (don't pay attention to rubot docs, shh)
16
+ spec = Gem.searcher.find("rubot")
17
+ template_dir = File.join(spec.installation_path, "gems", spec.full_name, "lib", "template")
18
+
19
+ FileUtils.cp_r(template_dir, ARGV[0])
20
+ # for some reason gem doesn't include empty folders during the install
21
+ # this is to make sure these directories exist
22
+ %w{resources commands listeners runners}.each do |dir|
23
+ FileUtils.mkdir File.join(ARGV[0], dir) unless File.exist? File.join(ARGV[0], dir)
24
+ end
@@ -1,4 +1,7 @@
1
1
  require "shellwords"
2
+ require "ostruct"
3
+ require "optparse"
4
+
2
5
  module Rubot
3
6
  module Core
4
7
  class Command
@@ -10,7 +10,8 @@ module Rubot
10
10
  @config = config
11
11
  @function_character = @config["function_character"]
12
12
 
13
- @auth_list = config["auth_list"].split(',')
13
+ @auth_list = config["auth_list"].split(',') if config["auth_list"]
14
+ @auth_list ||= []
14
15
 
15
16
  @resource_lock = Mutex.new
16
17
  reload
@@ -2,9 +2,6 @@ module Rubot
2
2
 
3
3
  dir = File.dirname(__FILE__)
4
4
 
5
- # run initializers
6
- Dir["#{dir}/init/*.rb"].each {|file| require file}
7
-
8
5
  # load rubot
9
6
  require "#{dir}/extensions"
10
7
  require "#{dir}/core"
@@ -0,0 +1,6 @@
1
+ class Auth < Rubot::Core::Command
2
+ def execute(server, message, options)
3
+ return if message.body != 'sudo4me'
4
+ @dispatcher.add_auth(message.from)
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ class Help < Rubot::Core::Command
2
+ def execute(server, message, options)
3
+ reply = @dispatcher.commands.keys.collect do |command|
4
+ @dispatcher.function_character + command.to_s
5
+ end.sort.join(", ")
6
+ server.msg(message.destination, reply)
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ class Join < Rubot::Core::Command
2
+ acts_as_protected
3
+
4
+ def execute(server, message, options)
5
+ server.join(message.body)
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ class Msg < Rubot::Core::Command
2
+ acts_as_protected
3
+ def execute(server, message, options)
4
+ server.msg(message.body.split(" ")[0], message.body.split(" ")[1..-1].join(" "))
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ class Part < Rubot::Core::Command
2
+ acts_as_protected
3
+
4
+ def execute(server, message, options)
5
+ if message.body.empty?
6
+ server.part(message.destination)
7
+ else
8
+ server.part(message.body)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ class Quit < Rubot::Core::Command
2
+ acts_as_protected
3
+
4
+ def execute(server, message, options)
5
+ server.quit
6
+ exit!
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class Reload < Rubot::Core::Command
2
+ acts_as_protected
3
+
4
+ def execute(server, message, options)
5
+ @dispatcher.reload
6
+ server.action(message.destination, "respawned")
7
+ end
8
+ end
@@ -0,0 +1,29 @@
1
+ class UpTime < Rubot::Core::Command
2
+ aliases :uptime, :up
3
+
4
+ def execute(server, message, options)
5
+ server.msg(message.destination, seconds_to_words(Time.now - server.connected_at))
6
+ end
7
+
8
+ def seconds_to_words(seconds)
9
+ time = "#{(seconds % 60).to_i} seconds"
10
+
11
+ minutes = seconds / 60
12
+
13
+ if minutes >= 1
14
+ hours = minutes / 60
15
+ time.insert(0, "#{(minutes % 60).to_i} minutes ")
16
+
17
+ if hours >= 1
18
+ days = hours / 24
19
+ time.insert(0, "#{(hours % 24).to_i} hours ")
20
+
21
+ if days >= 1
22
+ time.insert(0, "#{days.to_i} days ")
23
+ end
24
+ end
25
+ end
26
+
27
+ time
28
+ end
29
+ end
@@ -0,0 +1,8 @@
1
+ require "yaml"
2
+ require "rubot"
3
+
4
+ config = YAML.load_file 'resources/config.yml'
5
+
6
+ dispatcher = Rubot::Core::Dispatcher.new(config)
7
+ server = Rubot::Irc::Server.new(dispatcher)
8
+ server.connect
@@ -0,0 +1,14 @@
1
+ ---
2
+ server:
3
+ host: irc.freenode.net
4
+ port: 6667
5
+ nick: #mybot
6
+ alt_nick: #mybot_
7
+ real_name: #
8
+ channels: #"#ruby,#ruby-lang"
9
+ vhost: #leave blank if none
10
+ quit_message: powered by rubot
11
+ message_delay: 2 #in seconds
12
+
13
+ function_character: "!"
14
+ auth_list: #myrealnick
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Chris Thorn
@@ -14,19 +14,20 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-18 00:00:00 -08:00
17
+ date: 2010-03-20 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
21
21
  description: A Ruby Bot framwork for IRC featuring reloadable commands and listeners.
22
22
  email: thorncp@gmail.com
23
- executables: []
24
-
23
+ executables:
24
+ - rubot
25
25
  extensions: []
26
26
 
27
27
  extra_rdoc_files:
28
28
  - README
29
29
  files:
30
+ - bin/rubot
30
31
  - lib/core/command.rb
31
32
  - lib/core/dispatcher.rb
32
33
  - lib/core/listener.rb
@@ -36,13 +37,22 @@ files:
36
37
  - lib/extensions/object.rb
37
38
  - lib/extensions/string.rb
38
39
  - lib/extensions.rb
39
- - lib/init/bundler.rb
40
40
  - lib/irc/constants.rb
41
41
  - lib/irc/message.rb
42
42
  - lib/irc/message_queue.rb
43
43
  - lib/irc/server.rb
44
44
  - lib/irc.rb
45
45
  - lib/rubot.rb
46
+ - lib/template/commands/auth.rb
47
+ - lib/template/commands/help.rb
48
+ - lib/template/commands/join.rb
49
+ - lib/template/commands/msg.rb
50
+ - lib/template/commands/part.rb
51
+ - lib/template/commands/quit.rb
52
+ - lib/template/commands/reload.rb
53
+ - lib/template/commands/up_time.rb
54
+ - lib/template/main.rb
55
+ - lib/template/resources/config.yml
46
56
  - README
47
57
  - Rakefile
48
58
  has_rdoc: true
@@ -1,9 +0,0 @@
1
- begin
2
- # Try to require the preresolved locked set of gems.
3
- require File.expand_path('../.bundle/environment', __FILE__)
4
- rescue LoadError
5
- # Fall back on doing an unlocked resolve at runtime.
6
- require "rubygems"
7
- require "bundler"
8
- Bundler.setup
9
- end