<commit_before>(ns moomoo.core
  (:require [cljs.nodejs :as nodejs]
            [clojure.string :as string]
            [cognitect.transit :as transit]
            [moomoo.rooms :as rooms]))

(nodejs/enable-util-print!)

(def port 3001)

(def express (nodejs/require "express"))
(def app (express))
(def server (.Server (nodejs/require "http") app))
(def socketio (nodejs/require "socket.io"))
(def socketio-stream (nodejs/require "socket.io-stream"))
(def file-upload-directory "/tmp/moomoo-uploads")
(def js-uuid (nodejs/require "uuid"))
(def fs (nodejs/require "fs"))

(def io (.listen socketio server))

(defn handle-hotjoin [socket room-id]
  (println "User has hotjoined")
  (rooms/get-all-music-info room-id
    (fn [room-music-info]
      (if-not (nil? room-music-info)
        (rooms/get-current-track room-id
          (fn [current-track]
            (rooms/get-track-id-from-position room-id current-track
              (fn [current-track-id]
                (.emit socket "hotjoin-music-info" room-music-info
                                                   current-track-id)))))))))

(defn connection [socket]
  (println (str "User " (.-id socket) " has connected!"))

  (.on socket "disconnect"
    (fn []
      (rooms/disconnect (.-id socket)
        (fn [room-id]
          (rooms/get-all-users room-id
            #(.emit (.to io room-id) "users-list" (clj->js %1)))
          (println (str (.-id socket) " has disconnected!"))))))

  (.on socket "join-room"
    (fn [room-id]
      (.join socket room-id)))

  (.on socket "sign-in"
    (fn [room-id username]
      (rooms/does-room-exist? room-id
        (fn [reply]
          (if-not reply
            (rooms/init-room room-id #(println))
            (handle-hotjoin socket room-id))))
      (rooms/set-username room-id (.-id socket) username
        (fn []
          (.emit socket "sign-in-success")
          (rooms/get-all-users room-id
            #(.emit (.to io room-id) "users-list" (clj->js %1)))))))

  (.on socket "chat-message"
    (fn [room message]
      (rooms/get-username room (.-id socket)
        (fn [username]
          (.emit (.to io room) "chat-message" #js {:username username
                                                   :message  message})))))

  (.on socket "ready-to-start"
    (fn []
      (letfn [(convert-position [track-position-info]
                (+ (:position track-position-info)
                   (- (.now js/Date)
                      (:start-time track-position-info))))<commit_msg>fixed issue #6<commit_after>(ns moomoo.core
  (:require [cljs.nodejs :as nodejs]
            [clojure.string :as string]
            [cognitect.transit :as transit]
            [moomoo.rooms :as rooms]))

(nodejs/enable-util-print!)

(def port 3001)

(def express (nodejs/require "express"))
(def app (express))
(def server (.Server (nodejs/require "http") app))
(def socketio (nodejs/require "socket.io"))
(def socketio-stream (nodejs/require "socket.io-stream"))
(def file-upload-directory "/tmp/moomoo-uploads")
(def js-uuid (nodejs/require "uuid"))
(def fs (nodejs/require "fs"))

(def io (.listen socketio server))

(defn handle-hotjoin [socket room-id]
  (println "User has hotjoined")
  (rooms/get-all-music-info room-id
    (fn [room-music-info]
      (if-not (nil? room-music-info)
        (rooms/get-current-track room-id
          (fn [current-track]
            (rooms/get-track-id-from-position room-id current-track
              (fn [current-track-id]
                (.emit socket "hotjoin-music-info" room-music-info
                                                   current-track-id)))))))))

(defn connection [socket]
  (println (str "User " (.-id socket) " has connected!"))

  (.on socket "disconnect"
    (fn []
      (rooms/disconnect (.-id socket)
        (fn [room-id]
          (rooms/get-all-users room-id
            #(.emit (.to io room-id) "users-list" (clj->js %1)))
          (println (str (.-id socket) " has disconnected!"))))))

  (.on socket "connect"
    (fn [room-id]
      (println (str (.-id socket) " has connected to " room-id))))

  (.on socket "sign-in"
    (fn [room-id username]
      (.join socket room-id
        (fn []
          (rooms/does-room-exist? room-id
            (fn [reply]
              (if-not reply
                (rooms/init-room room-id #(println))
                (handle-hotjoin socket room-id))))
          (rooms/set-username room-id (.-id socket) username
            (fn []
              (.emit socket "sign-in-success")
              (rooms/get-all-users room-id
                #(.emit (.to io room-id) "users-list" (clj->js %1)))))))))

  (.on socket "chat-message"
    (fn [room message]
      (rooms/get-username room (.-id socket)
        (fn [username]
          (.emit (.to io room) "chat-message" #js {:username username
                                                   :message  message})))))

  (.on socket "ready-to-start"
    (fn []
      (letfn [(convert-position [track-position-info]
                (+ (:position track-position-info)
                   (- (.now js/Date)
                      (:start-time track-position-info))))
{'fraction_non_alphanumeric': 0.16224131198750488, 'fraction_numerical': 0.0025380710659898475, 'mean_word_length': 1.9561454125793423, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2601670', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1588, 'n_words': 406}