class RabbotDb
RabbotDb adapter — database-agnostic query helpers. Public: normalize_sql, row_count Depends: (none) Tests: test/rabbot_db_test.rb
RabbotDb bots — bot identity records for multi-persona PostgreSQL storage. Public: ensure_bot!, find_bot, list_bots Depends: rabbot_db/connection Tests: test/rabbot_db_test.rb, test/lib/bot_mesh_test.rb
RabbotDb migrations — PostgreSQL schema versioning. Public: (none — private migrate! helpers) Depends: RabbotDb constants Tests: test/rabbot_db_test.rb
RabbotDb test support — PostgreSQL test database helpers. Public: available?, reset!, with_test_db Depends: rabbot_db Tests: (self)
Constants
- ChannelInfo
- ChannelUser
- DEFAULT_LEVEL
- DEFAULT_PATH
- LEGACY_AUTOOP_PATH
- LEVELS
- LEVEL_ADMIN
- LEVEL_HALFOP
- LEVEL_OWNER
- LEVEL_RANK
- LEVEL_SUPERADMIN
- LEVEL_USER
- LEVEL_VOICE
- LIST_AUTOOP
- LIST_AUTOVOICE
- MUTEX
- RegisteredUser
- SCHEMA_VERSION
Public Class Methods
Source
# File lib/rabbot_db/channels.rb, line 84 def add_list_nick(network:, channel:, list_type:, nick:) nick = normalize_nick(nick) with_connection do |db| channel_id = ensure_channel!(db, network: network, channel: channel) position = db.get_first_value( "SELECT COALESCE(MAX(position), -1) + 1 FROM channel_lists WHERE channel_id = ? AND list_type = ?", [channel_id, list_type] ) db.execute( "INSERT INTO channel_lists (channel_id, list_type, nick, position) VALUES (?, ?, ?, ?) " \ "ON CONFLICT (channel_id, list_type, nick) DO NOTHING", [channel_id, list_type, nick, position] ) db.changes.positive? end end
Source
# File lib/rabbot_db/channels.rb, line 139 def autoop_channel_state(network:, channel:, default_nicks: []) { "nicks" => begin nicks = list_nicks(network: network, channel: channel, list_type: LIST_AUTOOP) nicks.empty? ? default_nicks.dup : nicks end, "total" => autoop_total(network: network, channel: channel) } end
Source
# File lib/rabbot_db/channels.rb, line 123 def autoop_total(network:, channel:) info = channel_info(network: network, channel: channel) info ? info.autoop_total : 0 end
Source
# File lib/rabbot_db/channels.rb, line 168 def autovoice_enabled?(network:, channel:) info = channel_info(network: network, channel: channel) info ? info.autovoice : false end
Source
# File lib/rabbot_db/channels.rb, line 31 def channel_info(network:, channel:, bot_id: current_bot_id) network = normalize_network(network) channel = normalize_channel(channel) bot_id = bot_id.to_s.strip.empty? ? current_bot_id : bot_id.to_s with_connection do |db| row = db.get_first_row( "SELECT network, channel, last_topic, last_topic_nick, last_topic_at, autovoice, autoop_total " \ "FROM channels WHERE bot_id = ? AND network = ? AND channel = ?", [bot_id, network, channel] ) return nil unless row ChannelInfo.new( network: row["network"], channel: row["channel"], last_topic: row["last_topic"], last_topic_nick: row["last_topic_nick"], last_topic_at: row["last_topic_at"], autovoice: row["autovoice"].to_i == 1, autoop_total: row["autoop_total"].to_i ) end end
Source
# File lib/rabbot_db/users.rb, line 72 def channel_user(network:, channel:, nick:) network = normalize_network(network) channel = normalize_channel(channel) nick = normalize_nick(nick) with_connection do |db| row = db.get_first_row(<<~SQL, [current_bot_id, network, channel, nick]) SELECT cu.nick, cu.last_message, cu.last_message_at, cu.last_action, cu.last_action_at, cu.last_part_message, cu.last_part_at, cu.registered_at, cu.level, c.network, c.channel FROM channel_users cu JOIN channels c ON c.id = cu.channel_id WHERE c.bot_id = ? AND c.network = ? AND c.channel = ? AND lower(cu.nick) = lower(?) SQL return nil unless row ChannelUser.new( network: row["network"], channel: row["channel"], nick: row["nick"], last_message: row["last_message"], last_message_at: row["last_message_at"], last_action: row["last_action"], last_action_at: row["last_action_at"], last_part_message: row["last_part_message"], last_part_at: row["last_part_at"], registered_at: row["registered_at"], level: row["level"] || DEFAULT_LEVEL ) end end
Source
# File lib/rabbot_db/connection.rb, line 52 def connection MUTEX.synchronize do @connection ||= open_connection end end
Source
# File lib/rabbot_db.rb, line 105 def current_bot_id @current_bot_id || "rabbot" end
Defined here (not only in connection.rb) so lib_reload cannot leave channels/plugin_data with current_bot_id defaults while connection.rb fails to load.
Source
# File lib/rabbot_db.rb, line 109 def current_bot_id=(bot_id) @current_bot_id = bot_id.to_s.strip.empty? ? "rabbot" : bot_id.to_s end
Source
# File lib/rabbot_db/connection.rb, line 13 def database_url @database_url || ENV["RABBOT_DATABASE_URL"] || default_database_url end
Source
# File lib/rabbot_db/connection.rb, line 17 def database_url=(url) @database_url = url.to_s.strip.empty? ? nil : url.to_s end
Source
# File lib/rabbot_db/connection.rb, line 22 def db_path @db_path || DEFAULT_PATH end
Legacy SQLite path — kept for test compatibility; maps to database_url when set.
Source
# File lib/rabbot_db/connection.rb, line 26 def db_path=(path) @db_path = path end
Source
# File lib/rabbot_db/bots.rb, line 10 def ensure_bot!(bot_id:, config_user: nil, nick: nil) bot_id = bot_id.to_s.strip return nil if bot_id.empty? config_user = config_user.to_s.strip nick = nick.to_s.strip now = iso_time with_connection do |db| db.execute(<<~SQL, [bot_id, config_user, nick, now]) INSERT INTO bots (bot_id, config_user, nick, created_at) VALUES (?, ?, ?, ?) ON CONFLICT (bot_id) DO UPDATE SET config_user = CASE WHEN excluded.config_user = '' THEN bots.config_user ELSE excluded.config_user END, nick = CASE WHEN excluded.nick = '' THEN bots.nick ELSE excluded.nick END SQL find_bot(bot_id: bot_id, db: db) end end
Source
# File lib/rabbot_db/channels.rb, line 15 def ensure_channel!(db, network:, channel:, bot_id: current_bot_id) network = normalize_network(network) channel = normalize_channel(channel) bot_id = bot_id.to_s.strip.empty? ? current_bot_id : bot_id.to_s row = db.get_first_row( "SELECT id FROM channels WHERE bot_id = ? AND network = ? AND channel = ?", [bot_id, network, channel] ) return row["id"] if row db.get_first_value( "INSERT INTO channels (bot_id, network, channel) VALUES (?, ?, ?) RETURNING id", [bot_id, network, channel] ) end
Source
# File lib/rabbot_db/users.rb, line 204 def ensure_default_registered_users!(network:, channel:, default_users:) return unless registered_users(network: network, channel: channel).empty? default_users.each do |nick, level| register_user(network: network, channel: channel, nick: nick, level: level) end end
Source
# File lib/rabbot_db/bots.rb, line 29 def find_bot(bot_id:, db: nil) bot_id = bot_id.to_s.strip return nil if bot_id.empty? if db row = db.get_first_row("SELECT bot_id, config_user, nick, created_at FROM bots WHERE bot_id = ?", [bot_id]) return bot_row(row) if row return nil end with_connection { |conn| find_bot(bot_id: bot_id, db: conn) } end
Source
# File lib/rabbot_db/channels.rb, line 113 def find_list_nick(network:, channel:, list_type:, nick:) target = normalize_nick(nick).downcase list_nicks(network: network, channel: channel, list_type: list_type) .find { |listed| listed.casecmp?(target) } end
Source
# File lib/rabbot_db/plugin_data.rb, line 53 def get_group_plugin_json(group_id:, plugin:, key:, network:, channel:, default: nil) scope = "bot_group" network = normalize_network(network) channel = normalize_channel(channel) with_connection do |db| row = db.get_first_row(<<~SQL, [plugin.to_s, key.to_s, scope, group_id.to_i, network, channel]) SELECT value FROM plugin_data WHERE plugin = ? AND key = ? AND scope = ? AND bot_id = '' AND group_id = ? AND network = ? AND channel = ? AND nick = '' SQL raw = row&.[]("value") return default if raw.nil? || raw.to_s.strip.empty? JSON.parse(raw) end rescue JSON::ParserError default end
Source
# File lib/rabbot_db/plugin_data.rb, line 30 def get_plugin_json(plugin:, key:, network: nil, channel: nil, nick: nil, default: nil, bot_id: current_bot_id) raw = get_plugin_value( plugin: plugin, key: key, network: network, channel: channel, nick: nick, bot_id: bot_id ) return default if raw.nil? || raw.to_s.strip.empty? JSON.parse(raw) rescue JSON::ParserError default end
Source
# File lib/rabbot_db/plugin_data.rb, line 13 def get_plugin_value(plugin:, key:, network: nil, channel: nil, nick: nil, bot_id: current_bot_id) scope = plugin_scope(network: network, channel: channel, nick: nick) network = network.nil? ? "" : normalize_network(network) channel = channel.nil? ? "" : normalize_channel(channel) nick = nick.nil? ? "" : normalize_nick(nick) bot_id = bot_id.to_s.strip.empty? ? current_bot_id : bot_id.to_s with_connection do |db| row = db.get_first_row(<<~SQL, [plugin.to_s, key.to_s, scope, bot_id, network, channel, nick]) SELECT value FROM plugin_data WHERE plugin = ? AND key = ? AND scope = ? AND bot_id = ? AND group_id = 0 AND network = ? AND channel = ? AND nick = ? SQL row&.[]("value") end end
Source
# File lib/rabbot_db/channels.rb, line 128 def increment_autoop_total(network:, channel:) with_connection do |db| channel_id = ensure_channel!(db, network: network, channel: channel) db.execute( "UPDATE channels SET autoop_total = COALESCE(autoop_total, 0) + 1 WHERE id = ?", [channel_id] ) db.get_first_value("SELECT autoop_total FROM channels WHERE id = ?", [channel_id]).to_i end end
Source
# File lib/rabbot_db.rb, line 91 def iso_time(time = Time.now) time.utc.iso8601 end
Source
# File lib/rabbot_db.rb, line 87 def level_at_least?(level, minimum) level_rank(level) >= level_rank(minimum) end
Source
# File lib/rabbot_db.rb, line 83 def level_rank(level) LEVEL_RANK.fetch(normalize_level(level) || DEFAULT_LEVEL, 0) end
Source
# File lib/rabbot_db/bots.rb, line 42 def list_bots with_connection do |db| db.execute("SELECT bot_id, config_user, nick, created_at FROM bots ORDER BY bot_id ASC").map do |row| bot_row(row) end end end
Source
# File lib/rabbot_db/channels.rb, line 70 def list_nicks(network:, channel:, list_type:) network = normalize_network(network) channel = normalize_channel(channel) with_connection do |db| db.execute(<<~SQL, [current_bot_id, network, channel, list_type]).map { |row| row["nick"] } SELECT cl.nick FROM channel_lists cl JOIN channels c ON c.id = cl.channel_id WHERE c.bot_id = ? AND c.network = ? AND c.channel = ? AND cl.list_type = ? ORDER BY cl.position ASC, cl.id ASC SQL end end
Source
# File lib/rabbot_db/plugin_data.rb, line 89 def list_plugin_json_by_key_prefix(plugin:, key_prefix:, network: nil, channel: nil, nick: nil, bot_id: current_bot_id) scope = plugin_scope(network: network, channel: channel, nick: nick) network = network.nil? ? "" : normalize_network(network) channel = channel.nil? ? "" : normalize_channel(channel) nick = nick.nil? ? "" : normalize_nick(nick) bot_id = bot_id.to_s.strip.empty? ? current_bot_id : bot_id.to_s pattern = "#{key_prefix.to_s}%" with_connection do |db| rows = db.execute(<<~SQL, [plugin.to_s, pattern, scope, bot_id, network, channel, nick]) SELECT key, value FROM plugin_data WHERE plugin = ? AND key LIKE ? AND scope = ? AND bot_id = ? AND group_id = 0 AND network = ? AND channel = ? AND nick = ? SQL rows.filter_map do |row| value = JSON.parse(row["value"]) { key: row["key"], value: value } rescue JSON::ParserError nil end end end
Source
# File lib/rabbot_db/channels.rb, line 183 def migrate_legacy_autoop_json!(path: LEGACY_AUTOOP_PATH, default_nicks: []) return unless File.file?(path) payload = JSON.parse(File.read(path)) payload.each do |raw_key, channel_state| network, channel = parse_legacy_storage_key(raw_key) next if channel.nil? || channel.empty? existing = list_nicks(network: network, channel: channel, list_type: LIST_AUTOOP) next unless existing.empty? state = channel_state.is_a?(Hash) ? channel_state.dup : {} state["nicks"] = default_nicks.dup if state["nicks"].nil? || state["nicks"].empty? save_autoop_channel_state(network: network, channel: channel, channel_state: state) end backup = "#{path}.migrated" File.rename(path, backup) unless File.exist?(backup) rescue JSON::ParserError, StandardError nil end
Source
# File lib/rabbot_db/channels.rb, line 119 def nick_on_list?(network:, channel:, list_type:, nick:) !find_list_nick(network: network, channel: channel, list_type: list_type, nick: nick).nil? end
Source
# File lib/rabbot_db.rb, line 64 def normalize_channel(channel) Normalize.channel(channel) end
Source
# File lib/rabbot_db.rb, line 72 def normalize_level(level) value = level.to_s.strip.downcase return DEFAULT_LEVEL if value.empty? LEVELS.include?(value) ? value : nil end
Source
# File lib/rabbot_db.rb, line 52 def normalize_network(network) value = if network.respond_to?(:name) network.name.to_s else network.to_s end value = value.strip return "unknown" if value.empty? || value.start_with?("#<") value end
Source
# File lib/rabbot_db.rb, line 68 def normalize_nick(nick) Normalize.nick(nick) end
Source
# File lib/rabbot_db.rb, line 95 def parse_time(value) return nil if value.nil? || value.to_s.strip.empty? Time.parse(value) rescue ArgumentError nil end
Source
# File lib/rabbot_db/users.rb, line 34 def record_action(network:, channel:, nick:, text:, at: Time.now) nick = normalize_nick(nick) text = text.to_s.strip return if nick.empty? || text.empty? with_connection do |db| channel_id = ensure_channel!(db, network: network, channel: channel) now = iso_time(at) db.execute(<<~SQL, [channel_id, nick, text, now, now]) INSERT INTO channel_users (channel_id, nick, last_action, last_action_at, updated_at) VALUES (?, ?, ?, ?, ?) ON CONFLICT(channel_id, nick) DO UPDATE SET last_action = excluded.last_action, last_action_at = excluded.last_action_at, updated_at = excluded.updated_at SQL end end
Source
# File lib/rabbot_db/users.rb, line 15 def record_message(network:, channel:, nick:, text:, at: Time.now) nick = normalize_nick(nick) text = text.to_s.strip return if nick.empty? || text.empty? with_connection do |db| channel_id = ensure_channel!(db, network: network, channel: channel) now = iso_time(at) db.execute(<<~SQL, [channel_id, nick, text, now, now]) INSERT INTO channel_users (channel_id, nick, last_message, last_message_at, updated_at) VALUES (?, ?, ?, ?, ?) ON CONFLICT(channel_id, nick) DO UPDATE SET last_message = excluded.last_message, last_message_at = excluded.last_message_at, updated_at = excluded.updated_at SQL end end
Source
# File lib/rabbot_db/users.rb, line 53 def record_part(network:, channel:, nick:, message: nil, at: Time.now) nick = normalize_nick(nick) return if nick.empty? with_connection do |db| channel_id = ensure_channel!(db, network: network, channel: channel) now = iso_time(at) part_message = message.to_s.strip db.execute(<<~SQL, [channel_id, nick, part_message, now, now]) INSERT INTO channel_users (channel_id, nick, last_part_message, last_part_at, updated_at) VALUES (?, ?, ?, ?, ?) ON CONFLICT(channel_id, nick) DO UPDATE SET last_part_message = excluded.last_part_message, last_part_at = excluded.last_part_at, updated_at = excluded.updated_at SQL end end
Source
# File lib/rabbot_db/channels.rb, line 55 def record_topic(network:, channel:, nick:, topic:, at: Time.now) network = normalize_network(network) channel = normalize_channel(channel) nick = normalize_nick(nick) topic = topic.to_s with_connection do |db| channel_id = ensure_channel!(db, network: network, channel: channel) db.execute( "UPDATE channels SET last_topic = ?, last_topic_nick = ?, last_topic_at = ? WHERE id = ?", [topic, nick, iso_time(at), channel_id] ) end end
Source
# File lib/rabbot_db/users.rb, line 144 def register_user(network:, channel:, nick:, level: DEFAULT_LEVEL, at: Time.now) nick = normalize_nick(nick) level = normalize_level(level) return false if nick.empty? || level.nil? with_connection do |db| channel_id = ensure_channel!(db, network: network, channel: channel) now = iso_time(at) db.execute(<<~SQL, [channel_id, nick, now, level, now]) INSERT INTO channel_users (channel_id, nick, registered_at, level, updated_at) VALUES (?, ?, ?, ?, ?) ON CONFLICT(channel_id, nick) DO UPDATE SET registered_at = excluded.registered_at, level = excluded.level, updated_at = excluded.updated_at SQL true end end
Source
# File lib/rabbot_db/users.rb, line 111 def registered?(network:, channel:, nick:, alternative_nicks: RegisteredUserNicks::DEFAULT_ALTERNATIVE_NICKS) !registered_channel_user( network: network, channel: channel, nick: nick, alternative_nicks: alternative_nicks ).nil? end
Source
# File lib/rabbot_db/users.rb, line 103 def registered_channel_user(network:, channel:, nick:, alternative_nicks: RegisteredUserNicks::DEFAULT_ALTERNATIVE_NICKS) RegisteredUserNicks.find_registered_user( nick: nick, registered_users: registered_users(network: network, channel: channel), alternative_nicks: alternative_nicks ) end
Source
# File lib/rabbot_db/users.rb, line 120 def registered_users(network:, channel:) network = normalize_network(network) channel = normalize_channel(channel) with_connection do |db| rows = db.execute(<<~SQL, [current_bot_id, network, channel]) SELECT cu.nick, cu.level, cu.registered_at FROM channel_users cu JOIN channels c ON c.id = cu.channel_id WHERE c.bot_id = ? AND c.network = ? AND c.channel = ? AND cu.registered_at IS NOT NULL AND cu.registered_at != '' ORDER BY lower(cu.nick) ASC SQL rows .map do |row| RegisteredUser.new( nick: row["nick"], level: row["level"] || DEFAULT_LEVEL, registered_at: row["registered_at"] ) end .sort_by { |user| [-level_rank(user.level), user.nick.downcase] } end end
Source
# File lib/rabbot_db/channels.rb, line 101 def remove_list_nick(network:, channel:, list_type:, nick:) nick = normalize_nick(nick) with_connection do |db| channel_id = ensure_channel!(db, network: network, channel: channel) db.execute( "DELETE FROM channel_lists WHERE channel_id = ? AND list_type = ? AND lower(nick) = lower(?)", [channel_id, list_type, nick] ) db.changes.positive? end end
Source
# File lib/rabbot_db/connection.rb, line 38 def reset!(path: nil, url: nil) MUTEX.synchronize do close_connection! if url self.database_url = url elsif !test_database_url.empty? self.database_url = test_database_url end conn = open_connection @connection = conn truncate_all!(conn) end end
Source
# File lib/rabbot_db/channels.rb, line 149 def save_autoop_channel_state(network:, channel:, channel_state:) nicks = Array(channel_state["nicks"]).map { |nick| normalize_nick(nick) }.reject(&:empty?) total = channel_state.fetch("total", 0).to_i network = normalize_network(network) channel = normalize_channel(channel) with_connection do |db| channel_id = ensure_channel!(db, network: network, channel: channel) db.execute("DELETE FROM channel_lists WHERE channel_id = ? AND list_type = ?", [channel_id, LIST_AUTOOP]) nicks.each_with_index do |nick, index| db.execute( "INSERT INTO channel_lists (channel_id, list_type, nick, position) VALUES (?, ?, ?, ?)", [channel_id, LIST_AUTOOP, nick, index] ) end db.execute("UPDATE channels SET autoop_total = ? WHERE id = ?", [total, channel_id]) end end
Source
# File lib/rabbot_db/channels.rb, line 173 def set_autovoice(network:, channel:, enabled:) with_connection do |db| channel_id = ensure_channel!(db, network: network, channel: channel) db.execute( "UPDATE channels SET autovoice = ? WHERE id = ?", [enabled ? 1 : 0, channel_id] ) end end
Source
# File lib/rabbot_db/plugin_data.rb, line 73 def set_group_plugin_json(group_id:, plugin:, key:, value:, network:, channel:) scope = "bot_group" network = normalize_network(network) channel = normalize_channel(channel) now = iso_time with_connection do |db| db.execute(<<~SQL, [scope, "", group_id.to_i, network, channel, plugin.to_s, key.to_s, JSON.generate(value), now]) INSERT INTO plugin_data (scope, bot_id, group_id, network, channel, nick, plugin, key, value, updated_at) VALUES (?, ?, ?, ?, ?, '', ?, ?, ?, ?) ON CONFLICT(scope, bot_id, group_id, network, channel, nick, plugin, key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at SQL end end
Source
# File lib/rabbot_db/users.rb, line 179 def set_level(network:, channel:, nick:, level:) nick = normalize_nick(nick) level = normalize_level(level) return false if nick.empty? || level.nil? with_connection do |db| channel_id = ensure_channel!(db, network: network, channel: channel) now = iso_time db.execute(<<~SQL, [channel_id, nick, level, now]) INSERT INTO channel_users (channel_id, nick, level, updated_at) VALUES (?, ?, ?, ?) ON CONFLICT(channel_id, nick) DO UPDATE SET level = excluded.level, updated_at = excluded.updated_at SQL true end end
Source
# File lib/rabbot_db/plugin_data.rb, line 41 def set_plugin_json(plugin:, key:, value:, network: nil, channel: nil, nick: nil, bot_id: current_bot_id) set_plugin_value( plugin: plugin, key: key, value: JSON.generate(value), network: network, channel: channel, nick: nick, bot_id: bot_id ) end
Source
# File lib/rabbot_db/plugin_data.rb, line 114 def set_plugin_value(plugin:, key:, value:, network: nil, channel: nil, nick: nil, bot_id: current_bot_id) scope = plugin_scope(network: network, channel: channel, nick: nick) network = network.nil? ? "" : normalize_network(network) channel = channel.nil? ? "" : normalize_channel(channel) nick = nick.nil? ? "" : normalize_nick(nick) bot_id = bot_id.to_s.strip.empty? ? current_bot_id : bot_id.to_s now = iso_time with_connection do |db| db.execute(<<~SQL, [scope, bot_id, network, channel, nick, plugin.to_s, key.to_s, value.to_s, now]) INSERT INTO plugin_data (scope, bot_id, group_id, network, channel, nick, plugin, key, value, updated_at) VALUES (?, ?, 0, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(scope, bot_id, group_id, network, channel, nick, plugin, key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at SQL end end
Source
# File lib/rabbot_db/users.rb, line 198 def set_registered_level(network:, channel:, nick:, level:) return false unless registered?(network: network, channel: channel, nick: nick) set_level(network: network, channel: channel, nick: nick, level: level) end
Source
# File lib/rabbot_db/connection.rb, line 65 def test_database_url ENV["RABBOT_TEST_DATABASE_URL"].to_s.strip end
Source
# File lib/rabbot_db/connection.rb, line 69 def test_mode? !test_database_url.empty? && database_url == test_database_url end
Source
# File lib/rabbot_db/users.rb, line 164 def unregister_user(network:, channel:, nick:) nick = normalize_nick(nick) with_connection do |db| channel_id = ensure_channel!(db, network: network, channel: channel) now = iso_time db.execute(<<~SQL, [DEFAULT_LEVEL, now, channel_id, nick]) UPDATE channel_users SET registered_at = NULL, level = ?, updated_at = ? WHERE channel_id = ? AND lower(nick) = lower(?) AND registered_at IS NOT NULL AND registered_at != '' SQL db.changes.positive? end end
Source
# File lib/rabbot_db/users.rb, line 212 def user_allowed?(network:, channel:, nick:, is_op:) is_op || registered?(network: network, channel: channel, nick: nick) end
Source
# File lib/rabbot_db/users.rb, line 216 def user_allowed_at_level?(network:, channel:, nick:, is_op:, minimum: LEVEL_ADMIN, alternative_nicks: RegisteredUserNicks::DEFAULT_ALTERNATIVE_NICKS) return true if is_op user = registered_channel_user( network: network, channel: channel, nick: nick, alternative_nicks: alternative_nicks ) return false unless user level_at_least?(user.level, minimum) end
Source
# File lib/rabbot_db.rb, line 79 def valid_level?(level) !normalize_level(level).nil? end
Source
# File lib/rabbot_db/connection.rb, line 58 def with_connection MUTEX.synchronize do @connection ||= open_connection yield @connection end end