diff options
author | eta <eta@theta.eu.org> | 2020-07-14T17·37+0100 |
---|---|---|
committer | eta <eta@theta.eu.org> | 2020-07-14T17·58+0000 |
commit | 209f8ef79f7844b7e883cf145515a16e44487ed6 (patch) | |
tree | 98fc89869533d757578e91b51910772f6bfaafb7 /users/glittershark/owothia/src | |
parent | 7986b93a35493e1bcd7bd9c00c8bf10b001a2564 (diff) |
feat(owothia): make more things configurable, better r/1291
- You can now configure server, port, password, nickserv password, and nick. - eta doing haskell: https://theta.eu.org/lx/selif/8pu34rll.jpg - (props to grfn for basically writing half this CL) Change-Id: I128ae01f5879df730a6404402ef16bf1f3429f98 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1164 Tested-by: BuildkiteCI Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'users/glittershark/owothia/src')
-rw-r--r-- | users/glittershark/owothia/src/Main.hs | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/users/glittershark/owothia/src/Main.hs b/users/glittershark/owothia/src/Main.hs index f0212881dbc1..5e0f18a924c8 100644 --- a/users/glittershark/owothia/src/Main.hs +++ b/users/glittershark/owothia/src/Main.hs @@ -11,16 +11,29 @@ import NLP.Corpora.Conll (Tag) import qualified Data.ByteString as BS import System.Random import System.Envy +import Data.Maybe -------------------------------------------------------------------------------- data Config = Config - { _nickservPassword :: Text - , _owoChance :: Int + { _owoChance :: Int + , _ircServer :: ByteString + , _ircPort :: Int + , _ircServerPassword :: Maybe Text + , _nickservPassword :: Maybe Text + , _ircNick :: Maybe Text } deriving stock (Show, Eq, Generic) - deriving anyclass (FromEnv) makeLenses ''Config +instance FromEnv Config where + fromEnv _ = + Config <$> env "OWO_CHANCE" + <*> env "IRC_SERVER" + <*> env "IRC_PORT" + <*> envMaybe "IRC_SERVER_PASSWORD" + <*> envMaybe "NICKSERV_PASSWORD" + <*> envMaybe "IRC_NICK" + stopWord :: Text -> Bool stopWord "'s" = True stopWord "is" = True @@ -59,8 +72,8 @@ doOwo conf = do liftIO $ putStrLn $ "rolled " <> show n pure $ n == 0 -owothiaHandler :: Config -> IORef Bool -> POSTagger Tag -> EventHandler s -owothiaHandler conf state tagger = EventHandler Just $ \src ev -> do +owothiaHandler :: Config -> Text -> IORef Bool -> POSTagger Tag -> EventHandler s +owothiaHandler conf nick state tagger = EventHandler Just $ \src ev -> do hasIdentified <- readIORef state when (not hasIdentified) $ do nickservAuth @@ -82,26 +95,22 @@ owothiaHandler conf state tagger = EventHandler Just $ \src ev -> do owoMessage m = do mVerb <- liftIO $ randomVerb tagger m for_ mVerb $ \verb -> send $ Privmsg "##tvl" $ Right $ owo verb - nickservAuthMsg = "IDENTIFY " <> myNick <> " " <> conf ^. nickservPassword + nickservAuthMsg = "IDENTIFY " <> nick <> " " <> fromJust (conf ^. nickservPassword) nickservAuth = send $ Privmsg "NickServ" $ Right nickservAuthMsg -myNick :: Text -myNick = "owothia" - -run :: ByteString -> Int -> IO () -run host port = do - Right conf <- decodeEnv +main :: IO () +main = do + conf <- either fail pure =<< decodeEnv tagger <- defaultTagger - state <- newIORef False - let conn = - plainConnection host port + state <- newIORef $ not . isJust $ (conf ^. nickservPassword) + let nick = fromMaybe "owothia" (conf ^. ircNick) + conn = + plainConnection (conf ^. ircServer) (conf ^. ircPort) & realname .~ "Owothia Revströwö" + & password .~ (conf ^. ircServerPassword) & logfunc .~ stdoutLogger cfg = - defaultInstanceConfig myNick + defaultInstanceConfig nick & channels .~ ["##tvl"] - & handlers %~ (owothiaHandler conf state tagger : ) + & handlers %~ (owothiaHandler conf nick state tagger : ) runClient conn cfg () - -main :: IO () -main = run "irc.freenode.net" 6667 |