diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-21 13:02:19 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-21 13:02:19 -0700 |
commit | 8fd8c27562184a18000d32d96921fbb0ca8045be (patch) | |
tree | 63236407917f5197637cef67b5153ce371bbcdc2 /dinobot.rb | |
parent | 6ff901dfe723b58ad13a2e3693473d934f5751b2 (diff) | |
download | dinobot-8fd8c27562184a18000d32d96921fbb0ca8045be.tar.gz dinobot-8fd8c27562184a18000d32d96921fbb0ca8045be.tar.xz |
Add some basic command aliasing support.
Diffstat (limited to 'dinobot.rb')
-rw-r--r-- | dinobot.rb | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -4,6 +4,7 @@ require_relative 'core/config' require_relative 'core/irc' require_relative 'core/logger' require_relative 'core/messageinfo' +require_relative 'core/store' module Dinobot class Bot @@ -19,6 +20,7 @@ module Dinobot @irc = Dinobot::Core::IRC.new(@server, @port, @nick, @pass) @config = Dinobot::Core::Config.instance @logger = Dinobot::Core::Logger.instance + @aliases = Dinobot::Core::Store.new('data/aliases') @modules = Hash.new @channels = Array.new @@ -95,6 +97,20 @@ module Dinobot end end + def add_alias(from, to) + @aliases.data[:global] = Hash.new unless @aliases.data[:global] + + @aliases.data[:global][from] = to + @aliases.save + end + + def remove_alias(from) + return unless @aliases.data[:global] + + @aliases.data[:global].delete(from) + @aliases.save + end + private def process_in_new_thread(str) @@ -130,6 +146,13 @@ module Dinobot end def exec_command(m, command) + # FIXME: Improve and add debug output. + if @aliases.data[:global] + @aliases.data[:global].each do |k, v| + command.sub!(/\A#{Regexp.escape(k)}\b/, v) + end + end + command, remainder = command.split(' | ', 2) mod = command.scan(/\A\S+/).first.downcase |