An IRC bot for learning, fun and collaboration in the Freepost community.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/VvM9v
SSH:
git clone USERNAME@vervis.peers.community:VvM9v
Branches
Tags
Main.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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | {- This file is part of funbot.
-
- Written in 2015 by fr33domlover <fr33domlover@rel4tion.org>.
-
- ♡ Copying is an act of love. Please copy, reuse and share.
-
- The author(s) have dedicated all copyright and related and neighboring
- rights to this software to the public domain worldwide. This software is
- distributed without any warranty.
-
- You should have received a copy of the CC0 Public Domain Dedication along
- with this software. If not, see
- <http://creativecommons.org/publicdomain/zero/1.0/>.
-}
module Main (main) where
import Control.Monad.IO.Class (liftIO)
import Data.Settings.Section (empty)
import FunBot.Commands (commandSet)
import FunBot.ExtHandlers (handler)
import FunBot.Memos
import FunBot.Settings
import FunBot.Sources
import FunBot.Types
import FunBot.UserOptions
import Network.IRC.Fun.Bot (runBot)
import Network.IRC.Fun.Bot.Behavior (defaultBehavior)
import Network.IRC.Fun.Bot.EventMatch
import Network.IRC.Fun.Bot.Types (Behavior (..), EventMatchSpace (..))
import qualified Data.HashMap.Lazy as M (empty)
import qualified FunBot.Config as C
import qualified FunBot.IrcHandlers as H
-- | Bot environment content
env saveS saveM saveUO = BotEnv
{ webHookSourcePort = C.webListenerPort
, saveSettings = saveS
, saveMemos = saveM
, saveUserOpts = saveUO
, feedErrorLogFile = C.feedErrorLogFile
}
-- | Initial content of the bot state
initialState sets ms userOpts = BotState
{ bsSettings = sets
, bsSTree = empty
, bsMemos = ms
, bsHistory = M.empty
, bsUserOptions = userOpts
}
-- | Event detector specification
matchers =
[ matchPrefixedCommand
MatchInChannel
True
, matchPrefixedCommandFromNames
MatchInPrivate
True
(Right commandSet)
privCmds
, matchRefCommandFromSet
MatchInChannel
modPleasePrefix'
, matchRefCommandFromNames
MatchInPrivate
modPleasePrefix'
True
privCmds
, matchRef
MatchInBoth
, defaultMatch
]
where
privCmds =
[ "help", "info", "echo", "tell", "get", "show-opts", "enable-history"
, "disable-history", "set-history-lines", "erase-opts"
]
-- | Bot behavior definition
behavior = defaultBehavior
{ handleJoin = H.handleJoin
, handleMsg = H.handleMsg
, handleAction = H.handleAction
, handleBotMsg = H.handleBotMsg
, commandSets = [commandSet]
, handleNickChange = H.handleNickChange
}
-- | Additional events sources
mkSources state =
[ webListenerSource
, feedWatcherSource C.feedErrorLogFile state
]
main = do
liftIO $ putStrLn "Loading bot settings"
sets <- loadBotSettings
ms <- loadBotMemos
uos <- loadUserOptions
saveS <- mkSaveBotSettings
saveM <- mkSaveBotMemos
saveUO <- mkSaveUserOptions
let state = initialState sets ms uos
runBot
C.configuration
matchers
behavior
(mkSources state)
handler
(env saveS saveM saveUO)
state
initTree
|