<commit_before>(ns lazubot.master
  (:require [clojure.java.io :as io]
            [clojure.java.shell :refer [sh]]
            [clojure.tools.logging :refer [warn]]
            [clojure.set :refer [difference]]
            [clojure.core.async :refer [<! >! go chan sliding-buffer]]
            [clojure-zulip.core :as zulip]
            [clojail.core :refer [sandbox]]
            [com.keminglabs.zmq-async.core :refer [register-socket!]])
  (:import [java.io PushbackReader]))

(def config (with-open [r (io/reader (io/resource "private/config"))]
              (read (PushbackReader. r))))
(def conn (zulip/connection config))
(def bot-streams ["test-stream"])
(def num-goroutines 10)
(def sb (sandbox [])) ;; sandbox without any testers, only using timeout capability

(defn open-socket []
  (let [addr "tcp://127.0.0.1:8080"
        [request-in request-out] (repeatedly 2 #(chan (sliding-buffer 10)))]
    (register-socket! {:in request-in :out request-out :socket-type :req
                       :configurator (fn [socket] (.bind socket addr))})
    (println (:out (sh "docker" "build" "-t lazubot-worker" "-" "<" "/lazubot/resources/public/WorkerDockerfile")))
    (println (:out (sh "docker" "run" "-rm=true" "-t" "-i" "-name client" "-link master:linked-master"
        "lazubot-worker" "lein with-profile worker run")))
    (go
     (>! request-in "hello there socket!")
     (println (<! request-out)))))

(defn ensure-subscriptions []
  (zulip/sync* (zulip/add-subscriptions conn bot-streams))
  (let [current-subs (set (map :name (:subscriptions (zulip/sync* (zulip/subscriptions conn)))))
        remove-subs (difference current-subs (set bot-streams))]
    (when (seq remove-subs)
      (zulip/sync* (zulip/remove-subscriptions conn remove-subs)))))

(defn respond [message reply]
  (let [str-reply (if (seq? reply) (str (seq reply)) (str reply))
        parsed-reply (str "~~~clojure\n" str-reply "\n~~~")]
    (if (= "private" (get-in message [:message :type]))
      (zulip/send-private-message conn
                                  (map :email (get-in message [:message :display_recipient]))
                                  parsed-reply)
      (zulip/send-stream-message conn<commit_msg>Cache is ruining things maybe<commit_after>(ns lazubot.master
  (:require [clojure.java.io :as io]
            [clojure.java.shell :refer [sh]]
            [clojure.tools.logging :refer [warn]]
            [clojure.set :refer [difference]]
            [clojure.core.async :refer [<! >! go chan sliding-buffer]]
            [clojure-zulip.core :as zulip]
            [clojail.core :refer [sandbox]]
            [com.keminglabs.zmq-async.core :refer [register-socket!]])
  (:import [java.io PushbackReader]))

(def config (with-open [r (io/reader (io/resource "private/config"))]
              (read (PushbackReader. r))))
(def conn (zulip/connection config))
(def bot-streams ["test-stream"])
(def num-goroutines 10)
(def sb (sandbox [])) ;; sandbox without any testers, only using timeout capability

(defn open-socket []
  (let [addr "tcp://127.0.0.1:8080"
        [request-in request-out] (repeatedly 2 #(chan (sliding-buffer 10)))]
    (register-socket! {:in request-in :out request-out :socket-type :req
                       :configurator (fn [socket] (.bind socket addr))})
    (println (:out (sh "docker" "build" "--no-cache" "-t lazubot-worker" "-" "<" "/lazubot/resources/public/WorkerDockerfile")))
    (println (:out (sh "docker" "run" "-rm=true" "-t" "-i" "-name client" "-link master:linked-master"
        "lazubot-worker" "lein with-profile worker run")))
    (go
     (>! request-in "hello there socket!")
     (println (<! request-out)))))

(defn ensure-subscriptions []
  (zulip/sync* (zulip/add-subscriptions conn bot-streams))
  (let [current-subs (set (map :name (:subscriptions (zulip/sync* (zulip/subscriptions conn)))))
        remove-subs (difference current-subs (set bot-streams))]
    (when (seq remove-subs)
      (zulip/sync* (zulip/remove-subscriptions conn remove-subs)))))

(defn respond [message reply]
  (let [str-reply (if (seq? reply) (str (seq reply)) (str reply))
        parsed-reply (str "~~~clojure\n" str-reply "\n~~~")]
    (if (= "private" (get-in message [:message :type]))
      (zulip/send-private-message conn
                                  (map :email (get-in message [:message :display_recipient]))
                                  parsed-reply)
      (zulip/send-stream-message conn
{'fraction_non_alphanumeric': 0.16835243875028097, 'fraction_numerical': 0.006743088334457181, 'mean_word_length': 2.8594969644405897, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4190270', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1486, 'n_words': 370}