feat(fun/owothia): add configurable join channels.
owothia is hardcoded to join ##tvl, which is a remnant of when TVL was on freenode, and on hackint the IRC channel is single-hash #tvl instead. Instead of hardcoding another channel name, let's make this configurable, so we don't need to recompile owothia for every different channel we want her in. It's now possible to set IRC_CHANNELS in owothia's environment to '["#foo", "#bar"]' to make her join both #foo and #bar automatically. Additionally IRC_IDENT can now be set to configure owothia's ident, which is required for ZNC compatibility. Change-Id: I0fc0856f4ea35f59255b76ae0e594325f18ef993 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3130 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
48b052c1e4
commit
fd6ce088ba
1 changed files with 20 additions and 8 deletions
|
@ -12,7 +12,9 @@ import NLP.Corpora.Conll (Tag)
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
import System.Random
|
import System.Random
|
||||||
import System.Envy
|
import System.Envy
|
||||||
|
import System.IO as S
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
import Data.Foldable (traverse_)
|
||||||
import qualified Data.Text
|
import qualified Data.Text
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -23,10 +25,16 @@ data Config = Config
|
||||||
, _ircServerPassword :: Maybe Text
|
, _ircServerPassword :: Maybe Text
|
||||||
, _nickservPassword :: Maybe Text
|
, _nickservPassword :: Maybe Text
|
||||||
, _ircNick :: Maybe Text
|
, _ircNick :: Maybe Text
|
||||||
|
, _ircIdent :: Maybe Text
|
||||||
|
, _ircChannels :: [Text]
|
||||||
}
|
}
|
||||||
deriving stock (Show, Eq, Generic)
|
deriving stock (Show, Eq, Generic)
|
||||||
makeLenses ''Config
|
makeLenses ''Config
|
||||||
|
|
||||||
|
instance Var [Text] where
|
||||||
|
toVar ts = show ts
|
||||||
|
fromVar s = readMaybe s >>= (pure . map Data.Text.pack)
|
||||||
|
|
||||||
instance FromEnv Config where
|
instance FromEnv Config where
|
||||||
fromEnv _ =
|
fromEnv _ =
|
||||||
Config <$> env "OWO_CHANCE"
|
Config <$> env "OWO_CHANCE"
|
||||||
|
@ -35,6 +43,8 @@ instance FromEnv Config where
|
||||||
<*> envMaybe "IRC_SERVER_PASSWORD"
|
<*> envMaybe "IRC_SERVER_PASSWORD"
|
||||||
<*> envMaybe "NICKSERV_PASSWORD"
|
<*> envMaybe "NICKSERV_PASSWORD"
|
||||||
<*> envMaybe "IRC_NICK"
|
<*> envMaybe "IRC_NICK"
|
||||||
|
<*> envMaybe "IRC_IDENT"
|
||||||
|
<*> env "IRC_CHANNELS"
|
||||||
|
|
||||||
stopWord :: Text -> Bool
|
stopWord :: Text -> Bool
|
||||||
stopWord "'s" = True
|
stopWord "'s" = True
|
||||||
|
@ -116,25 +126,25 @@ owothiaHandler conf nick state tagger = EventHandler Just $ \src ev -> do
|
||||||
hasIdentified <- readIORef state
|
hasIdentified <- readIORef state
|
||||||
when (not hasIdentified) $ do
|
when (not hasIdentified) $ do
|
||||||
nickservAuth
|
nickservAuth
|
||||||
send $ Join "##tvl"
|
traverse_ (send . Join) (conf ^. ircChannels)
|
||||||
writeIORef state True
|
writeIORef state True
|
||||||
|
|
||||||
when ("You are now identified" `BS.isInfixOf` (ev ^. raw)) $
|
when ("You are now identified" `BS.isInfixOf` (ev ^. raw)) $
|
||||||
send $ Join "##tvl"
|
traverse_ (send . Join) (conf ^. ircChannels)
|
||||||
|
|
||||||
case (src, ev ^. message) of
|
case (src, ev ^. message) of
|
||||||
(Channel "##tvl" nick, Privmsg _ (Right m)) -> do
|
(Channel chan nick, Privmsg _ (Right m)) -> do
|
||||||
willOwo <- doOwo conf
|
willOwo <- doOwo conf
|
||||||
when willOwo $ owoMessage m
|
when willOwo $ owoMessage chan m
|
||||||
_ -> pure ()
|
_ -> pure()
|
||||||
|
|
||||||
pure ()
|
pure ()
|
||||||
|
|
||||||
where
|
where
|
||||||
owoMessage m = do
|
owoMessage chan m = do
|
||||||
owoType <- liftIO randomIO
|
owoType <- liftIO randomIO
|
||||||
mWord <- liftIO $ randomOwo owoType tagger m
|
mWord <- liftIO $ randomOwo owoType tagger m
|
||||||
for_ mWord $ \word -> send $ Privmsg "##tvl" $ Right $ owo owoType word
|
for_ mWord $ \word -> send $ Privmsg chan $ Right $ owo owoType word
|
||||||
nickservAuthMsg = "IDENTIFY " <> nick <> " " <> fromJust (conf ^. nickservPassword)
|
nickservAuthMsg = "IDENTIFY " <> nick <> " " <> fromJust (conf ^. nickservPassword)
|
||||||
nickservAuth = send $ Privmsg "NickServ" $ Right nickservAuthMsg
|
nickservAuth = send $ Privmsg "NickServ" $ Right nickservAuthMsg
|
||||||
|
|
||||||
|
@ -143,14 +153,16 @@ main = do
|
||||||
conf <- either fail pure =<< decodeEnv
|
conf <- either fail pure =<< decodeEnv
|
||||||
tagger <- defaultTagger
|
tagger <- defaultTagger
|
||||||
state <- newIORef $ not . isJust $ (conf ^. nickservPassword)
|
state <- newIORef $ not . isJust $ (conf ^. nickservPassword)
|
||||||
|
S.hSetBuffering stdout LineBuffering
|
||||||
let nick = fromMaybe "owothia" (conf ^. ircNick)
|
let nick = fromMaybe "owothia" (conf ^. ircNick)
|
||||||
conn =
|
conn =
|
||||||
plainConnection (conf ^. ircServer) (conf ^. ircPort)
|
plainConnection (conf ^. ircServer) (conf ^. ircPort)
|
||||||
& realname .~ "Owothia Revströwö"
|
& realname .~ "Owothia Revströwö"
|
||||||
& password .~ (conf ^. ircServerPassword)
|
& password .~ (conf ^. ircServerPassword)
|
||||||
|
& username .~ fromMaybe "owothia" (conf ^. ircIdent)
|
||||||
& logfunc .~ stdoutLogger
|
& logfunc .~ stdoutLogger
|
||||||
cfg =
|
cfg =
|
||||||
defaultInstanceConfig nick
|
defaultInstanceConfig nick
|
||||||
& channels .~ ["##tvl"]
|
& channels .~ (conf ^. ircChannels)
|
||||||
& handlers %~ (owothiaHandler conf nick state tagger : )
|
& handlers %~ (owothiaHandler conf nick state tagger : )
|
||||||
runClient conn cfg ()
|
runClient conn cfg ()
|
||||||
|
|
Loading…
Reference in a new issue