Skip to content

Commit

Permalink
Fix ToJSON ChannelType instance (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
MorrowM authored Oct 14, 2024
1 parent d00b35d commit a6f8c27
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions calamity/Calamity/Types/Model/Channel/ChannelType.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,19 @@ $(deriveTextShow ''ChannelType)
$(makeFieldLabelsNoPrefix ''ChannelType)

instance Aeson.ToJSON ChannelType where
toJSON t = Aeson.toJSON (fromEnum t)
toEncoding t = Aeson.toEncoding (fromEnum t)
toJSON t = Aeson.Number $ case t of
GuildTextType -> 0
DMType -> 1
GuildVoiceType -> 2
GroupDMType -> 3
GuildCategoryType -> 4
GuildNewsType -> 5
GuildNewsThreadType -> 10
GuildPublicThreadType -> 11
GuildPrivateThreadType -> 12
GuildStageVoiceType -> 13
GuildDirectoryType -> 14
GuildForumType -> 15

instance Aeson.FromJSON ChannelType where
parseJSON = Aeson.withScientific "ChannelType" $ \n -> case toBoundedInteger @Int n of
Expand Down

0 comments on commit a6f8c27

Please sign in to comment.