--important, reminder, Digit ! This is stage4 type, not stage 3 type. -- therefor, mind your pastes from type 3 to type 4 need the " h" taken out of equations --also -- check daskherbserchtest.hs to see how far you got towards implementing faux search. import Data.List import Network import System.IO import System.Exit import Control.Arrow import Control.Monad.Reader import Control.Exception import Text.Printf import System.Random -- import random, it said, surely they meant import Random, trying System.Random server = "irc.freenode.org" port = 6667 chan = "#gentoo-weed" nick = "daskherb" -- The 'Net' monad, a wrapper over IO, carrying the bot's immutable state. type Net = ReaderT Bot IO data Bot = Bot { socket :: Handle } -- Set up actions to run on start and end, and run the main loop main :: IO () main = bracket connect disconnect loop where disconnect = hClose . socket loop st = runReaderT run st -- Connect to the server and return the initial bot state connect :: IO Bot connect = notify $ do h <- connectTo server (PortNumber (fromIntegral port)) hSetBuffering h NoBuffering return (Bot h) where notify a = bracket_ (printf "Connecting to %s ... " server >> hFlush stdout) (putStrLn "done.") a -- We're in the Net monad now, so we've connected successfully -- Join a channel, and start processing commands run :: Net () run = do write "NICK" nick write "USER" (nick++" 0 * :DigitsStonerBot") write "JOIN" chan asks socket >>= listen -- Process each line from the server listen :: Handle -> Net () listen h = forever $ do s <- init `fmap` io (hGetLine h) io (putStrLn s) if ping s then pong s else eval (clean s) where forever a = a >> forever a clean = drop 1 . dropWhile (/= ':') . drop 1 ping x = "PING :" `isPrefixOf` x pong x = write "PONG" (':' : drop 6 x) --let ecumenical = ["yes","that would be an ecumenical matter."] --let ecumenical = [("yes"),("that would be an ecumenical matter.")] --ecumenical = [("yes"),("that would be an ecumenical matter.")] -- oh oh array! lets try that! --ecumenical = array (1, 3) [(1, "yes"),(2, "that would be an ecumenical matter."),(3, "drink!")] -- Dispatch a command eval :: String -> Net () eval "!quit" = write "QUIT" ":Exiting" >> io (exitWith ExitSuccess) eval x | "!id " `isPrefixOf` x = privmsg (drop 4 x) eval "tryme" = privmsg "this will never work" --eval h x | Just x <- stripPrefix "!id " x = privmsg h x --eval h (stripPrefix "!id " -> Just x) = privmsg h x --eval x | "!id " `isPrefixOf` x = privmsg (drop 4 x) -- -- !search, based on !id/!say^... oops, made this then realised i already made !seek and !search eval x | "!research " `isPrefixOf` x = privmsg ("https://lmddgtfy.net/?q=" ++ (drop 10 x)) eval x | "!seek " `isPrefixOf` x = privmsg ("well you would want to search for " ++ (drop 6 x) ++ " wouldnt you.") -- JOY (this is the winner, we can delete the rest... once you dont want them around any longer to see how you incrementally got there today. --single --"https://duckduckgo.com/?q=words" "https://lmddgtfy.net/?q=words" --[2018-07-15 20:28:21] string.replace(" ", "%20") eval x | "!search " `isPrefixOf` x = privmsg ("https://lmddgtfy.net/?q=" ++ (drop 8 x) ++ " ok?") --multiple -- eval x | "!search " `isPrefixOf` x = privmsg ("https://lmddgtfy.net/?q=" ++ (drop 8 x) ++ " though i caution you, these are not the droids you're looking for") -- eval x | "!pass " `isPrefixOf` x = privmsg ("Puff Puff Pass, " ++ (drop 5 x) ++ "! You're fucking up the rotation.") -- test remake of weedykins' !toke --eval x | "?!" `isSuffixOf` x = privmsg ("I dont know (or maybe I do), and cant (or wont) tell you.") ----------------------------- ----------------------------- ----- fatherjackbot dev ----- --teehee. trained jack feature development happening here. -- level ONEs -- now get these two under the same "?" --eval x | "?" `isSuffixOf` x = privmsg ("yes") --eval x | "!?" `isSuffixOf` x = privmsg ("that would be an ecumenical matter.") -- level TWOs (as developed in daskjack.hs) ---------- works --eval x | "?" `isSuffixOf` x = privmsg (if x == "?" then "that would be an ecumenical matter" else "yes") -- works :) use me! use me! -- the less spammy silenced(tedprefixed) version of level two working. * -- * -- --[2018-08- 1 02:02:00] <+Digit> i thought i covered that with my volunteered info, why am i being interogated? --[2018-08- 1 02:02:01] yes --[2018-08- 1 02:02:35] <+Digit> oh, daskherb i thought i told you to stop answering any question with a yes? --[2018-08- 1 02:49:47] <+Digit> oh, i see, the isSufficOf is in effect, but the if x == "ted?" on the right of the equation still elsing so any~ yeah, just gonna comment that out until i get it right. ... ideally with a live toggle to stfu/jack-mode. -- eval x | "ted?" `isSuffixOf` x = privmsg (if x == "ted?" then "that would be an ecumenical matter" else "yes") --- ^ so that version needs work still... a toggle features feature is highly desireable. ... levels of stfu, interesting idea. per command stfu'ness, interesting too. combination... nice. -- nice vapor -- trying something (lets call it revisiting level 2, for 2.1) --eval x | "test?" `isSuffixOf` x = privmsg (if x == "thetest?" then "that would be an ecumenical matter" else "yes") eval x | "test?" `isSuffixOf` x = privmsg (if "daskherb:" `isPrefixOf` x then "that would be an ecumenical matter" else "yes") --works, as far as this goes. -- -- ^ that, if works (ha!) is only one increment away from fully functioning trained jack, would put the ecumenical/yes in the "then" and leave the "else" blank, so it doesnt reply to questions (or even "*test?" questions) if it's not the one being asked. -- trying level 2.2, where: then "that would be an ecumenical matter"|"yes" else "" -- if $name, if end="?" then either ecumenical or yes, else nada. --eval x | "retest?" `isSuffixOf` x = privmsg (if "daskherb:" `isPrefixOf` x then "that would be an ecumenical matter"|"yes" else "") --"" else "that would be an ecumenical matter"|"yes") -- level THREEs (development towards true random continues through other criteria). --eval x | "?" `isSuffixOf` x = privmsg (runRandom (("yes"),("that would be an ecumenical matter.")))-- no way will i get this right first time. --eval x | "?" `isSuffixOf` x = privmsg (runRandom (randR(("yes"),("that would be an ecumenical matter."))))-- no way will i get this right 2nd time. --eval x | "?" `isSuffixOf` x = privmsg (randR ("yes","that would be an ecumenical matter.")) --ok, this one's using the list defined above. ecumenical. teehee. --eval x | "ted?" `isSuffixOf` x = privmsg (random.choice(ecumenical)) --eval x | "ted?" `isSuffixOf` x = privmsg (randR(ecumenical)) ---- ^ i will get there. i'm close. --eval x | "ted?" `isSuffixOf` x = privmsg (randR(ecumenical) x) --eval x | "ted?" `isSuffixOf` x = privmsg (random.choice(ecumenical) x) --eval x | "ted?" `isSuffixOf` x = privmsg (random.choice(ecumenical)) --eval x | "ted?" `isSuffixOf` x = privmsg (randR(ecumenical)) --eval x | "ted?" `isSuffixOf` x = privmsg (listo(rando)) -- halfway towards working it out then the insight slipped outta mind. --eval x | "ted?" `isSuffixOf` x = privmsg (randomRs ('e', 'y'))-- --eval x | "ted?" `isSuffixOf` x = privmsg (randomRs ('e', 'y'))-- --eval "!gimmieanumber" = privmsg (randR ("1","2") -- oh oh do it in an array! ... make the list above an array! --eval x | "ted?" `isSuffixOf` x = privmsg $ ecumenical -- -- level 4, like level 0(?) use isInfixOf, yus. eval x | "retest?" `isInfixOf` x = privmsg (if "daskherb:" `isPrefixOf` x then "that would be an ecumenical matter" else "yes") --works, as far as this goes. -- eventually i'll get that such that it's a full working fatherjackbot.... ---- fatherjackbot: --eval x | "?" `isInfixOf` x = privmsg (if "daskherb:" `isPrefixOf` x then "that would be an ecumenical matter" else "yes") --works, as far as this goes. -----commented out the full fatherjackbot line, since it would be annoying in a chan, answering every question with yes, unless asked directly then saying it would be an ecumenical matter. the isInfixOf "?" could likely just as well be isSuffixOf. that might reduce verbosity. ----- --teehee --eval x | "420" `isInfixOf` x = privmsg ("!toke Weedykins") --eval x | "4:20" `isInfixOf` x = privmsg ("!toke all the lonely people") -- now try pass to the chatter who issued the command. --eval x | " flo " `isInfixOf` x = privmsg ("!toke all who want to get motivated by toking some Flo") -- -- these are some basic sample commands for u to try out to make your own ones. eval "hello" = privmsg "is there anybody in there?" eval "!testcommand" = privmsg "this is the test responce." -- eval x | "meep" `isInfixOf` x = privmsg "I detect a meep!" eval "irie" = privmsg "bun bun babylon" eval x | "dhmo" `isInfixOf` x = privmsg "dont fall for it. it's using your chemistry ignorance and unconventional naming to obfuscate that it's just water! it's just water! dhmo = dihydrogenmonoxide = 2 hydrogen 1 oxygen = water. dont ban it! next they'll tell you cannabis/hemp is a demon called marijuana. dont fall for lies trying to deprive you/us/all of essentials!" --eval "!bong" = privmsg "gurgle gurgle gurgle" -- making bongs able to have more said after them. eval x | "!bong" `isPrefixOf` x = privmsg "gurgle gurgle gurgle - https://soffmimuhod.bandcamp.com/track/havabong" eval x | "!bomg" `isPrefixOf` x = privmsg "gurgle gurgle gurgle - https://soffmimuhod.bandcamp.com/track/havabong - (you typo'd bong again. but that's ok. i dont want to deny you a bong rip." -- next make bongs passable. ... maybe have a single hitter output when not passing, and a different output when passing. if just bong, solo bong, if bong name, pass bong, if bong not-name, solo bong. eval "!toke daskherb" = privmsg "dont pass to me. i dont have the lungs for it." eval "!walk" = privmsg "take your plants for a tour https://www.youtube.com/watch?v=iD9VI2rnc4g put a smile on your face." eval "!dank" = privmsg "take your plants for a tour https://www.youtube.com/watch?v=iD9VI2rnc4g put a smile on your face." eval "!session" = privmsg "https://www.youtube.com/watch?v=iD9VI2rnc4g" eval "!massage" = privmsg "YEAH! move that lymphatic goop! :) soften that muscle tension. soften the body, relax the mind. self massage is gooooooood. take a massage-break. you've earned it. and it will help you make the world a better place." eval x | "!tokough" `isPrefixOf` x = privmsg "*cough* *cough* pass" -- eval "!tokough" = privmsg "*cough* *cough* pass" eval "!enema" = privmsg "coffee or cannabis?" eval "!pee" = privmsg "have a glorious pee pee." eval "!poop" = privmsg "may all poop be smooth and anandamide inducing." eval "!coffee" = privmsg "colon or esophagus? detox or drug?" -- coffee please eval "coffee please" = privmsg "ok, here's 500ml, cool to under a 4second sting, quardouple strength, coconut oil lubed for insertion. hold it for 9-12 minutes, if you can. rub your belly anti-clockwise. dont hesitate to get to the toilet if you feel the need. super charging liver, bliirubin bilirubin bilirubin!" eval "colon" = privmsg "ok, here's 500ml, cool to under a 4second sting, quardouple strength, coconut oil lubed for insertion. hold it for 9-12 minutes, if you can. rub your belly anti-clockwise. dont hesitate to get to the toilet if you feel the need. super charging liver, bliirubin bilirubin bilirubin!" eval "cannabis please" = privmsg "cannabis!? up the bum!? ;D" eval "esophagus" = privmsg "https://66.media.tumblr.com/00afe13500a385c70b390f3bf319b993/tumblr_ot1bhaNLAJ1s9a9yjo1_400.gif" eval "!detox" = privmsg "coffee enema, lymph massage, bouncing rebound, juice cleanse, ... what else you got?" eval "detox please" = privmsg "coffee enema, lymph massage, bouncing rebound, juice cleanse, ... what else you got?" eval "!brownie" = privmsg "om nom nom ... om nom nom. ... ... om nom nom nom nom nom nom nom." eval "!munch" = privmsg "with jam in. :) with jam in. with jam in. yeah we hope you like jam in too. with jam in. ;D holding my sandwich." eval "!walk" = privmsg "https://www.youtube.com/watch?v=iD9VI2rnc4g" eval "!cbd" = privmsg "https://www.youtube.com/watch?v=3bZb10ZxpBk" --eval "!roll" = privmsg "rolllllllll another one... " --eval "!wake&bake" = privmsg "i toked 2 joints in the morning, and then i toked 2 more." eval "!wake&bake" = privmsg "set up the day, the right way." --eval "!daskeb" = privmsg "hello, i am daskeb, digit's haskell bot. of course, i'm just a basic starter template. you might want to look up http://www.haskell.org/haskellwiki/Roll_your_own_IRC_bot just for starters. i came from half of that. i now have my own web presence at http://wastedartist.com/scripts/daskeb/daskeb.html" eval "!didge" = privmsg "BWAWWUWUWUWOUWOUWOUYOIYIOWOAWOOWAYAYAYYIYIYIWUWUWAWUWOAWAWU" eval "!wank" = privmsg "fapfapfapfapfap" eval "!about" = privmsg "hello, i am (based on) daskeb, digit's haskell bot, just a basic starter template. you might want to look up http://www.haskell.org/haskellwiki/Roll_your_own_IRC_bot just for starters. it originally came from half of that." eval "!help" = privmsg "you'll get no help from me. i'm mystereous like that. ... i also cant spell." --reasons against shites eval x | "amazon.com" `isInfixOf` x = privmsg "https://www.stallman.org/amazon.html" eval x | "twitter.com" `isInfixOf` x = privmsg "https://www.stallman.org/twitter.html" eval _ = return () -- ignore everything else -- Send a privmsg to the current chan + server privmsg :: String -> Net () privmsg s = write "PRIVMSG" (chan ++ " :" ++ s) -- Send a message out to the server we're currently connected to write :: String -> String -> Net () write s t = do h <- asks socket io $ hPrintf h "%s %s\r\n" s t io $ printf "> %s %s\n" s t -- Convenience. io :: IO a -> Net a io = liftIO