<commit_before>(ns yetibot.core.adapters.init
  "Manages the lifecycle of adapters"
  (:require
    [schema.core :as s]
    [yetibot.core.adapters.slack :as slack]
    [yetibot.core.adapters.irc :as irc]
    [taoensso.timbre :as log :refer [info warn error]]
    [clojure.stacktrace :refer [print-stack-trace]]
    [yetibot.core.adapters.adapter :as a]
    [yetibot.core.config :refer [get-config conf-valid?]]
    [yetibot.core.adapters.irc :as irc]))

(def adapters-schema
  [{:name s/Str
    :type s/Str
    ;; different types of adapters require different keys - make them optional
    ;; Slack
    (s/optional-key :token) s/Str
    ;; IRC
    (s/optional-key :host) s/Str
    (s/optional-key :port) s/Str
    (s/optional-key :ssl?) s/Str
    (s/optional-key :username) s/Str
    (s/optional-key :password) s/Str}])

(defn adapters-config []
  (let [c (get-config adapters-schema [:yetibot :adapters])]
    (if (:error c)
      (throw (ex-info "Invalid adapters config" c))
      (:value c))))

(defn report-ex [f n]
  (try
    (info "Trying" n)
    (f)
    (catch Exception e
      (warn "Error on" n (with-out-str (print-stack-trace e))))))

(defn make-adapter [idx config]
  (condp = (keyword (:type config))
    :slack (slack/make-slack idx config)
    :irc (irc/make-irc idx config)
    (throw (ex-info (str "Unknown adapter type " (:type config)) config))))

(defn validate-adapter-config!<commit_msg>Fix yetibot adapters schema for ssl option<commit_after>(ns yetibot.core.adapters.init
  "Manages the lifecycle of adapters"
  (:require
    [schema.core :as s]
    [yetibot.core.adapters.slack :as slack]
    [yetibot.core.adapters.irc :as irc]
    [taoensso.timbre :as log :refer [info warn error]]
    [clojure.stacktrace :refer [print-stack-trace]]
    [yetibot.core.adapters.adapter :as a]
    [yetibot.core.config :refer [get-config conf-valid?]]
    [yetibot.core.adapters.irc :as irc]))

(def adapters-schema
  [{:name s/Str
    :type s/Str
    ;; different types of adapters require different keys - make them optional
    ;; Slack
    (s/optional-key :token) s/Str
    ;; IRC
    (s/optional-key :host) s/Str
    (s/optional-key :port) s/Str
    (s/optional-key :ssl) s/Str
    (s/optional-key :username) s/Str
    (s/optional-key :password) s/Str}])

(defn adapters-config []
  (let [c (get-config adapters-schema [:yetibot :adapters])]
    (if (:error c)
      (throw (ex-info "Invalid adapters config" c))
      (:value c))))

(defn report-ex [f n]
  (try
    (info "Trying" n)
    (f)
    (catch Exception e
      (warn "Error on" n (with-out-str (print-stack-trace e))))))

(defn make-adapter [idx config]
  (condp = (keyword (:type config))
    :slack (slack/make-slack idx config)
    :irc (irc/make-irc idx config)
    (throw (ex-info (str "Unknown adapter type " (:type config)) config))))

(defn validate-adapter-config!
{'fraction_non_alphanumeric': 0.15333333333333332, 'fraction_numerical': 0.0, 'mean_word_length': 3.125904486251809, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4506774', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1052, 'n_words': 281}