Skip to content

Instantly share code, notes, and snippets.

@diogotito
Created February 8, 2018 04:14
Show Gist options
  • Save diogotito/7ec003b24ff0a7717bc7091537c5d65f to your computer and use it in GitHub Desktop.
Save diogotito/7ec003b24ff0a7717bc7091537c5d65f to your computer and use it in GitHub Desktop.
Play a round at abra.pineman.win
{-# LANGUAGE OverloadedStrings #-}
import Test.WebDriver
import Test.WebDriver.Commands.Wait
import Test.WebDriver.Session
import Data.Text.IO
import qualified Data.Text as T
import qualified Data.Text.IO
import Control.Monad
import Control.Monad.Trans
import Control.Concurrent
import System.Random
firefoxConfig :: WDConfig
firefoxConfig = defaultConfig
main = runSession firefoxConfig playABRA
playABRA :: WD WDSession
playABRA = do
playerLogin
suchFast
getSession -- allows `s <- main` to get this session in GHCi
playerLogin :: WD ()
playerLogin = do
openPage "https://abra.pineman.win"
playerName <- findElem (ById "getname")
startBtn <- findElem (ById "start-button")
sendKeys "Chuck Norris" playerName
click startBtn
suchFast :: WD ()
suchFast = do
hiddenInput <- findElem (ById "hidden-input")
textDisplay <- findElem (ById "text")
forceStart <- findElem (ById "force-start")
statusDisplay <- findElem (ById "status")
waitUntil' 100000 1 (click forceStart)
liftIO (threadDelay 6000000)
text <- getText textDisplay
forM_ (T.unpack text) $ \key -> do
liftIO (randomDelay 20000 200000)
sendKeys (T.pack [key]) hiddenInput
randomDelay :: Int -> Int -> IO ()
randomDelay minTime maxTime = do
let sqrtRange = floor (sqrt $ fromIntegral (maxTime - minTime))
r1 <- randomRIO (1, sqrtRange)
r2 <- randomRIO (1, sqrtRange)
threadDelay (minTime + r1 * r2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment