Main.hs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. {- This file is part of funbot.
  2. -
  3. - Written in 2015 by fr33domlover <fr33domlover@rel4tion.org>.
  4. -
  5. - ♡ Copying is an act of love. Please copy, reuse and share.
  6. -
  7. - The author(s) have dedicated all copyright and related and neighboring
  8. - rights to this software to the public domain worldwide. This software is
  9. - distributed without any warranty.
  10. -
  11. - You should have received a copy of the CC0 Public Domain Dedication along
  12. - with this software. If not, see
  13. - <http://creativecommons.org/publicdomain/zero/1.0/>.
  14. -}
  15. module Main (main) where
  16. import Control.Monad.IO.Class (liftIO)
  17. import qualified Data.HashMap.Lazy as M (empty)
  18. import Data.Settings.Section (empty)
  19. import FunBot.Commands (commandSet)
  20. import qualified FunBot.Config as C
  21. import FunBot.ExtHandlers (handler)
  22. import qualified FunBot.IrcHandlers as H
  23. import FunBot.Memos
  24. import FunBot.Settings
  25. import FunBot.Sources
  26. import FunBot.Types
  27. import Network.IRC.Fun.Bot (runBot)
  28. import Network.IRC.Fun.Bot.Behavior (defaultBehavior)
  29. import Network.IRC.Fun.Bot.EventMatch
  30. import Network.IRC.Fun.Bot.Types (Behavior (..))
  31. -- | Bot environment content
  32. env saveS saveM = BotEnv
  33. { webHookSourcePort = C.webListenerPort
  34. , saveSettings = saveS
  35. , saveMemos = saveM
  36. , feedErrorLogFile = C.feedErrorLogFile
  37. }
  38. -- | Initial content of the bot state
  39. initialState sets ms = BotState
  40. { settings = sets
  41. , stree = empty
  42. , memos = ms
  43. }
  44. -- | Event detector specification
  45. matchers =
  46. [ matchPrefixedCommandC
  47. , matchRefCommandFromSetC
  48. , matchRefCommandFromNamesP ["help", "info", "echo", "tell", "get"]
  49. , matchRef
  50. , defaultMatch
  51. ]
  52. -- | Bot behavior definition
  53. behavior = defaultBehavior
  54. { handleJoin = H.handleJoin
  55. , handleMsg = H.handleMsg
  56. , handleBotMsg = H.handleBotMsg
  57. , commandSets = [commandSet]
  58. , handleNickChange = H.handleNickChange
  59. }
  60. -- | Additional events sources
  61. mkSources state =
  62. [ webListenerSource
  63. , feedWatcherSource C.feedErrorLogFile state
  64. ]
  65. main = do
  66. liftIO $ putStrLn "Loading bot settings"
  67. sets <- loadBotSettings
  68. ms <- loadBotMemos
  69. saveS <- mkSaveBotSettings
  70. saveM <- mkSaveBotMemos
  71. let state = initialState sets ms
  72. runBot
  73. C.configuration
  74. matchers
  75. behavior
  76. (mkSources state)
  77. handler
  78. (env saveS saveM)
  79. state
  80. initTree