From 7f134adccb20abe773234acecf526c9951b418e8 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sun, 20 Apr 2014 04:23:20 -0700 Subject: Improved namespace and directory structure. --- module/admin.rb | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 module/admin.rb (limited to 'module/admin.rb') diff --git a/module/admin.rb b/module/admin.rb new file mode 100644 index 0000000..d59fd49 --- /dev/null +++ b/module/admin.rb @@ -0,0 +1,79 @@ +require_relative 'module' + +module Dinobot + module Module + class Admin < Module + def initialize(bot) + super + + @commands << :join << :part << :load << :unload + @commands << :listadmins << :listmodules << :listchannels + + @admins = Array.new + end + + def add(user) + @admins << user unless @admins.include?(user) + end + + def remove(user) + @admins.delete(user) + end + + def is_admin?(user) + # FIXME: Using hostname for testing purposes. Need better solution. + @admins.include?(user.sub(/.+@/, '')) + end + + def join(user, channel, argument) + return unless is_admin?(user) + + [[:join, argument.strip]] + end + + def part(user, channel, argument) + return unless is_admin?(user) + + [[:part, argument.strip]] + 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) + + argument.split.each do |x| + @bot.load_module x.intern + end + + nil + end + + def unload(user, channel, argument) + return unless is_admin?(user) + + argument.split.each do |x| + @bot.unload_module x.intern + end + + nil + end + + def listmodules(user, channel, argument) + return unless is_admin?(user) + + [[:say, channel, "Modules: #{@bot.modules.keys.sort.join(' ')}"]] + end + + def listchannels(user, channel, argument) + return unless is_admin?(user) + + [[:say, channel, "Channels: #{@bot.channels.sort.join(' ')}"]] + end + end + end +end -- cgit v1.2.3-70-g09d2