diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/aliaser.rb | 53 | ||||
-rw-r--r-- | core/config.rb | 2 | ||||
-rw-r--r-- | core/irc.rb | 3 |
3 files changed, 55 insertions, 3 deletions
diff --git a/core/aliaser.rb b/core/aliaser.rb new file mode 100644 index 0000000..b867e10 --- /dev/null +++ b/core/aliaser.rb @@ -0,0 +1,53 @@ +require_relative 'store' + +module Dinobot + module Core + class Aliaser + attr_accessor :data + + @@instance = nil + @@mutex = Mutex.new + + def initialize + @store = Dinobot::Core::Store.new('aliaser.db') + @data = @store.data + end + + def add(from, to, channel=:global) + @data[channel] = Hash.new unless @data.key?(channel) + @data[channel][from] = to + + save + end + + def remove(from, channel=:global) + return unless data.key?(channel) + + @data[channel].delete(from) + @data.delete(channel) if @data[channel].empty? + + save + end + + def aliases + @data.dup + end + + def save + @store.save + end + + class << self + def instance + return @@instance if @@instance + + @@mutex.synchronize do + @@instance ||= new + end + end + end + + private_class_method :allocate, :new + end + end +end diff --git a/core/config.rb b/core/config.rb index 36511ed..236b3d9 100644 --- a/core/config.rb +++ b/core/config.rb @@ -9,7 +9,7 @@ module Dinobot @@mutex = Mutex.new def initialize - @store = Dinobot::Core::Store.new('config') + @store = Dinobot::Core::Store.new('config.db') @data = @store.data if @data.empty? diff --git a/core/irc.rb b/core/irc.rb index fdb2ad7..d682299 100644 --- a/core/irc.rb +++ b/core/irc.rb @@ -17,7 +17,6 @@ module Dinobot def connect @logger.info "Connecting to #{@server}:#{@port}." - @socket = TCPSocket.new(@server, @port) puts "PASS #{@pass}" if @pass @@ -26,6 +25,7 @@ module Dinobot end def disconnect + @logger.info 'Disconnecting.' @socket.close end @@ -44,7 +44,6 @@ module Dinobot def puts(str) @logger.out str.inspect - @socket.puts str end |