class RabbotApp
Constants
- Config
- DEFAULT_CONFIG_PATH
- DEFAULT_INCLUDED_PLUGIN_NAMES
- DEFAULT_MAX_MESSAGES
- DEFAULT_MESSAGES_PER_SECOND
- DEFAULT_MESSAGE_SPLIT_END
- DEFAULT_MESSAGE_SPLIT_START
- DEFAULT_PLUGIN_GLOB
- ROOT
Public Class Methods
Source
# File lib/rabbot_app.rb, line 203 def apply_db_path(config) RabbotDb.current_bot_id = config.bot_id RabbotDb.database_url = config.database_url if config.database_url RabbotDb.db_path = config.db_path if config.db_path end
Source
# File lib/rabbot_app.rb, line 209 def bot_id_from_path(path) RabbotWeb.bot_id_from_path(path) end
Source
# File lib/rabbot_app.rb, line 58 def build(config_path = DEFAULT_CONFIG_PATH, config: nil, plugin_paths: DEFAULT_PLUGIN_GLOB, available_plugins: nil) config ||= load_config(config_path) plugins = resolve_plugins( config.plugin_config, available_plugins: available_plugins || load_plugin_classes(plugin_paths: plugin_paths) ) plugins << PluginReloadSignal unless plugins.include?(PluginReloadSignal) plugins << GracefulQuitSignal unless plugins.include?(GracefulQuitSignal) plugins << IrcReconnectGuard unless plugins.include?(IrcReconnectGuard) apply_db_path(config) build_bot(config, plugins: plugins) end
Source
# File lib/rabbot_app.rb, line 166 def build_bot(config, plugins:) Cinch::Bot.new do configure do |c| c.server = config.server c.channels = config.channels c.nick = config.nick c.nicks = config.nicks unless config.nicks.empty? c.realname = config.realname c.identd = config.identd c.user = config.user c.plugins.plugins = plugins c.shared[:nick_fallbacks] = config.nick_fallback_config unless config.nick_fallback_config.empty? c.shared[:bot_role] = config.bot_role unless config.bot_role.empty? c.shared[:bot_level] = BotIdentity.resolve_level( bot_role: config.bot_role, level: config.level ) c.shared[:build_coordinator] = config.build_coordinator_config unless config.build_coordinator_config.empty? c.shared[:character_profile_path] = config.profile_path if config.profile_path c.shared[:character_profile] = CharacterProfile.load(config.profile_path) if config.profile_path c.shared[:ai_model] = config.ai_model unless config.ai_model.empty? c.messages_per_second = config.messages_per_second c.max_messages = config.max_messages c.message_split_start = config.message_split_start c.message_split_end = config.message_split_end IrcServerFallback.apply_shared_config!( c.shared, primary_server: config.server, irc_config: config.irc_config ) c.shared[:bot_id] = config.bot_id c.shared[:web_config] = config.web_config c.shared[:web_sites] = config.web_config[:sites] end end end
Source
# File lib/rabbot_app.rb, line 129 def discover_plugin_classes ObjectSpace.each_object(Class) .select { |klass| plugin_class?(klass) } .uniq .sort_by(&:name) end
Source
# File lib/rabbot_app.rb, line 153 def include_default_plugins(selected, excluded:, by_name:) excluded_keys = excluded.map { |klass| klass.name.to_s.downcase } DEFAULT_INCLUDED_PLUGIN_NAMES.each do |name| next if excluded_keys.include?(name.downcase) klass = by_name[name] next unless klass selected << klass unless selected.include?(klass) end selected.sort_by(&:name) end
Source
# File lib/rabbot_app.rb, line 72 def load_config(path = DEFAULT_CONFIG_PATH) expanded_path = File.expand_path(path.to_s, ROOT) raise ConfigError, "Bot config not found: #{expanded_path}" unless File.file?(expanded_path) raw = YAML.safe_load_file(expanded_path, aliases: false) || {} raw = stringify_keys(raw) raise ConfigError, "Bot config must be a YAML mapping: #{expanded_path}" unless raw.is_a?(Hash) nick = required_string(raw, "nick") identd = optional_string(raw, "identd", nick.downcase) bot_role = optional_string(raw, "bot_role", "") level = optional_string(raw, "level", "") Config.new( path: expanded_path, bot_id: bot_id_from_path(expanded_path), server: required_string(raw, "server"), channels: required_channels(raw), nick: nick, nicks: optional_string_list(raw, "nicks", [nick]), preferred_nick: optional_string(raw, "preferred_nick", nick), nick_fallback_config: normalize_nick_fallback_config(raw["nick_fallbacks"], preferred: optional_string(raw, "preferred_nick", nick)), bot_role: bot_role, level: level, build_coordinator_config: normalize_build_coordinator_config(raw["build_coordinator"]), realname: optional_string(raw, "realname", nick), identd: identd, user: optional_string(raw, "user", normalize_irc_user(identd.empty? ? nick : identd)), db_path: optional_path(raw, "db_path"), database_url: optional_string(raw, "database_url", ""), profile_path: optional_path(raw, "profile_path"), ai_model: optional_string(raw, "ai_model", ""), plugin_config: normalize_plugin_config(raw["plugins"]), messages_per_second: optional_float(raw, "messages_per_second", DEFAULT_MESSAGES_PER_SECOND), max_messages: optional_integer_or_nil(raw, "max_messages", DEFAULT_MAX_MESSAGES), message_split_start: optional_string(raw, "message_split_start", DEFAULT_MESSAGE_SPLIT_START), message_split_end: optional_string(raw, "message_split_end", DEFAULT_MESSAGE_SPLIT_END), irc_config: normalize_irc_config(raw["irc"]), web_config: normalize_web_config( raw["web"], bot_id: bot_id_from_path(expanded_path), bot_role: bot_role, level: level ) ) end
Source
# File lib/rabbot_app.rb, line 118 def load_plugin_classes(plugin_paths: DEFAULT_PLUGIN_GLOB) paths = if plugin_paths.is_a?(String) Dir[plugin_paths] else Array(plugin_paths) end paths.sort.each { |path| require path } discover_plugin_classes end
Source
# File lib/rabbot_app.rb, line 136 def resolve_plugins(plugin_config, available_plugins:) available = available_plugins.select { |klass| plugin_class?(klass) } .uniq .sort_by(&:name) by_name = available.to_h { |klass| [klass.name, klass] } include_value = plugin_config.fetch("include", "all") selected = if include_all?(include_value) available else lookup_plugin_names(include_value, by_name, label: "include") end excluded = lookup_plugin_names(plugin_config.fetch("exclude", []), by_name, label: "exclude") selected = selected - excluded include_default_plugins(selected, excluded: excluded, by_name: by_name) end