From 349371e4c13e619b787fb4ab5a3dfcde95fd355e Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 21 Apr 2014 05:16:29 -0700 Subject: Persistent storing of admin list (allows reload). --- core/store.rb | 1 + module/admin.rb | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/core/store.rb b/core/store.rb index 4d5e9a7..856acee 100644 --- a/core/store.rb +++ b/core/store.rb @@ -6,6 +6,7 @@ module Dinobot attr_accessor :data def initialize(file) + Dir.mkdir(File.dirname(file)) unless Dir.exist?(File.dirname(file)) @store = PStore.new(file, true) read diff --git a/module/admin.rb b/module/admin.rb index f700a74..768d4f6 100644 --- a/module/admin.rb +++ b/module/admin.rb @@ -1,4 +1,5 @@ require_relative 'base' +require_relative '../core/store' module Dinobot module Module @@ -6,18 +7,27 @@ module Dinobot def initialize(bot) super + @store = Dinobot::Core::Store.new('data/admin') + @commands << :join << :part << :quit << :load << :unload @commands << :listadmins << :listmodules << :listchannels - @admins = Array.new + @admins = @store.data[:admins] + @admins ||= Array.new end def add(user) @admins << user unless @admins.include?(user) + + @store.data[:admins] = @admins + @store.save end def remove(user) @admins.delete(user) + + @store.data[:admins] = @admins + @store.save end def is_admin?(user) @@ -43,12 +53,6 @@ module Dinobot [[:quit, argument ? argument.strip : 'Quitting.']] end - def listadmins(user, channel, argument) - return unless is_admin?(user) - - [[:say, channel, @admins.join(' ')]] - end - def load(user, channel, argument) return unless is_admin?(user) @@ -69,6 +73,12 @@ module Dinobot nil end + def listadmins(user, channel, argument) + return unless is_admin?(user) + + [[:say, channel, @admins.join(' ')]] + end + def listmodules(user, channel, argument) return unless is_admin?(user) -- cgit v1.2.3-70-g09d2