Sutto-marvin 0.3.0 → 0.3.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/VERSION.yml +3 -3
- data/handlers/debug_handler.rb +0 -5
- data/handlers/logging_handler.rb +2 -0
- data/handlers/simple_logger.rb +24 -0
- data/lib/marvin.rb +2 -1
- data/lib/marvin/abstract_client.rb +4 -0
- data/lib/marvin/core_commands.rb +31 -0
- data/lib/marvin/daemon.rb +2 -2
- data/lib/marvin/irc/server.rb +1 -1
- data/lib/marvin/logger.rb +1 -1
- data/lib/marvin/logging_handler.rb +76 -0
- metadata +12 -8
data/VERSION.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
:major: 0
|
3
|
+
:minor: 3
|
4
|
+
:patch: 2
|
data/handlers/debug_handler.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
# Use this class to debug stuff as you
|
2
2
|
# go along - e.g. dump events etc.
|
3
3
|
class DebugHandler < Marvin::CommandHandler
|
4
|
-
|
5
|
-
exposes :about
|
6
|
-
def about(*args)
|
7
|
-
reply "Marvin v#{Marvin::VERSION::STRING} running on Ruby #{RUBY_VERSION} (#{RUBY_PLATFORM})"
|
8
|
-
end
|
9
4
|
|
10
5
|
end
|
data/handlers/logging_handler.rb
CHANGED
@@ -21,6 +21,7 @@ class LoggingHandler < Marvin::CommandHandler
|
|
21
21
|
|
22
22
|
exposes :listen, :earmuffs
|
23
23
|
|
24
|
+
desc "Makes me listen up and take not of what you're saying."
|
24
25
|
def listen(data)
|
25
26
|
unless listening?
|
26
27
|
@listening = true
|
@@ -30,6 +31,7 @@ class LoggingHandler < Marvin::CommandHandler
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
34
|
+
desc "Sends me off into a corner with my ear muffs so you can have your discussions in peace"
|
33
35
|
def earmuffs(data)
|
34
36
|
if listening?
|
35
37
|
@listening = false
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# A reference logger example
|
2
|
+
class SimpleLogger < Marvin::LoggingHandler
|
3
|
+
|
4
|
+
def setup_logging
|
5
|
+
logger.warn "Setting up the client"
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown_logging
|
9
|
+
logger.warn "Tearing down the logger"
|
10
|
+
end
|
11
|
+
|
12
|
+
def log_incoming(server, nick, target, message)
|
13
|
+
logger.fatal "[INCOMING] #{server} (#{target}) #{nick}: #{message}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def log_outgoing(server, nick, target, message)
|
17
|
+
logger.fatal "[OUTGOING] #{server} (#{target}) #{nick}: #{message}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def log_message(server, nick, target, message)
|
21
|
+
logger.fatal "[MESSAGE] #{server} (#{target}) #{nick}: #{message}"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/marvin.rb
CHANGED
@@ -11,7 +11,7 @@ module Marvin
|
|
11
11
|
module VERSION
|
12
12
|
MAJOR = 0
|
13
13
|
MINOR = 3
|
14
|
-
PATCH =
|
14
|
+
PATCH = 2
|
15
15
|
|
16
16
|
STRING = [MAJOR, MINOR, PATCH].join(".")
|
17
17
|
end
|
@@ -26,6 +26,7 @@ module Marvin
|
|
26
26
|
autoload :ClientMixin, 'marvin/client_mixin'
|
27
27
|
autoload :Settings, 'marvin/settings'
|
28
28
|
autoload :Logger, 'marvin/logger'
|
29
|
+
autoload :LoggingHandler, 'marvin/logging_handler'
|
29
30
|
autoload :IRC, 'marvin/irc'
|
30
31
|
autoload :TestClient, 'marvin/test_client'
|
31
32
|
autoload :Loader, 'marvin/loader'
|
@@ -114,6 +114,10 @@ module Marvin
|
|
114
114
|
@default_channels = channels.to_a.map { |c| c.to_s }
|
115
115
|
end
|
116
116
|
|
117
|
+
def host_with_port
|
118
|
+
@host_with_port ||= "#{self.server}:#{self.port}"
|
119
|
+
end
|
120
|
+
|
117
121
|
def nicks
|
118
122
|
if @nicks.blank? && !@nicks_loaded
|
119
123
|
logger.info "Setting default nick list"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Marvin
|
2
|
+
class CoreCommands < CommandHandler
|
3
|
+
|
4
|
+
exposes :help
|
5
|
+
desc "Generates this usage statement"
|
6
|
+
def help(methods)
|
7
|
+
method_names = exposed_method_names.map { |n| n.to_s }
|
8
|
+
documented_names = descriptions.keys.map { |k| k.to_s } & method_names
|
9
|
+
if methods.empty?
|
10
|
+
width = documented_names.map { |s| s.length }.max
|
11
|
+
say "Hello there, I know the following commands:"
|
12
|
+
documented_names.each { |name| say "#{name.ljust(width)} - #{descriptions[name.to_sym]}" }
|
13
|
+
say "As well as the following undescribed commands: #{(method_names - documented_names).sort.join(", ")}"
|
14
|
+
else
|
15
|
+
m = methods.first
|
16
|
+
if documented_names.include? m.to_s
|
17
|
+
reply "#{m}: #{descriptions[m.to_sym]}"
|
18
|
+
else
|
19
|
+
reply "I'm sorry, I can't help with #{m} - it seems to be undocumented."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
exposes :about
|
25
|
+
desc "Displays the current marvin and ruby versions."
|
26
|
+
def about(*args)
|
27
|
+
reply "Marvin v#{Marvin::VERSION::STRING} running on Ruby #{RUBY_VERSION} (#{RUBY_PLATFORM})"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/marvin/daemon.rb
CHANGED
@@ -31,7 +31,7 @@ module Marvin
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def cleanup!
|
34
|
-
f = Marvin::
|
34
|
+
f = pids_file_for(Marvin::Loader.type)
|
35
35
|
FileUtils.rm_f(f) if (pids_from(f) - Process.pid).blank?
|
36
36
|
end
|
37
37
|
|
@@ -50,7 +50,7 @@ module Marvin
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def pid_file_for(type)
|
53
|
-
Marvin::Settings.root / "tmp/pids/marvin-#{type.to_s.underscore}.pid"
|
53
|
+
Marvin::Settings.root / "tmp" / "pids" / "marvin-#{type.to_s.underscore}.pid"
|
54
54
|
end
|
55
55
|
|
56
56
|
def pids_from(file)
|
data/lib/marvin/irc/server.rb
CHANGED
@@ -39,7 +39,7 @@ module Marvin
|
|
39
39
|
autoload :VirtualUserConnection, 'marvin/irc/server/virtual_user_connection'
|
40
40
|
autoload :AbstractConnection, 'marvin/irc/server/abstract_connection'
|
41
41
|
autoload :UserConnection, 'marvin/irc/server/user_connection'
|
42
|
-
autoload :ServerConnection, 'marvin/irc/server/server_connection'
|
42
|
+
# autoload :ServerConnection, 'marvin/irc/server/server_connection'
|
43
43
|
# Extensions for each part
|
44
44
|
autoload :User, 'marvin/irc/server/user'
|
45
45
|
|
data/lib/marvin/logger.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
module Marvin
|
2
|
+
# A generic class to make it easy to implement loggers
|
3
|
+
# in marvin. Users only need to implement 1 method for simple
|
4
|
+
# logging but have control to do more. Please note that
|
5
|
+
# if you want it correctly log the order of messages, it
|
6
|
+
# needs to be the first registered handler, otherwise
|
7
|
+
# outgoing messages will be processed before incoming ones.
|
8
|
+
class LoggingHandler < CommandHandler
|
9
|
+
|
10
|
+
on_event :incoming_message do
|
11
|
+
if should_log?
|
12
|
+
log_incoming(@server, options.nick, options.target, options.message)
|
13
|
+
log_message(@server, options.nick, options.target, options.message)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
on_event :outgoing_message do
|
18
|
+
if should_log?
|
19
|
+
log_outgoing(@server, @nick, options.target, options.message)
|
20
|
+
log_message(@server, @nick, options.target, options.message)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
on_event :client_connected do
|
25
|
+
@server = self.client.host_with_port
|
26
|
+
@nick = self.client.nickname
|
27
|
+
setup_logging
|
28
|
+
end
|
29
|
+
|
30
|
+
on_event :client_disconnected do
|
31
|
+
teardown_logging
|
32
|
+
end
|
33
|
+
|
34
|
+
on_event :outgoing_nick do
|
35
|
+
@nick = options.new_nick
|
36
|
+
end
|
37
|
+
|
38
|
+
# Called when the client connects, over ride it to
|
39
|
+
# do any of your specific setup.
|
40
|
+
def setup_logging
|
41
|
+
# NOP
|
42
|
+
end
|
43
|
+
|
44
|
+
# Called when the client disconnects, over ride it to
|
45
|
+
# do any of your specific teardown.
|
46
|
+
def teardown_logging
|
47
|
+
# NOP
|
48
|
+
end
|
49
|
+
|
50
|
+
# Called before logging a message for conditional logging.
|
51
|
+
# Override with your implementation specific version.
|
52
|
+
def should_log?
|
53
|
+
true
|
54
|
+
end
|
55
|
+
|
56
|
+
# Log an incoming message (i.e. from another user)
|
57
|
+
# Note that +server+ is in the port host:port,
|
58
|
+
# nick is the origin nick and target is either
|
59
|
+
# a channel or the bots nick (if PM'ed)
|
60
|
+
def log_incoming(server, nick, target, message)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Log an outgoing message (i.e. from this user)
|
64
|
+
# Note that +server+ is in the port host:port,
|
65
|
+
# nick is the bots nick and target is either
|
66
|
+
# a channel or the user the bot is replying to.
|
67
|
+
def log_outgoing(server, nick, target, message)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Logs a message - used when you want to log
|
71
|
+
# both incoming and outgoing messages
|
72
|
+
def log_message(server, nick, target, message)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Sutto-marvin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darcy Laycock
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-05 00:00:00 -07:00
|
13
13
|
default_executable: marvin
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -58,8 +58,8 @@ executables:
|
|
58
58
|
- marvin
|
59
59
|
extensions: []
|
60
60
|
|
61
|
-
extra_rdoc_files:
|
62
|
-
|
61
|
+
extra_rdoc_files:
|
62
|
+
- README.textile
|
63
63
|
files:
|
64
64
|
- README.textile
|
65
65
|
- TUTORIAL.textile
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/marvin/base.rb
|
72
72
|
- lib/marvin/command_handler.rb
|
73
73
|
- lib/marvin/console.rb
|
74
|
+
- lib/marvin/core_commands.rb
|
74
75
|
- lib/marvin/core_ext.rb
|
75
76
|
- lib/marvin/daemon.rb
|
76
77
|
- lib/marvin/data_store.rb
|
@@ -83,7 +84,6 @@ files:
|
|
83
84
|
- lib/marvin/exception_tracker.rb
|
84
85
|
- lib/marvin/exceptions.rb
|
85
86
|
- lib/marvin/handler.rb
|
86
|
-
- lib/marvin/hookable.rb
|
87
87
|
- lib/marvin/irc
|
88
88
|
- lib/marvin/irc/client.rb
|
89
89
|
- lib/marvin/irc/event.rb
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- lib/marvin/irc.rb
|
104
104
|
- lib/marvin/loader.rb
|
105
105
|
- lib/marvin/logger.rb
|
106
|
+
- lib/marvin/logging_handler.rb
|
106
107
|
- lib/marvin/middle_man.rb
|
107
108
|
- lib/marvin/options.rb
|
108
109
|
- lib/marvin/parsers
|
@@ -138,16 +139,19 @@ files:
|
|
138
139
|
- handlers/debug_handler.rb
|
139
140
|
- handlers/hello_world.rb
|
140
141
|
- handlers/logging_handler.rb
|
142
|
+
- handlers/powwow_handler.rb
|
143
|
+
- handlers/simple_logger.rb
|
141
144
|
- handlers/tweet_tweet.rb
|
142
145
|
- config/setup.rb
|
143
146
|
- config/boot.rb
|
144
147
|
- config/settings.yml.sample
|
145
148
|
- config/connections.yml.sample
|
146
|
-
has_rdoc:
|
149
|
+
has_rdoc: true
|
147
150
|
homepage: http://blog.ninjahideout.com/
|
148
151
|
post_install_message:
|
149
|
-
rdoc_options:
|
150
|
-
|
152
|
+
rdoc_options:
|
153
|
+
- --inline-source
|
154
|
+
- --charset=UTF-8
|
151
155
|
require_paths:
|
152
156
|
- lib
|
153
157
|
required_ruby_version: !ruby/object:Gem::Requirement
|