Module: Blur::Script::MessageParsing
- Defined in:
- library/blur/script/messageparsing.rb
Overview
The MessageParsing module is a module that gives the ability to turn a script into a DSL-like framework.
What it does is automatically test to see if a message starts with a trigger, and then, if so, it sends the command-part of the message to the script object itself.
This way, the plugin-writer doesn't need to have repetetive code like that in every script.
Constant Summary
- MessageTrigger =
The prefix that turns it into a possible command.
"."
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (Object) message(user, channel, line)
Handle all calls to the scripts message method, check to see if the message containts a valid command, serialize it and pass it to the script as command_name with the parameters user, channel and message.
-
- (Object) serialize(name)
protected
Strip all non-word characters from the input command.
Class Method Details
+ (Object) extended(klass)
34 35 36 |
# File 'library/blur/script/messageparsing.rb', line 34 def self.extended klass warn "#{File.realpath __FILE__}: MessageParsing will be deprecated in the future, use Fantasy." end |
Instance Method Details
- (Object) message(user, channel, line)
Handle all calls to the scripts message method, check to see if the message containts a valid command, serialize it and pass it to the script as command_name with the parameters user, channel and message.
42 43 44 45 46 47 48 49 50 51 |
# File 'library/blur/script/messageparsing.rb', line 42 def user, channel, line return unless line.start_with? MessageTrigger command, args = line.split $;, 2 name = :command_#{serialize command}" if respond_to? name __send__ name, user, channel, args end end |
- (Object) serialize(name) (protected)
Strip all non-word characters from the input command.
56 57 58 |
# File 'library/blur/script/messageparsing.rb', line 56 def serialize name name.gsub /\W/, '' if name end |