aboutsummaryrefslogtreecommitdiff
path: root/admin.rb
blob: 3cffd1f588599ae712858b470784688842bc8372 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require_relative 'module'

module Dinobot
  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
    end

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

      argument.split.each do |x|
        @bot.unload_module x.intern
      end
    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