Module: Cinch::Admin

Constant Summary collapse

TYPES =

Valid symbols for bot admin types

[:admins, :trusted]

Instance Method Summary collapse

Methods included from Helpers

#check_user, #is_channel_disabled?, table_format

Instance Method Details

#add_admin(mask) ⇒ Object

Examples:

add_admin('*!*@unaffiliated/azure')

See Also:

  • #add_action

13
# File 'lib/cinch/admin.rb', line 13

def add_admin (mask); add_action(mask, :admins); end

#add_trusted(mask) ⇒ Object

See Also:


22
# File 'lib/cinch/admin.rb', line 22

def add_trusted (mask); add_action(mask, :trusted); end

#delete_admin(mask) ⇒ Object

Examples:

delete_admin('*!*@unaffiliated/azure')

See Also:

  • #delete_action

17
# File 'lib/cinch/admin.rb', line 17

def delete_admin (mask); delete_action(mask, :admins); end

#delete_trusted(mask) ⇒ Object

See Also:


24
# File 'lib/cinch/admin.rb', line 24

def delete_trusted (mask); delete_action(mask, :trusted); end

#each_controlchannel {|channel| ... } ⇒ Object

Note:

`:controlchannel` may be either an array or a string. Channel keys are separated by spaces.

Yields all control channels listed in the shared config entry :controlchannel. The bot will join any control channel that it is not in yet.

Yields:

  • (channel)

    All control channels


54
55
56
57
58
59
60
61
# File 'lib/cinch/admin.rb', line 54

def each_controlchannel
  Array[*shared[:controlchannel]].each {|channel| 
    chan, key = channel.split(' ')
    c = Channel(chan)
    c.join(key) if !@bot.channels.include?(chan)
    yield c
  }
end

#each_online_admin {|user| ... } ⇒ Object

Yields all online users that are bot admins within all control channels.

Yields:

  • (user)

    Users that are bot admins.


65
66
67
68
69
70
71
# File 'lib/cinch/admin.rb', line 65

def each_online_admin
  each_controlchannel {|channel|
    channel.users.each {|user, modes|
      yield(user) if is_admin?(user)
    }
  }
end

#each_online_trustedObject

See Also:


74
75
76
77
78
79
80
# File 'lib/cinch/admin.rb', line 74

def each_online_trusted
  each_controlchannel {|channel|
    channel.users.each {|user, modes|
      yield(user) if is_trusted?(user)
    }
  }
end

#get_adminsObject

See Also:

  • #get_action

19
# File 'lib/cinch/admin.rb', line 19

def get_admins; get_action(:admins); end

#get_trustedObject

See Also:

  • #get_action

26
# File 'lib/cinch/admin.rb', line 26

def get_trusted; get_action(:trusted); end

#is_admin?(user) ⇒ Boolean

Fetches all stored hostmasks for the bot's per-network ADMIN group and performs a comparison between the supplied User object and each hostmask.


32
33
34
35
36
# File 'lib/cinch/admin.rb', line 32

def is_admin? (user)
  get_admins.any? {|admin|
    user =~ admin
  } && user.authed?
end

#is_trusted?(user) ⇒ Boolean

See Also:


39
40
41
42
43
# File 'lib/cinch/admin.rb', line 39

def is_trusted? (user)
  get_trusted.any? {|trusted|
    user =~ trusted
  } && user.authed?
end

#no_admins?Boolean


46
47
48
# File 'lib/cinch/admin.rb', line 46

def no_admins?
  shared[:redis].scard("bot.%s:admins" % @bot.irc.isupport['NETWORK'].downcase) == 0
end