Created
December 5, 2019 03:54
-
-
Save Gabriella439/ab5a4ac5196403b3168271ce8d2c49ed to your computer and use it in GitHub Desktop.
Simple Twitter chat bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveAnyClass #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE RecordWildCards #-} | |
import Data.ByteString (ByteString) | |
import Data.Default.Class (Default(..)) | |
import GHC.Generics (Generic) | |
import Network.Connection (ConnectionParams(..)) | |
import Options.Generic (ParseRecord) | |
import qualified Control.Concurrent as Concurrent | |
import qualified Control.Monad as Monad | |
import qualified Data.ByteString.Char8 as ByteString | |
import qualified Network.Connection as Connection | |
import qualified Options.Generic as Options | |
data Options = Options { token :: ByteString } deriving (Generic, ParseRecord) | |
main :: IO () | |
main = do | |
Options{..} <- Options.getRecord "Simple Twitch chat bot" | |
connectionContext <- Connection.initConnectionContext | |
let connectionHostname = "irc.chat.twitch.tv" | |
let connectionPort = 6697 | |
let connectionUseSecure = Just def | |
let connectionUseSocks = Nothing | |
connection <- Connection.connectTo connectionContext ConnectionParams{..} | |
Connection.connectionPut connection ("PASS " <> token <> "\r\n") | |
Connection.connectionPut connection ("NICK gabrielg439\r\n") | |
Connection.connectionPut connection ("JOIN #awakesecurity\r\n") | |
_ <- Concurrent.forkIO $ Monad.forever $ do | |
bytes <- Connection.connectionGetLine 1024 connection | |
ByteString.putStrLn bytes | |
Monad.forever $ do | |
message <- ByteString.getLine | |
Connection.connectionPut connection ("PRIVMSG #awakesecurity " <> message <> "\r\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment