<commit_before>(ns yetibot.core.adapters.irc
  (:require
    [rate-gate.core :refer [rate-limit]]
    [taoensso.timbre :refer [info warn error debug]]
    [yetibot.core.chat]
    [irclj
     [core :as irc]
     [connection :as irc-conn]]
    [yetibot.core.models.users :as users]
    [clojure.string :refer [split-lines]]
    [yetibot.core.config :refer [get-config config-for-ns conf-valid?]]
    [yetibot.core.chat :refer [send-msg-for-each register-chat-adapter]]
    [yetibot.core.util.format :as fmt]
    [yetibot.core.handler :refer [handle-raw]]))

(def conn (atom nil))
(declare config channel connect start)
(def chat-source (format "irc/%s" channel))
(def wait-before-reconnect 25000)

(def send-msg
  "Rate-limited function for sending messages to IRC. It's rate limited in order
   to prevent 'Excess Flood' kicks"
  (rate-limit
    (fn [msg]
      (try
        (irc/message @conn channel msg)
        (catch java.net.SocketException e
          ; it must have disconnect, try reconnecting again
          (info "SocketException, trying to reconnect in" wait-before-reconnect "ms")
          (Thread/sleep wait-before-reconnect)
          (connect)
          (start))))
    3 600))

(defn- create-user [info]
  (let [username (:nick info)
        id (:user info)]<commit_msg>Send long IRC messages as multiple messages split up; fix devth/yetibot#352<commit_after>(ns yetibot.core.adapters.irc
  (:require
    [rate-gate.core :refer [rate-limit]]
    [taoensso.timbre :refer [info warn error debug]]
    [yetibot.core.chat]
    [irclj
     [core :as irc]
     [connection :as irc-conn]]
    [yetibot.core.models.users :as users]
    [clojure.string :refer [split-lines join]]
    [yetibot.core.config :refer [get-config config-for-ns conf-valid?]]
    [yetibot.core.chat :refer [send-msg-for-each register-chat-adapter]]
    [yetibot.core.util.format :as fmt]
    [yetibot.core.handler :refer [handle-raw]]))

(defonce conn (atom nil))
(declare config channel connect start)
(def chat-source (format "irc/%s" channel))
(def wait-before-reconnect 30000)

(def irc-max-message-length 420)

(defn split-msg-into-irc-max-length-chunks [msg]
  (map join (partition-all irc-max-message-length msg)))

(def send-msg
  "Rate-limited function for sending messages to IRC. It's rate limited in order
   to prevent 'Excess Flood' kicks"
  (rate-limit
    (fn [msg]
      (try
        (if (> (count msg) irc-max-message-length)
          (doall (map send-msg (split-msg-into-irc-max-length-chunks msg)))
          (irc/message @conn channel msg))
        (catch java.net.SocketException e
          ; it must have disconnect, try reconnecting again
          (info "SocketException, trying to reconnect in" wait-before-reconnect "ms")
          (Thread/sleep wait-before-reconnect)
          (connect)
          (start))))
    3 900))

(defn- create-user [info]
  (let [username (:nick info)
        id (:user info)]
{'fraction_non_alphanumeric': 0.13271604938271606, 'fraction_numerical': 0.00823045267489712, 'mean_word_length': 3.0123796423658873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '649319', 'n_tokens_mistral': 1029, 'n_tokens_neox': 978, 'n_words': 268}