<commit_before>(ns yetibot.core.webapp.resolvers
  (:require
    [yetibot.core.models.users :as users]
    [yetibot.core.webapp.resolvers.stats :as stats]
    [cuerdas.core :refer [kebab snake]]
    [yetibot.core.adapters.adapter :as adapter]
    [yetibot.core.db.history :as history]
    [yetibot.core.db.alias :as db.alias]
    [yetibot.core.db.observe :as db.observe]
    [yetibot.core.db.cron :as db.cron]
    [yetibot.core.handler :refer [handle-unparsed-expr]]
    [taoensso.timbre :refer [error debug info color-str]]))

(defn eval-resolver
  [context {:keys [expr] :as args} value]
  (debug "eval-resolver" args)
  (let [result (handle-unparsed-expr expr)]
    (if (coll? result)
      result
      [result])))

(defn adapters-resolver
  [context {:keys [] :as args} value]
  (->>
    @adapter/adapters
    vals
    (map #(hash-map :uuid (name (adapter/uuid %))
                    :platform (adapter/platform-name %)))))

(defn history-resolver
  [context
   {:keys [offset limit chat_source_room chat_source_adapter commands_only
           search_query]
    :as args}
   value]
  (info "history resolver with args" args)
  (let [where-map (merge {"is_private" false}
                         (when commands_only {"is_command" true})
                         )
        where-clause (when search_query
                       {:where/clause
                        "to_tsvector(body) @@ to_tsquery(?)"
                        :where/args [search_query]})
        ]
    (history/query (merge {:query/identifiers identity
                           :where/map where-map
                           :limit/clause limit
                           :offset/clause offset
                           :order/clause "created_at DESC"}
                          where-clause))))

(def stats-resolver (partial stats/stats-resolver))

(defn users-resolver
  [context {:keys [] :as args} value]
  (map (fn [{:keys [username active? id last-active]}]
         {:username username
          :is_active active?
          :id id
          :last_active last-active})
       (vals @users/users)))

(defn aliases-resolver
  [context {:keys [] :as args} value]
  (db.alias/query {:query/identifiers identity}))<commit_msg>Use plainto_tsquery<commit_after>(ns yetibot.core.webapp.resolvers
  (:require
    [yetibot.core.models.users :as users]
    [yetibot.core.webapp.resolvers.stats :as stats]
    [cuerdas.core :refer [kebab snake]]
    [yetibot.core.adapters.adapter :as adapter]
    [yetibot.core.db.history :as history]
    [yetibot.core.db.alias :as db.alias]
    [yetibot.core.db.observe :as db.observe]
    [yetibot.core.db.cron :as db.cron]
    [yetibot.core.handler :refer [handle-unparsed-expr]]
    [taoensso.timbre :refer [error debug info color-str]]))

(defn eval-resolver
  [context {:keys [expr] :as args} value]
  (debug "eval-resolver" args)
  (let [result (handle-unparsed-expr expr)]
    (if (coll? result)
      result
      [result])))

(defn adapters-resolver
  [context {:keys [] :as args} value]
  (->>
    @adapter/adapters
    vals
    (map #(hash-map :uuid (name (adapter/uuid %))
                    :platform (adapter/platform-name %)))))

(defn history-resolver
  [context
   {:keys [offset limit chat_source_room chat_source_adapter commands_only
           search_query]
    :as args}
   value]
  (info "history resolver with args" args)
  (let [where-map (merge {"is_private" false}
                         (when commands_only {"is_command" true})
                         )
        where-clause (when search_query
                       {:where/clause
                        "to_tsvector(body) @@ plainto_tsquery(?)"
                        :where/args [search_query]})
        ]
    (history/query (merge {:query/identifiers identity
                           :where/map where-map
                           :limit/clause limit
                           :offset/clause offset
                           :order/clause "created_at DESC"}
                          where-clause))))

(def stats-resolver (partial stats/stats-resolver))

(defn users-resolver
  [context {:keys [] :as args} value]
  (map (fn [{:keys [username active? id last-active]}]
         {:username username
          :is_active active?
          :id id
          :last_active last-active})
       (vals @users/users)))

(defn aliases-resolver
  [context {:keys [] :as args} value]
  (db.alias/query {:query/identifiers identity}))
{'fraction_non_alphanumeric': 0.12745762711864406, 'fraction_numerical': 0.0, 'mean_word_length': 2.1524216524216526, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4108492', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1406, 'n_words': 322}