-
Notifications
You must be signed in to change notification settings - Fork 0
/
george.hs
85 lines (70 loc) · 2.39 KB
/
george.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import IRCBot
import System.Exit
import System.Environment
import Data.List
import Control.Monad
main :: IO ()
main = do
args <- getArgs
pname <- getProgName
when (length args /= 1) (putStrLn ("Usage: " ++ pname ++ " <channel>") >> exitWith (ExitFailure (0-1)))
let chan = args !! 0
runProg chan "irc.freenode.com" 6667 "karavaev" "gs4"
runProg :: String -> String -> Int -> String -> String -> IO ()
runProg chan' server port nick uname = do
let chan = if chan' !! 0 == '#' then chan' else '#':chan'
putStrLn $ "Connecting to channel " ++ chan ++ " on server " ++ server ++ ":" ++ show port
h <- ircConnect server chan port nick uname
runBot (Bot h port server chan nick uname) georgeHooks
georgeHooks :: Hook
georgeHooks msg = return msg >>= v2w >>= randomQuestions >>= doEmotes >>= askWhy
>>= doEmotes >>= disagree >>= disagree2 >>= disagree3
v2w m@(PrivMsg nick name host to msg) =
do if "vodka" `elem` (words . stripPunctuation) msg
then privMsg "Wodka?"
else return ()
return m
randomQuestions m@(PrivMsg nick name host to msg) =
do x <- botRand
if x <= 0.05
then do let ws = (words . stripPunctuation) msg
y <- botRand
let n = truncate $ fromIntegral (length ws) * y
let w = ws !! n
privMsg $ w ++ "?"
else return ()
return m
doEmotes m@(PrivMsg nick name host to msg) =
do x <- botRand
if x <= 0.01
then privMsg "guys..."
else return ()
return m
askWhy m@(PrivMsg nick name host to msg) =
do myName <- getNick
if (myName `isInfixOf` msg)
then privMsg "what?"
else return ()
return m
disagree m@(PrivMsg nick name host to msg) =
do x <- botRand
if x <= 0.01
then privMsg "that's not right"
else return ()
return m
disagree2 m@(PrivMsg nick name host to msg) =
do x <- botRand
if x <= 0.01
then privMsg "no?"
else return ()
return m
disagree3 m@(PrivMsg nick name host to msg) =
do x <- botRand
if x <= 0.01
then privMsg "incorrect"
else return ()
return m
stripPunctuation [] = []
stripPunctuation (a:str) = if a `elem` "!.,:;?-()-_=+~'\"[]{}\\|<>/"
then stripPunctuation str
else a:(stripPunctuation str)