diff options
| author | LLLL Colonq <llll@colonq> | 2023-11-16 19:06:43 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2023-11-16 19:06:43 -0500 |
| commit | dcef0b65069fb38fd0f6c4382353167f603ebff1 (patch) | |
| tree | 45954ffe308c3dd056e6af4f734e6d2af89e5856 /deps/discord-haskell/examples/ExampleUtils.hs | |
Initial commit
Diffstat (limited to 'deps/discord-haskell/examples/ExampleUtils.hs')
| -rw-r--r-- | deps/discord-haskell/examples/ExampleUtils.hs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/deps/discord-haskell/examples/ExampleUtils.hs b/deps/discord-haskell/examples/ExampleUtils.hs new file mode 100644 index 0000000..517178b --- /dev/null +++ b/deps/discord-haskell/examples/ExampleUtils.hs @@ -0,0 +1,29 @@ +module ExampleUtils where + +import qualified Data.Text as T +import qualified Data.Text.IO as TIO +import Discord +import qualified Discord.Requests as R +import Discord.Types +import Text.Read (readMaybe) + +getToken :: IO T.Text +getToken = TIO.readFile "./examples/auth-token.secret" + +getGuildId :: IO GuildId +getGuildId = do + gids <- readFile "./examples/guildid.secret" + case readMaybe gids of + Just g -> pure g + Nothing -> error "could not read guild id from `guildid.secret`" + +-- | Given the test server and an action operating on a channel id, get the +-- first text channel of that server and use the action on that channel. +actionWithChannelId :: GuildId -> (ChannelId -> DiscordHandler a) -> DiscordHandler a +actionWithChannelId testserverid f = do + Right chans <- restCall $ R.GetGuildChannels testserverid + (f . channelId) (head (filter isTextChannel chans)) + where + isTextChannel :: Channel -> Bool + isTextChannel ChannelText {} = True + isTextChannel _ = False |
