aboutsummaryrefslogtreecommitdiff
path: root/admin.rb
blob: fceaa26a06369d7bdcd9cb7691d2a642f5217fbe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require_relative 'module'

module Dinobot
  class Admin < Module
    def initialize
      super

      @commands << :join << :part << :listadmins << :load << :unload

      @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

    def listadmins(user, channel, argument)
      [[:say, channel, @admins.join(' ')]] if is_admin?(user)
    end

    def load(user, channel, argument)
      return unless is_admin?(user)

      argument.split.map { |x| [:load_module, x.intern] }
    end

    def unload(user, channel, argument)
      return unless is_admin?(user)

      argument.split.map { |x| [:unload_module, x.intern] }
    end
  end
end