Class: ESM::Community

Inherits:
ApplicationRecord show all
Defined in:
lib/esm/model/community.rb

Constant Summary collapse

ESM_ID =
"452568470765305866"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.community_idsObject



7
8
9
10
11
# File 'lib/esm/model/community.rb', line 7

def self.community_ids
  ESM.cache.fetch("community_ids", expires_in: ESM.config.cache.community_ids) do
    ESM::Database.with_connection { pluck(:community_id) }
  end
end

Instance Method Details

#discord_serverObject



19
20
21
22
23
# File 'lib/esm/model/community.rb', line 19

def discord_server
  ESM.bot.server(guild_id)
rescue
  nil
end

#log_event(event, message) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/esm/model/community.rb', line 25

def log_event(event, message)
  return if logging_channel_id.blank?

  # Only allow logging events to logging channel if permission has been given
  case event
  when :xm8
    return if !log_xm8_event
  when :discord_log
    return if !log_discord_log_event
  when :reconnect
    return if !log_reconnect_event
  when :error
    return if !log_error_event
  else
    raise ESM::Exception::Error, "Attempted to log :#{event} to #{guild_id} without explicit permission.\nMessage:\n#{message}"
  end

  # Check this first to avoid an infinite loop if the bot cannot send a message to this channel
  # since this method is called from the #deliver method for this exact reason.
  channel = logging_channel
  return if channel.nil?

  ESM.bot.deliver(message, to: channel)
end

#logging_channelObject



13
14
15
16
17
# File 'lib/esm/model/community.rb', line 13

def logging_channel
  ESM.bot.channel(logging_channel_id)
rescue
  nil
end

#modifiable_by?(guild_member) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
# File 'lib/esm/model/community.rb', line 50

def modifiable_by?(guild_member)
  return true if guild_member.permission?(:administrator) || guild_member.owner?

  # Check for roles
  dashboard_access_role_ids.any? { |role_id| guild_member.role?(role_id) }
end