-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
157 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
module Main where | ||
|
||
import Control.Monad (forever) | ||
import Control.Concurrent.MVar (MVar, newMVar, swapMVar) | ||
import Control.Monad.Extra | ||
import Data.Maybe (fromMaybe) | ||
import Data.Text (pack) | ||
import LoadEnv (loadEnv) | ||
import System.Environment (getEnv, lookupEnv) | ||
import System.Process | ||
import Tablebot (runTablebot) | ||
import Tablebot.Internal.Administration | ||
import Tablebot.Plugins (plugins) | ||
|
||
-- @main@ runs forever. This allows bot reloading by fully shutting down the bot and letting it restart. | ||
main :: IO () | ||
main = forever $ do | ||
loadEnv | ||
dToken <- pack <$> getEnv "DISCORD_TOKEN" | ||
prefix <- pack . fromMaybe "!" <$> lookupEnv "PREFIX" | ||
dbpath <- getEnv "SQLITE_FILENAME" | ||
runTablebot dToken prefix dbpath plugins | ||
main = do | ||
rFlag <- newMVar Reload :: IO (MVar ShutdownReason) | ||
whileM $ do | ||
_ <- swapMVar rFlag Reload | ||
loadEnv | ||
dToken <- pack <$> getEnv "DISCORD_TOKEN" | ||
prefix <- pack . fromMaybe "!" <$> lookupEnv "PREFIX" | ||
dbpath <- getEnv "SQLITE_FILENAME" | ||
runTablebot dToken prefix dbpath (plugins rFlag) | ||
exit <- swapMVar rFlag Reload | ||
restartAction exit | ||
pure $ not (restartIsTerminal exit) | ||
putStrLn "Tablebot closed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters