Skip to content

Commit

Permalink
Merge pull request discord-haskell#179 from penelopeysm/emojis
Browse files Browse the repository at this point in the history
Extend emoji support
  • Loading branch information
L0neGamer authored Jul 22, 2023
2 parents 4d5dec4 + 7e87f0e commit 02c32f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion discord-haskell.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ library
base64-bytestring >=1.1 && <1.3,
containers >=0.6 && <0.7,
data-default >=0.7 && <0.8,
emoji ==0.1.*,
emojis >=0.1.2 && <0.2,
http-client >=0.6 && <0.8,
iso8601-time >=0.1 && <0.2,
MonadRandom >=0.5 && <0.7,
Expand Down
26 changes: 20 additions & 6 deletions src/Discord/Internal/Rest/Channel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Discord.Internal.Rest.Channel

import Data.Aeson
import Data.Default (Default, def)
import Data.Emoji (unicodeByName)
import Text.Emoji (emojiFromAlias)
import qualified Data.Text as T
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
Expand Down Expand Up @@ -401,11 +401,25 @@ channelMajorRoute c = case c of
cleanupEmoji :: T.Text -> T.Text
cleanupEmoji emoji =
let noAngles = T.replace "<" "" (T.replace ">" "" emoji)
byName = T.pack <$> unicodeByName (T.unpack (T.replace ":" "" emoji))
in case (byName, T.stripPrefix ":" noAngles) of
(Just e, _) -> e
(_, Just a) -> "custom:" <> a
(_, Nothing) -> noAngles
noColons = T.replace ":" "" emoji
toneModifier s = case s of
"tone1" -> Just "\x1f3fb"
"tone2" -> Just "\x1f3fc"
"tone3" -> Just "\x1f3fd"
"tone4" -> Just "\x1f3fe"
"tone5" -> Just "\x1f3ff"
_ -> Nothing
byName = case emojiFromAlias noColons of
Just e -> Just e
Nothing ->
let (prefix, tone) = T.breakOnEnd "_" noColons
in case ((fst <$> T.unsnoc prefix) >>= emojiFromAlias, toneModifier tone) of
(Just p, Just t) -> Just (p <> t)
_ -> Nothing
in case (byName, T.stripPrefix ":" noAngles) of
(Just e, _) -> e
(_, Just a) -> "custom:" <> a
(_, Nothing) -> noAngles

channels :: R.Url 'R.Https
channels = baseUrl /: "channels"
Expand Down
3 changes: 0 additions & 3 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ packages:

resolver: lts-18.28

extra-deps:
- emoji-0.1.0.2@sha256:d995572a5c7dcd28f98eb15c6e387a7b3bda1ac2477ab0d9dba8580d5d7b161f,1273


nix:
packages: [ zlib, gmp ]

0 comments on commit 02c32f3

Please sign in to comment.