Last active
December 21, 2015 20:59
-
-
Save Deraen/6365017 to your computer and use it in GitHub Desktop.
Irc foo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns deraenircclj.core | |
(:require [clojure.core.match :refer [match]] | |
[lamina.core :as c] | |
[aleph.tcp :as tcp] | |
[gloss.core :as gloss] | |
[irclj.parser :refer [parse]])) | |
(defn create-connection | |
[] | |
(let [input (c/permanent-channel) | |
output (c/permanent-channel)] | |
{:in input :out output})) | |
(defn connect | |
[conn server port] | |
(let [client (c/wait-for-result | |
(tcp/tcp-client {:host server | |
:port port | |
:frame (gloss/string :utf-8 :delimiters ["\r\n"])}))] | |
(c/siphon client (conn :out)) | |
(c/siphon (conn :in) client) | |
client)) | |
(defn write [conn msg] | |
(c/enqueue (conn :in) msg)) | |
(defn log [ch pre] | |
(c/receive-all (c/fork ch) #(println (str pre ": " %)))) | |
(defn process [conn msg] | |
(let [p (parse msg)] | |
(println p) | |
(match p | |
[{:command "PING"}] (write conn "PONG" (first (p :params)))))) | |
(do | |
(def conn (create-connection)) | |
(log (conn :out) "output") | |
(log (conn :in) "input") | |
(c/receive-all (c/fork (conn :out)) (partial process conn)) | |
(connect conn "irc.cc.tut.fi" 6667) | |
(write conn "PASS *") | |
(write conn "NICK Deraen_clj") | |
(write conn "USER Deraen_clj 0 * :Deraen Clj") | |
(write conn "JOIN #deraen_testi")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment