summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2017-04-11 20:46:44 +0200
committertv <tv@krebsco.de>2017-04-11 20:46:44 +0200
commite6d8b646d243a7110a8c58bcc0dd90a713472419 (patch)
treebcbe96dc23a27f75c9347abda35ac1caef580806
initial commit
-rw-r--r--main.hs40
-rw-r--r--shell.nix34
2 files changed, 74 insertions, 0 deletions
diff --git a/main.hs b/main.hs
new file mode 100644
index 0000000..b178370
--- /dev/null
+++ b/main.hs
@@ -0,0 +1,40 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+import Control.Monad (forever)
+import Network (withSocketsDo, PortID(..), connectTo)
+import System.IO (hSetBuffering, hSetNewlineMode, hPutStrLn, hClose, hGetLine, BufferMode(LineBuffering), universalNewlineMode, Handle)
+import Control.Concurrent.Async (race)
+import Control.Exception.Base (finally)
+import Data.Text (isPrefixOf, pack, replace, unpack)
+
+main :: IO ()
+main = withSocketsDo $ do
+ h <- connectTo "ni.r" (PortNumber 6667)
+ talk h `finally` hClose h
+
+handshake :: Handle -> IO ()
+handshake h = do
+ hPutStrLn h "NICK test"
+ hPutStrLn h "USER test * 0 :test"
+ hPutStrLn h "JOIN #retiolum"
+
+talk :: Handle -> IO ()
+talk h = do
+ hSetNewlineMode h universalNewlineMode
+ hSetBuffering h LineBuffering
+ handshake h
+ _ <- race fromServer toServer
+ return ()
+ where
+ fromServer = forever $ do
+ line <- hGetLine h
+ --case line of
+ if (isPrefixOf "PING" (pack line)) then
+ hPutStrLn h (unpack (replace "PING" "PONG" (pack line)))
+ else
+ print line
+ toServer = do
+ line <- getLine
+ case line of
+ ":quit" -> do hPutStrLn h "/quit"; return "Quit"
+ _ -> do hPutStrLn h ("PRIVMSG #retiolum :" ++ line); toServer
diff --git a/shell.nix b/shell.nix
new file mode 100644
index 0000000..1e27f23
--- /dev/null
+++ b/shell.nix
@@ -0,0 +1,34 @@
+
+let
+ pname = "news";
+ version = "1";
+
+ pkgs = nixpkgs // extrapkgs;
+ nixpkgs = import <nixpkgs> {};
+ extrapkgs = {
+ };
+ hsPkgs = pkgs.haskellPackages;
+ hsEnv = hsPkgs.ghcWithPackages (_hsPkgs: with _hsPkgs;
+ [
+ irc
+ irc-client
+ feed
+ split
+ warp
+ wai-util
+ ]);
+in
+
+pkgs.myEnvFun {
+ name = "${pname}-${version}";
+
+ buildInputs = with pkgs; [
+ hsEnv
+ ];
+
+ extraCmds = with pkgs; ''
+ $(grep export ${hsEnv.outPath}/bin/ghc)
+ '';
+}
+
+# vim: set fdm=marker :