From e6d8b646d243a7110a8c58bcc0dd90a713472419 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 11 Apr 2017 20:46:44 +0200 Subject: initial commit --- main.hs | 40 ++++++++++++++++++++++++++++++++++++++++ shell.nix | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 main.hs create mode 100644 shell.nix 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 {}; + 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 : -- cgit v1.2.3