-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#64] Add possibility to run tzbot as server
Problem: only server-like Slack apps can be published in the Slack App Directory. Solution: Allow to choose how to run the server, using common handler functions.
- Loading branch information
1 parent
635077e
commit 7c3ff2b
Showing
17 changed files
with
647 additions
and
143 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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
-- SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io/> | ||
-- | ||
-- SPDX-License-Identifier: MPL-2.0 | ||
|
||
module TzBot.BotMain.Common where | ||
|
||
import Universum | ||
|
||
import Control.Monad.Managed (Managed, managed) | ||
import Network.HTTP.Client (newManager) | ||
import Network.HTTP.Client.TLS (tlsManagerSettings) | ||
import Time (hour) | ||
|
||
import TzBot.Cache | ||
(TzCacheSettings(tcsExpiryRandomAmplitudeFraction), defaultTzCacheSettings, withTzCache, | ||
withTzCacheDefault) | ||
import TzBot.Config | ||
import TzBot.Config.Types (BotConfig) | ||
import TzBot.Logger | ||
import TzBot.RunMonad | ||
import TzBot.Util | ||
|
||
withBotState :: BotConfig -> Managed BotState | ||
withBotState bsConfig@Config {..} = do | ||
let fifteenPercentAmplitudeSettings = defaultTzCacheSettings | ||
{ tcsExpiryRandomAmplitudeFraction = Just 0.15 | ||
} | ||
|
||
bsManager <- liftIO $ newManager tlsManagerSettings | ||
bsFeedbackConfig <- | ||
managed $ withFeedbackConfig bsConfig | ||
bsUserInfoCache <- | ||
managed $ withTzCache fifteenPercentAmplitudeSettings cCacheUsersInfo | ||
|
||
bsConversationMembersCache <- | ||
managed $ withTzCache fifteenPercentAmplitudeSettings cCacheConversationMembers | ||
let defaultMessageInfoCachingTime = hour 1 | ||
bsMessageCache <- | ||
managed $ withTzCacheDefault defaultMessageInfoCachingTime | ||
bsMessageLinkCache <- | ||
managed $ withTzCacheDefault defaultMessageInfoCachingTime | ||
bsReportEntries <- | ||
managed $ withTzCacheDefault cCacheReportDialog | ||
-- auto-acknowledge received messages | ||
(bsLogNamespace, bsLogContext, bsLogEnv) <- managed $ withLogger cLogLevel | ||
pure BotState {..} | ||
|
||
withFeedbackConfig :: BotConfig -> (FeedbackConfig -> IO a) -> IO a | ||
withFeedbackConfig Config {..} action = do | ||
let fcFeedbackChannel = cFeedbackChannel | ||
withFeedbackFile cFeedbackFile $ \fcFeedbackFile -> | ||
action FeedbackConfig {..} | ||
where | ||
withFeedbackFile :: Maybe FilePath -> (Maybe Handle -> IO a) -> IO a | ||
withFeedbackFile mbPath action = | ||
withMaybe mbPath (action Nothing) $ \path -> | ||
withFile path AppendMode (action . Just) |
Oops, something went wrong.