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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | {- This file is part of funbot.
-
- Written in 2015, 2016 by fr33domlover <fr33domlover@riseup.net>.
-
- ♡ 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/>.
-}
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Control.Concurrent.Chan (newChan)
import Control.Monad.IO.Class (liftIO)
import Data.Default.Class (def)
import Data.Settings.Section (empty)
import FunBot.Commands
import FunBot.ExtHandlers (handler)
import FunBot.KnownNicks
import FunBot.Memos
import FunBot.Settings
import FunBot.Settings.Persist
import FunBot.Settings.Sections
import FunBot.Sources
import FunBot.Types
import FunBot.UserOptions
import FunBot.Util (cmds)
import Network.IRC.Fun.Bot (runBot)
import Network.IRC.Fun.Bot.EventMatch
import Network.IRC.Fun.Bot.Types (Behavior (..), EventMatchSpace (..))
import Web.Feed.Collect (newCommandQueue)
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 saveKN cq lq = BotEnv
{ webHookSourcePort = C.webListenerPort
, saveSettings = saveS
, saveMemos = saveM
, saveUserOpts = saveUO
, saveNicks = saveKN
, feedErrorLogFile = C.feedErrorLogFile
, feedCmdQueue = cq
, loopbackQueue = lq
}
-- | Initial content of the bot state
initialState sets ms userOpts nicks = BotState
{ bsSettings = sets
, bsSTree = empty
, bsMemos = ms
, bsUserOptions = userOpts
, bsKnownNicks = nicks
, bsLastMsgTime = M.empty
, bsPuppet = M.empty
, bsPrivPuppet = Nothing
}
-- | 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 = cmds
[ "help", "info", "echo", "tell", "get", "show-opts", "enable-history"
, "disable-history", "set-history-lines", "erase-opts", "show-history"
, "where", "lwhere", "gwhere"
]
-- | Bot behavior definition
behavior :: Behavior BotEnv BotState
behavior = def
{ handleJoin = H.handleJoin
, handleMsg = H.handleMsg
, handleAction = H.handleAction
, handleBotMsg = H.handleBotMsg
, commandSets = [commandSet]
, handleNickChange = H.handleNickChange
, handleNames = H.handleNames
}
-- | Additional events sources
mkSources state =
[ webListenerSource C.webErrorLogFile
, feedWatcherSource C.feedErrorLogFile state
, loopbackSource
]
main :: IO ()
main = do
liftIO $ putStrLn "Loading bot settings"
sets <- loadBotSettings
ms <- loadBotMemos
uos <- loadUserOptions
nicks <- loadKnownNicks
saveS <- mkSaveBotSettings
saveM <- mkSaveBotMemos
saveUO <- mkSaveUserOptions
saveKN <- mkSaveKnownNicks
cq <- newCommandQueue
lq <- newChan
let state = initialState sets ms uos nicks
runBot
C.configuration
matchers
behavior
(mkSources state)
handler
(env saveS saveM saveUO saveKN cq lq)
state
initTree
|