module ChannelTrust
Constants
- BOTS_CONFIG_DIR
Public Instance Methods
Source
# File lib/channel_trust.rb, line 20 def bot_nick?(nick, bot_nicks: persona_bot_nicks) target = RabbotDb.normalize_nick(nick).downcase bot_nicks.any? { |candidate| candidate.casecmp?(target) } end
Source
# File lib/channel_trust.rb, line 93 def channel_name(channel) channel.respond_to?(:name) ? channel.name : channel.to_s end
Source
# File lib/channel_trust.rb, line 64 def human_admin_nick?(network:, channel:, nick:, is_op: false, bot_nicks: persona_bot_nicks) return false if bot_nick?(nick, bot_nicks: bot_nicks) RabbotDb.user_allowed_at_level?( network: network, channel: channel, nick: nick, is_op: is_op, minimum: RabbotDb::LEVEL_ADMIN ) end
Source
# File lib/channel_trust.rb, line 89 def idea_source?(nick, idea_sources) Array(idea_sources).any? { |source| source.to_s.casecmp?(nick.to_s) } end
Source
# File lib/channel_trust.rb, line 97 def load_persona_bot_nicks nicks = [] Dir.glob(File.join(BOTS_CONFIG_DIR, "*.yml")).each do |path| next if File.basename(path) == "example.yml" data = YAML.safe_load(File.read(path), permitted_classes: [], aliases: true) next unless data.is_a?(Hash) nicks << data["nick"] if data["nick"] nicks.concat(Array(data["nicks"])) nicks << data["preferred_nick"] if data["preferred_nick"] end nicks.compact.map { |nick| RabbotDb.normalize_nick(nick) }.reject(&:empty?).uniq rescue StandardError %w[Rabbot Steve Dr_Weird HappyTimeHarry] end
Source
# File lib/channel_trust.rb, line 12 def persona_bot_nicks @persona_bot_nicks ||= load_persona_bot_nicks end
Source
# File lib/channel_trust.rb, line 76 def registered_owner_nick?(network:, channel:, nick:, bot_nicks: persona_bot_nicks) return false if bot_nick?(nick, bot_nicks: bot_nicks) user = RabbotDb.registered_channel_user( network: network, channel: channel_name(channel), nick: nick ) return false unless user user.level.to_s == RabbotDb::LEVEL_OWNER end
Source
# File lib/channel_trust.rb, line 16 def reload_persona_bot_nicks! @persona_bot_nicks = load_persona_bot_nicks end
Source
# File lib/channel_trust.rb, line 53 def stranger_nick?(nick:, channel:, user:, network:, idea_sources: [], bot_nicks: persona_bot_nicks) !trusted_nick?( nick: nick, channel: channel, user: user, network: network, idea_sources: idea_sources, bot_nicks: bot_nicks ) end
Source
# File lib/channel_trust.rb, line 42 def trusted_context_nick?(nick:, channel:, user:, network:, idea_sources: [], bot_nicks: persona_bot_nicks) trusted_nick?( nick: nick, channel: channel, user: user, network: network, idea_sources: idea_sources, bot_nicks: bot_nicks ) end
Source
# File lib/channel_trust.rb, line 25 def trusted_nick?(nick:, channel:, user:, network:, idea_sources: [], bot_nicks: persona_bot_nicks) return true if bot_nick?(nick, bot_nicks: bot_nicks) return true if idea_source?(nick, idea_sources) if channel.respond_to?(:opped?) return true if AiAccess.channel_opped?(channel, user) return true if AiAccess.channel_voiced?(channel, user) end RabbotDb.user_allowed_at_level?( network: network, channel: channel_name(channel), nick: nick, is_op: false, minimum: RabbotDb::LEVEL_VOICE ) end