summaryrefslogtreecommitdiff
path: root/deps/discord-haskell/docs/design.md
blob: a642b93190071eb7813354d4b50526ed05dc1434 (plain)
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
### Design

```haskell
~> :info runDiscord
runDiscord :: RunDiscordOpts -> IO T.Text {- Text is user facing error. Print it -}

~> :info RunDiscordOpts
data RunDiscordOpts = RunDiscordOpts
    { discordToken :: T.Text
    , discordOnStart :: DiscordHandler ()
    , discordOnEnd :: IO ()
    , discordOnEvent :: Event -> DiscordHandler ()  -- response to action
    , discordOnLog :: Text -> IO ()
    , discordForkThreadForEvents :: Bool
    }

~> :info DiscordHandler
type DiscordHandler = ReaderT DiscordHandle IO

{- ReaderT for access to the Handle -}

{- Event handlers and Options for the program

  An exception in discordOnStart exits the program immediately
  An exception in discordOnEvent continues loop

-}

 ~> :info DiscordHandle
data DiscordHandle = DiscordHandle
    { --[[ Some internal data that you normally won't use ]]
      --[[ Makes sure we don't violate rate-limits! ]]
      --[[ Threadsafe access ]]
    }

{- Import Discord.Handle to view the insides -}

```


#### Internals

Use `Chan`s to pass data between threads.

#### Websocket loop

Make user handle events as they happen

#### Rest request loop

Allow executing rest requests without overstepping ratelimits