From 15ad905666c937b33e8dfd76951c66fe39881a87 Mon Sep 17 00:00:00 2001 From: Apple Princess Date: Sat, 7 Apr 2018 20:42:59 +0100 Subject: [PATCH] Formatted and removed some debugging code. --- app/CommentReader/Main.hs | 121 ++++++++++++-------------------------- 1 file changed, 36 insertions(+), 85 deletions(-) diff --git a/app/CommentReader/Main.hs b/app/CommentReader/Main.hs index f32e24c..2e7cde3 100644 --- a/app/CommentReader/Main.hs +++ b/app/CommentReader/Main.hs @@ -1,26 +1,27 @@ {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ViewPatterns #-} -{-# LANGUAGE CPP #-} +{-# LANGUAGE ViewPatterns #-} +-- {-# LANGUAGE CPP #-} module Main (main) where -import Control.Monad (when) -import qualified Data.ByteString as B +import Control.Monad (when) +import qualified Data.ByteString as B import Data.IORef -import Data.List (elemIndices) -import Data.Semigroup ((<>)) -import qualified Data.Text as T -import qualified Data.Text.Encoding as TE +import Data.List (elemIndices) +import Data.Semigroup ((<>)) +import qualified Data.Text as T +import qualified Data.Text.Encoding as TE import Data.Word -import System.IO (hFlush, stdout, stdin, hSetEcho, hGetEcho) -import System.IO.Unsafe (unsafePerformIO) -import System.Process (createProcess, shell) +import System.IO (hFlush, hGetEcho, hSetEcho, stdin, + stdout) +import System.IO.Unsafe (unsafePerformIO) +import System.Process (createProcess, shell) -import Network.Socket hiding (recv, send) -import Network.Socket.ByteString (send) -import Options.Applicative +import Network.Socket hiding (recv, send) +import Network.Socket.ByteString (send) +import Options.Applicative -import Framework -import Mimizu +import Framework +import Mimizu data ReadingSystem = Bouyomi | Softalk deriving (Show, Read, Eq) @@ -32,10 +33,6 @@ data Options = Options , identifier :: String , password :: String , formatStr :: String -#ifdef DEBUG - , connectTo :: String - , isChatOnly :: Bool -#endif } parseOptions :: Parser Options @@ -87,32 +84,17 @@ parseOptions = Options <> metavar "FORMAT" <> value "%s\t%m" <> showDefault ) -#ifdef DEBUG - <*> option str - ( long "game-connect-to" - <> metavar "GAMEIP" - <> short 'g' - <> showDefault - <> value "160.16.82.222" - <> help "IP addres, the game/the chat connecting to") - <*> switch - ( long "chat-only" - <> short 'c' - <> help "Specifies whether chat only or not") -#endif {-# NOINLINE options #-} options :: IORef Options -options = unsafePerformIO $ newIORef (Options Bouyomi - "softalk.exe" - "127.0.0.1" - 50001 - "" - "" - "%s\t%m" -#ifdef DEBUG - "160.16.82.222" False -#endif +options = unsafePerformIO $ newIORef (Options + Bouyomi + "softalk.exe" + "127.0.0.1" + 50001 + "" + "" + "%s\t%m" ) errorHandler :: ErrorHandler @@ -184,10 +166,10 @@ getPassword = do formatMessage :: Chat -> String -> T.Text -formatMessage c fStr = T.replace (T.pack "%s") (T.pack $ sender c) $ +formatMessage c fStr = T.replace (T.pack "\\t") (T.pack "\t") $ + T.replace (T.pack "%s") (T.pack $ sender c) $ T.replace (T.pack "%m") (T.pack $ message c) (T.pack fStr) --- これもフォーマット させたいが,今は時間がないので, とりあえず 名前とメッセージだけを送信! generateBouyomiData :: Chat -> String -> B.ByteString generateBouyomiData chat fStr = B.pack $ sendCommand ++ defaultSpeed ++ defaultPitch ++ defaultVolume ++ defaultTone ++ defaultEncoding @@ -212,52 +194,21 @@ main = do <> header "chat - a simple comment reader bridge" ) opt <- execParser hdr atomicModifyIORef' options $ const (opt, ()) -#ifdef DEBUG - let host = hFunc . map ((read :: String -> Word8) . T.unpack) $ T.split (== '.') $ T.pack (connectTo opt') - cFunc = if isChatOnly opt' then Just chatReceived else Nothing -#else let host = (160, 16, 82, 222) cFunc = Just chatReceived -#endif opt' <- readIORef options -#ifdef DEBUG - putStr "PID: " - hFlush stdout - pid <- getLine - if not (null pid) - then mainLoop pid errorHandler sampleGameReceive chatCallback chatCallback' False -#else - if False - then undefined -#endif - -#ifdef DEBUG - (isChatOnly opt') -#else - True -#endif - (Just host) - Nothing - Nothing - cFunc - else do id' <- if null (identifier opt') - then do putStr "ID: " - hFlush stdout - getLine - else return (identifier opt') - password' <- if null (password opt') - then getPassword - else return (password opt') - mainLoop "" errorHandler sampleGameReceive chatCallback chatCallback' False -#ifdef DEBUG - (isChatOnly opt') -#else + id' <- if null (identifier opt') + then do putStr "ID: " + hFlush stdout + getLine + else return (identifier opt') + password' <- if null (password opt') + then getPassword + else return (password opt') + mainLoop "" errorHandler sampleGameReceive chatCallback chatCallback' False True -#endif (Just host) (Just id') (Just password') cFunc - -- chatOnly id' password chatReceived - return () where hFunc [a, b, c, d] = (a, b, c, d)