Class: Rubot::Core::Command
Overview
Base class that handles the dirty work for IRC commands.
Instance Method Summary collapse
-
#initialize(dispatcher) ⇒ Command
constructor
Takes an instance of Rubot::Core::Dispatcher.
-
#protected? ⇒ Boolean
Whether the command is marked as protected or not (using Command::acts_as_protected).
-
#run(server, message) ⇒ Object
Runs the command with the given server and message.
Constructor Details
#initialize(dispatcher) ⇒ Command
Takes an instance of Rubot::Core::Dispatcher. Any child class that needs a constructor should override this method.
Parameters
- dispatcher<Rubot::Core::Dispatcher>
-
The dispatcher that was used to create
the instance of the command.
17 18 19 |
# File 'lib/core/command.rb', line 17 def initialize(dispatcher) @dispatcher = dispatcher end |
Instance Method Details
#protected? ⇒ Boolean
Whether the command is marked as protected or not (using Command::acts_as_protected).
47 48 49 |
# File 'lib/core/command.rb', line 47 def protected? false end |
#run(server, message) ⇒ Object
Runs the command with the given server and message.
Parameters
- server<Rubot::Irc::Server>
-
Server instance the command should use for
messaging and information.
- message<Rubot::Irc::Message>
-
The message that invoked the command.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/core/command.rb', line 27 def run(server, ) if protected? && !.authenticated server.msg(.destination, "unauthorized") return end args = Shellwords.shellwords(.body.gsub(/(')/n, "\\\\\'")) = parse(args) if .help # this to_s.lines.to_a business is a hack to not display the -h, --help line # there's got to be an easier/better way to do this. but it'll work for now server.msg(.destination, .help.to_s.lines.to_a[0..-2]) else .body = args.join(" ") execute(server, , ) end end |