From 29cc359a91d8f73f9a2f4e47646e691bfe117346 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 14 Apr 2014 05:48:01 -0700 Subject: Add very basic admin support. --- admin.rb | 34 ++++++++++++++++++++++++++++++++++ dinobot.rb | 4 +++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 admin.rb diff --git a/admin.rb b/admin.rb new file mode 100644 index 0000000..3fc0338 --- /dev/null +++ b/admin.rb @@ -0,0 +1,34 @@ +require_relative 'module' + +module Dinobot + class Admin < Module + def initialize + super + + @commands << :join << :part + + @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) + [[:join, argument]] if is_admin?(user) + end + + def part(user, channel, argument) + [[:part, argument]] if is_admin?(user) + end + end +end diff --git a/dinobot.rb b/dinobot.rb index 01eeeab..4828aac 100644 --- a/dinobot.rb +++ b/dinobot.rb @@ -68,7 +68,9 @@ module Dinobot mod = message.split.first.downcase.intern if @modules.has_key?(mod) - exec_commands(@modules[mod].call(user, channel, message)) + commands = @modules[mod].call(user, channel, message) + + exec_commands(commands) unless commands.nil? end end end -- cgit v1.2.3-70-g09d2