{-# OPTIONS_GHC -fno-warn-orphans #-}

-- | 'ParameterParser' instances for calamity models
module Calamity.Commands.CalamityParsers () where

import Calamity.Cache.Eff
import Calamity.Commands.Context
import Calamity.Types.Model.Channel (Channel, GuildChannel)
import Calamity.Types.Model.Guild (Emoji, Guild, Member, Partial (PartialEmoji), RawEmoji (..), Role)
import Calamity.Types.Model.User (User)
import Calamity.Types.Partial
import Calamity.Types.Snowflake
import CalamityCommands.ParameterInfo
import CalamityCommands.Parser
import Control.Monad
import Control.Monad.Trans (lift)
import Data.Maybe (fromMaybe, isJust)
import Data.Text qualified as T
import Data.Typeable
import Optics
import Polysemy qualified as P
import Polysemy.Reader qualified as P
import Text.Megaparsec hiding (parse)
import Text.Megaparsec.Char.Lexer (decimal)
import Text.Megaparsec.Error.Builder (errFancy, fancy)

parserName :: forall a c r. ParameterParser a c r => T.Text
parserName :: forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName =
  let ParameterInfo (Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" -> Text
name) TypeRep
type_ Text
_ = forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
ParameterInfo
parameterInfo @a @c @r
   in Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (TypeRep -> String
forall a. Show a => a -> String
show TypeRep
type_)

instance Typeable (Snowflake a) => ParameterParser (Snowflake a) c r where
  parse :: Sem (ParserEffs c r) (ParserResult (Snowflake a))
parse = Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake a)
-> Sem (ParserEffs c r) (Snowflake a)
forall c (r :: [(* -> *) -> * -> *]) a.
Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> Sem (ParserEffs c r) a
parseMP (forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName @(Snowflake a)) ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake a)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake
  parameterDescription :: Text
parameterDescription = Text
"discord id"

-- | Accepts both plain IDs and mentions
instance {-# OVERLAPS #-} ParameterParser (Snowflake User) c r where
  parse :: Sem (ParserEffs c r) (ParserResult (Snowflake User))
parse = Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
-> Sem (ParserEffs c r) (Snowflake User)
forall c (r :: [(* -> *) -> * -> *]) a.
Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> Sem (ParserEffs c r) a
parseMP (forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName @(Snowflake User)) (ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
forall e (m :: * -> *) a.
MonadParsec e Text m =>
Text -> m (Snowflake a)
ping Text
"@") ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake)
  parameterDescription :: Text
parameterDescription = Text
"user mention or id"

-- | Accepts both plain IDs and mentions
instance {-# OVERLAPS #-} ParameterParser (Snowflake Member) c r where
  parse :: Sem (ParserEffs c r) (ParserResult (Snowflake Member))
parse = Text
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
-> Sem (ParserEffs c r) (Snowflake Member)
forall c (r :: [(* -> *) -> * -> *]) a.
Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> Sem (ParserEffs c r) a
parseMP (forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName @(Snowflake Member)) (ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Text
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
forall e (m :: * -> *) a.
MonadParsec e Text m =>
Text -> m (Snowflake a)
ping Text
"@") ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake)
  parameterDescription :: Text
parameterDescription = Text
"user mention or id"

-- | Accepts both plain IDs and mentions
instance {-# OVERLAPS #-} ParameterParser (Snowflake Channel) c r where
  parse :: Sem (ParserEffs c r) (ParserResult (Snowflake Channel))
parse = Text
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Channel)
-> Sem (ParserEffs c r) (Snowflake Channel)
forall c (r :: [(* -> *) -> * -> *]) a.
Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> Sem (ParserEffs c r) a
parseMP (forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName @(Snowflake Channel)) (ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Channel)
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Channel)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Text
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Channel)
forall e (m :: * -> *) a.
MonadParsec e Text m =>
Text -> m (Snowflake a)
ping Text
"#") ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Channel)
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Channel)
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Channel)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Channel)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake)
  parameterDescription :: Text
parameterDescription = Text
"channel mention or id"

-- | Accepts both plain IDs and mentions
instance {-# OVERLAPS #-} ParameterParser (Snowflake Role) c r where
  parse :: Sem (ParserEffs c r) (ParserResult (Snowflake Role))
parse = Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
-> Sem (ParserEffs c r) (Snowflake Role)
forall c (r :: [(* -> *) -> * -> *]) a.
Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> Sem (ParserEffs c r) a
parseMP (forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName @(Snowflake Role)) (ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
forall e (m :: * -> *) a.
MonadParsec e Text m =>
Text -> m (Snowflake a)
ping Text
"@&") ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake)
  parameterDescription :: Text
parameterDescription = Text
"role mention or id"

-- | Accepts both plain IDs and uses of emoji
instance {-# OVERLAPS #-} ParameterParser (Snowflake Emoji) c r where
  parse :: Sem (ParserEffs c r) (ParserResult (Snowflake Emoji))
parse = Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
-> Sem (ParserEffs c r) (Snowflake Emoji)
forall c (r :: [(* -> *) -> * -> *]) a.
Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> Sem (ParserEffs c r) a
parseMP (forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName @(Snowflake Emoji)) (ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
emoji ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake)
  parameterDescription :: Text
parameterDescription = Text
"emoji or id"

mapParserMaybeM :: (Monad m, Stream s) => ParsecT SpannedError s m a -> T.Text -> (a -> m (Maybe b)) -> ParsecT SpannedError s m b
mapParserMaybeM :: forall (m :: * -> *) s a b.
(Monad m, Stream s) =>
ParsecT SpannedError s m a
-> Text -> (a -> m (Maybe b)) -> ParsecT SpannedError s m b
mapParserMaybeM ParsecT SpannedError s m a
m Text
e a -> m (Maybe b)
f = do
  Int
offs <- ParsecT SpannedError s m Int
forall e s (m :: * -> *). MonadParsec e s m => m Int
getOffset
  Maybe b
r <- ParsecT SpannedError s m a
m ParsecT SpannedError s m a
-> (a -> ParsecT SpannedError s m (Maybe b))
-> ParsecT SpannedError s m (Maybe b)
forall a b.
ParsecT SpannedError s m a
-> (a -> ParsecT SpannedError s m b) -> ParsecT SpannedError s m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= m (Maybe b) -> ParsecT SpannedError s m (Maybe b)
forall (m :: * -> *) a.
Monad m =>
m a -> ParsecT SpannedError s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Maybe b) -> ParsecT SpannedError s m (Maybe b))
-> (a -> m (Maybe b)) -> a -> ParsecT SpannedError s m (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m (Maybe b)
f
  Int
offe <- ParsecT SpannedError s m Int
forall e s (m :: * -> *). MonadParsec e s m => m Int
getOffset
  case Maybe b
r of
    Just b
r' -> b -> ParsecT SpannedError s m b
forall a. a -> ParsecT SpannedError s m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure b
r'
    Maybe b
Nothing -> ParseError s SpannedError -> ParsecT SpannedError s m b
forall a. ParseError s SpannedError -> ParsecT SpannedError s m a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
ParseError s e -> m a
parseError (ParseError s SpannedError -> ParsecT SpannedError s m b)
-> (SpannedError -> ParseError s SpannedError)
-> SpannedError
-> ParsecT SpannedError s m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> EF SpannedError -> ParseError s SpannedError
forall e s. Int -> EF e -> ParseError s e
errFancy Int
offs (EF SpannedError -> ParseError s SpannedError)
-> (SpannedError -> EF SpannedError)
-> SpannedError
-> ParseError s SpannedError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorFancy SpannedError -> EF SpannedError
forall e. ErrorFancy e -> EF e
fancy (ErrorFancy SpannedError -> EF SpannedError)
-> (SpannedError -> ErrorFancy SpannedError)
-> SpannedError
-> EF SpannedError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SpannedError -> ErrorFancy SpannedError
forall e. e -> ErrorFancy e
ErrorCustom (SpannedError -> ParsecT SpannedError s m b)
-> SpannedError -> ParsecT SpannedError s m b
forall a b. (a -> b) -> a -> b
$ Text -> Int -> Int -> SpannedError
SpannedError Text
e Int
offs Int
offe

{- | ParameterParser for members in the guild the command was invoked in, this only looks
 in the cache. Use @'Snowflake' 'Member'@ and use
 'Calamity.Types.Upgradeable.upgrade' if you want to allow fetching from http.
-}
instance (P.Member CacheEff r, CalamityCommandContext c) => ParameterParser Member c r where
  parse :: Sem (ParserEffs c r) (ParserResult Member)
parse =
    Text
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (ParserResult Member)
-> Sem (ParserEffs c r) (ParserResult Member)
forall c (r :: [(* -> *) -> * -> *]) a.
Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> Sem (ParserEffs c r) a
parseMP (forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName @Member @c @r) (ParsecT
   SpannedError Text (Sem (Reader c : r)) (ParserResult Member)
 -> Sem (ParserEffs c r) (ParserResult Member))
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (ParserResult Member)
-> Sem (ParserEffs c r) (ParserResult Member)
forall a b. (a -> b) -> a -> b
$
      ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
-> Text
-> (Snowflake Member -> Sem (Reader c : r) (Maybe Member))
-> ParsecT SpannedError Text (Sem (Reader c : r)) Member
forall (m :: * -> *) s a b.
(Monad m, Stream s) =>
ParsecT SpannedError s m a
-> Text -> (a -> m (Maybe b)) -> ParsecT SpannedError s m b
mapParserMaybeM
        (ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Text
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
forall e (m :: * -> *) a.
MonadParsec e Text m =>
Text -> m (Snowflake a)
ping Text
"@") ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Member)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake)
        Text
"Couldn't find a Member with this id"
        ( \Snowflake Member
mid -> do
            c
ctx <- Sem (Reader c : r) c
forall i (r :: [(* -> *) -> * -> *]).
Member (Reader i) r =>
Sem r i
P.ask
            Maybe Guild
guild <- Maybe (Maybe Guild) -> Maybe Guild
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Maybe (Maybe Guild) -> Maybe Guild)
-> Sem (Reader c : r) (Maybe (Maybe Guild))
-> Sem (Reader c : r) (Maybe Guild)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Snowflake Guild -> Sem (Reader c : r) (Maybe Guild)
forall (r :: [(* -> *) -> * -> *]).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild (Snowflake Guild -> Sem (Reader c : r) (Maybe Guild))
-> Maybe (Snowflake Guild)
-> Sem (Reader c : r) (Maybe (Maybe Guild))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
`traverse` c -> Maybe (Snowflake Guild)
forall c. CalamityCommandContext c => c -> Maybe (Snowflake Guild)
ctxGuildID c
ctx
            Maybe Member -> Sem (Reader c : r) (Maybe Member)
forall a. a -> Sem (Reader c : r) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Member -> Sem (Reader c : r) (Maybe Member))
-> Maybe Member -> Sem (Reader c : r) (Maybe Member)
forall a b. (a -> b) -> a -> b
$ Maybe Guild
guild Maybe Guild
-> Optic' An_AffineTraversal NoIx (Maybe Guild) Member
-> Maybe Member
forall k s (is :: IxList) a.
Is k An_AffineFold =>
s -> Optic' k is s a -> Maybe a
^? Prism (Maybe Guild) (Maybe Guild) Guild Guild
forall a b. Prism (Maybe a) (Maybe b) a b
_Just Prism (Maybe Guild) (Maybe Guild) Guild Guild
-> Optic
     A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
-> Optic
     An_AffineTraversal
     NoIx
     (Maybe Guild)
     (Maybe Guild)
     (SnowflakeMap Member)
     (SnowflakeMap Member)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
#members Optic
  An_AffineTraversal
  NoIx
  (Maybe Guild)
  (Maybe Guild)
  (SnowflakeMap Member)
  (SnowflakeMap Member)
-> Optic
     (IxKind (SnowflakeMap Member))
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     Member
     Member
-> Optic' An_AffineTraversal NoIx (Maybe Guild) Member
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Member)
-> Optic'
     (IxKind (SnowflakeMap Member))
     NoIx
     (SnowflakeMap Member)
     (IxValue (SnowflakeMap Member))
forall m. Ixed m => Index m -> Optic' (IxKind m) NoIx m (IxValue m)
ix Index (SnowflakeMap Member)
Snowflake Member
mid
        )
  parameterDescription :: Text
parameterDescription = Text
"user mention or id"

{- | ParameterParser for users, this only looks in the cache. Use @'Snowflake'
 'User'@ and use 'Calamity.Types.Upgradeable.upgrade' if you want to allow
 fetching from http.
-}
instance P.Member CacheEff r => ParameterParser User c r where
  parse :: Sem (ParserEffs c r) (ParserResult User)
parse =
    Text
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (ParserResult User)
-> Sem (ParserEffs c r) (ParserResult User)
forall c (r :: [(* -> *) -> * -> *]) a.
Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> Sem (ParserEffs c r) a
parseMP (forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName @User @c @r) (ParsecT SpannedError Text (Sem (Reader c : r)) (ParserResult User)
 -> Sem (ParserEffs c r) (ParserResult User))
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (ParserResult User)
-> Sem (ParserEffs c r) (ParserResult User)
forall a b. (a -> b) -> a -> b
$
      ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
-> Text
-> (Snowflake User -> Sem (Reader c : r) (Maybe User))
-> ParsecT SpannedError Text (Sem (Reader c : r)) User
forall (m :: * -> *) s a b.
(Monad m, Stream s) =>
ParsecT SpannedError s m a
-> Text -> (a -> m (Maybe b)) -> ParsecT SpannedError s m b
mapParserMaybeM
        (ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
forall e (m :: * -> *) a.
MonadParsec e Text m =>
Text -> m (Snowflake a)
ping Text
"@") ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake User)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake)
        Text
"Couldn't find a User with this id"
        Snowflake User -> Sem (Reader c : r) (Maybe User)
forall (r :: [(* -> *) -> * -> *]).
Member CacheEff r =>
Snowflake User -> Sem r (Maybe User)
getUser
  parameterDescription :: Text
parameterDescription = Text
"user mention or id"

{- | ParameterParser for channels in the guild the command was invoked in, this only
 looks in the cache. Use @'Snowflake' 'Channel'@ and use
 'Calamity.Types.Upgradeable.upgrade' if you want to allow fetching from http.
-}
instance (P.Member CacheEff r, CalamityCommandContext c) => ParameterParser GuildChannel c r where
  parse :: Sem (ParserEffs c r) (ParserResult GuildChannel)
parse =
    Text
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (ParserResult GuildChannel)
-> Sem (ParserEffs c r) (ParserResult GuildChannel)
forall c (r :: [(* -> *) -> * -> *]) a.
Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> Sem (ParserEffs c r) a
parseMP (forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName @GuildChannel @c @r) (ParsecT
   SpannedError Text (Sem (Reader c : r)) (ParserResult GuildChannel)
 -> Sem (ParserEffs c r) (ParserResult GuildChannel))
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (ParserResult GuildChannel)
-> Sem (ParserEffs c r) (ParserResult GuildChannel)
forall a b. (a -> b) -> a -> b
$
      ParsecT
  SpannedError Text (Sem (Reader c : r)) (Snowflake GuildChannel)
-> Text
-> (Snowflake GuildChannel
    -> Sem (Reader c : r) (Maybe GuildChannel))
-> ParsecT SpannedError Text (Sem (Reader c : r)) GuildChannel
forall (m :: * -> *) s a b.
(Monad m, Stream s) =>
ParsecT SpannedError s m a
-> Text -> (a -> m (Maybe b)) -> ParsecT SpannedError s m b
mapParserMaybeM
        (ParsecT
  SpannedError Text (Sem (Reader c : r)) (Snowflake GuildChannel)
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake GuildChannel)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Text
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake GuildChannel)
forall e (m :: * -> *) a.
MonadParsec e Text m =>
Text -> m (Snowflake a)
ping Text
"#") ParsecT
  SpannedError Text (Sem (Reader c : r)) (Snowflake GuildChannel)
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake GuildChannel)
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (Snowflake GuildChannel)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT
  SpannedError Text (Sem (Reader c : r)) (Snowflake GuildChannel)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake)
        Text
"Couldn't find a GuildChannel with this id"
        ( \Snowflake GuildChannel
cid -> do
            c
ctx <- Sem (Reader c : r) c
forall i (r :: [(* -> *) -> * -> *]).
Member (Reader i) r =>
Sem r i
P.ask
            Maybe Guild
guild <- Maybe (Maybe Guild) -> Maybe Guild
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Maybe (Maybe Guild) -> Maybe Guild)
-> Sem (Reader c : r) (Maybe (Maybe Guild))
-> Sem (Reader c : r) (Maybe Guild)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Snowflake Guild -> Sem (Reader c : r) (Maybe Guild)
forall (r :: [(* -> *) -> * -> *]).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild (Snowflake Guild -> Sem (Reader c : r) (Maybe Guild))
-> Maybe (Snowflake Guild)
-> Sem (Reader c : r) (Maybe (Maybe Guild))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
`traverse` c -> Maybe (Snowflake Guild)
forall c. CalamityCommandContext c => c -> Maybe (Snowflake Guild)
ctxGuildID c
ctx
            Maybe GuildChannel -> Sem (Reader c : r) (Maybe GuildChannel)
forall a. a -> Sem (Reader c : r) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe GuildChannel -> Sem (Reader c : r) (Maybe GuildChannel))
-> Maybe GuildChannel -> Sem (Reader c : r) (Maybe GuildChannel)
forall a b. (a -> b) -> a -> b
$ Maybe Guild
guild Maybe Guild
-> Optic' An_AffineTraversal NoIx (Maybe Guild) GuildChannel
-> Maybe GuildChannel
forall k s (is :: IxList) a.
Is k An_AffineFold =>
s -> Optic' k is s a -> Maybe a
^? Prism (Maybe Guild) (Maybe Guild) Guild Guild
forall a b. Prism (Maybe a) (Maybe b) a b
_Just Prism (Maybe Guild) (Maybe Guild) Guild Guild
-> Optic
     A_Lens
     NoIx
     Guild
     Guild
     (SnowflakeMap GuildChannel)
     (SnowflakeMap GuildChannel)
-> Optic
     An_AffineTraversal
     NoIx
     (Maybe Guild)
     (Maybe Guild)
     (SnowflakeMap GuildChannel)
     (SnowflakeMap GuildChannel)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
#channels Optic
  An_AffineTraversal
  NoIx
  (Maybe Guild)
  (Maybe Guild)
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
-> Optic
     (IxKind (SnowflakeMap GuildChannel))
     NoIx
     (SnowflakeMap GuildChannel)
     (SnowflakeMap GuildChannel)
     GuildChannel
     GuildChannel
-> Optic' An_AffineTraversal NoIx (Maybe Guild) GuildChannel
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap GuildChannel)
-> Optic'
     (IxKind (SnowflakeMap GuildChannel))
     NoIx
     (SnowflakeMap GuildChannel)
     (IxValue (SnowflakeMap GuildChannel))
forall m. Ixed m => Index m -> Optic' (IxKind m) NoIx m (IxValue m)
ix Index (SnowflakeMap GuildChannel)
Snowflake GuildChannel
cid
        )
  parameterDescription :: Text
parameterDescription = Text
"channel mention or id"

{- | ParameterParser for guilds, this only looks in the cache. Use @'Snowflake' 'Guild'@
 and use 'Calamity.Types.Upgradeable.upgrade' if you want to allow fetching
 from http.
-}
instance P.Member CacheEff r => ParameterParser Guild c r where
  parse :: Sem (ParserEffs c r) (ParserResult Guild)
parse =
    Text
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (ParserResult Guild)
-> Sem (ParserEffs c r) (ParserResult Guild)
forall c (r :: [(* -> *) -> * -> *]) a.
Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> Sem (ParserEffs c r) a
parseMP (forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName @Guild @c @r) (ParsecT
   SpannedError Text (Sem (Reader c : r)) (ParserResult Guild)
 -> Sem (ParserEffs c r) (ParserResult Guild))
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (ParserResult Guild)
-> Sem (ParserEffs c r) (ParserResult Guild)
forall a b. (a -> b) -> a -> b
$
      ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Guild)
-> Text
-> (Snowflake Guild -> Sem (Reader c : r) (Maybe Guild))
-> ParsecT SpannedError Text (Sem (Reader c : r)) Guild
forall (m :: * -> *) s a b.
(Monad m, Stream s) =>
ParsecT SpannedError s m a
-> Text -> (a -> m (Maybe b)) -> ParsecT SpannedError s m b
mapParserMaybeM
        ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Guild)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake
        Text
"Couldn't find a Guild with this id"
        Snowflake Guild -> Sem (Reader c : r) (Maybe Guild)
forall (r :: [(* -> *) -> * -> *]).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild
  parameterDescription :: Text
parameterDescription = Text
"guild id"

{- | ParameterParser for emojis in the guild the command was invoked in, this only
 looks in the cache. Use @'Snowflake' 'Emoji'@ and use
 'Calamity.Types.Upgradeable.upgrade' if you want to allow fetching from http.
-}
instance (P.Member CacheEff r, CalamityCommandContext c) => ParameterParser Emoji c r where
  parse :: Sem (ParserEffs c r) (ParserResult Emoji)
parse =
    Text
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (ParserResult Emoji)
-> Sem (ParserEffs c r) (ParserResult Emoji)
forall c (r :: [(* -> *) -> * -> *]) a.
Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> Sem (ParserEffs c r) a
parseMP (forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName @Emoji @c @r) (ParsecT
   SpannedError Text (Sem (Reader c : r)) (ParserResult Emoji)
 -> Sem (ParserEffs c r) (ParserResult Emoji))
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (ParserResult Emoji)
-> Sem (ParserEffs c r) (ParserResult Emoji)
forall a b. (a -> b) -> a -> b
$
      ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
-> Text
-> (Snowflake Emoji -> Sem (Reader c : r) (Maybe Emoji))
-> ParsecT SpannedError Text (Sem (Reader c : r)) Emoji
forall (m :: * -> *) s a b.
(Monad m, Stream s) =>
ParsecT SpannedError s m a
-> Text -> (a -> m (Maybe b)) -> ParsecT SpannedError s m b
mapParserMaybeM
        (ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
emoji ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Emoji)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake)
        Text
"Couldn't find an Emoji with this id"
        ( \Snowflake Emoji
eid -> do
            c
ctx <- Sem (Reader c : r) c
forall i (r :: [(* -> *) -> * -> *]).
Member (Reader i) r =>
Sem r i
P.ask
            Maybe Guild
guild <- Maybe (Maybe Guild) -> Maybe Guild
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Maybe (Maybe Guild) -> Maybe Guild)
-> Sem (Reader c : r) (Maybe (Maybe Guild))
-> Sem (Reader c : r) (Maybe Guild)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Snowflake Guild -> Sem (Reader c : r) (Maybe Guild)
forall (r :: [(* -> *) -> * -> *]).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild (Snowflake Guild -> Sem (Reader c : r) (Maybe Guild))
-> Maybe (Snowflake Guild)
-> Sem (Reader c : r) (Maybe (Maybe Guild))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
`traverse` c -> Maybe (Snowflake Guild)
forall c. CalamityCommandContext c => c -> Maybe (Snowflake Guild)
ctxGuildID c
ctx
            Maybe Emoji -> Sem (Reader c : r) (Maybe Emoji)
forall a. a -> Sem (Reader c : r) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Emoji -> Sem (Reader c : r) (Maybe Emoji))
-> Maybe Emoji -> Sem (Reader c : r) (Maybe Emoji)
forall a b. (a -> b) -> a -> b
$ Maybe Guild
guild Maybe Guild
-> Optic' An_AffineTraversal NoIx (Maybe Guild) Emoji
-> Maybe Emoji
forall k s (is :: IxList) a.
Is k An_AffineFold =>
s -> Optic' k is s a -> Maybe a
^? Prism (Maybe Guild) (Maybe Guild) Guild Guild
forall a b. Prism (Maybe a) (Maybe b) a b
_Just Prism (Maybe Guild) (Maybe Guild) Guild Guild
-> Optic
     A_Lens NoIx Guild Guild (SnowflakeMap Emoji) (SnowflakeMap Emoji)
-> Optic
     An_AffineTraversal
     NoIx
     (Maybe Guild)
     (Maybe Guild)
     (SnowflakeMap Emoji)
     (SnowflakeMap Emoji)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Emoji) (SnowflakeMap Emoji)
#emojis Optic
  An_AffineTraversal
  NoIx
  (Maybe Guild)
  (Maybe Guild)
  (SnowflakeMap Emoji)
  (SnowflakeMap Emoji)
-> Optic
     (IxKind (SnowflakeMap Emoji))
     NoIx
     (SnowflakeMap Emoji)
     (SnowflakeMap Emoji)
     Emoji
     Emoji
-> Optic' An_AffineTraversal NoIx (Maybe Guild) Emoji
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Emoji)
-> Optic'
     (IxKind (SnowflakeMap Emoji))
     NoIx
     (SnowflakeMap Emoji)
     (IxValue (SnowflakeMap Emoji))
forall m. Ixed m => Index m -> Optic' (IxKind m) NoIx m (IxValue m)
ix Index (SnowflakeMap Emoji)
Snowflake Emoji
eid
        )
  parameterDescription :: Text
parameterDescription = Text
"emoji or id"

-- | Parses both discord emojis, and unicode emojis
instance ParameterParser RawEmoji c r where
  parse :: Sem (ParserEffs c r) (ParserResult RawEmoji)
parse = Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) RawEmoji
-> Sem (ParserEffs c r) RawEmoji
forall c (r :: [(* -> *) -> * -> *]) a.
Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> Sem (ParserEffs c r) a
parseMP (forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName @RawEmoji) (ParsecT SpannedError Text (Sem (Reader c : r)) RawEmoji
-> ParsecT SpannedError Text (Sem (Reader c : r)) RawEmoji
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT SpannedError Text (Sem (Reader c : r)) RawEmoji
forall {f :: * -> *} {e}. MonadParsec e Text f => f RawEmoji
parseCustomEmoji ParsecT SpannedError Text (Sem (Reader c : r)) RawEmoji
-> ParsecT SpannedError Text (Sem (Reader c : r)) RawEmoji
-> ParsecT SpannedError Text (Sem (Reader c : r)) RawEmoji
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> RawEmoji
UnicodeEmoji (Text -> RawEmoji)
-> ParsecT SpannedError Text (Sem (Reader c : r)) Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) RawEmoji
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe String
-> Int
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> Int -> m (Tokens s)
takeP (String -> Maybe String
forall a. a -> Maybe a
Just String
"A unicode emoji") Int
1)
    where
      parseCustomEmoji :: f RawEmoji
parseCustomEmoji = Partial Emoji -> RawEmoji
CustomEmoji (Partial Emoji -> RawEmoji) -> f (Partial Emoji) -> f RawEmoji
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (Partial Emoji)
forall e (m :: * -> *). MonadParsec e Text m => m (Partial Emoji)
partialEmoji
  parameterDescription :: Text
parameterDescription = Text
"emoji"

{- | ParameterParser for roles in the guild the command was invoked in, this only
 looks in the cache. Use @'Snowflake' 'Role'@ and use
 'Calamity.Types.Upgradeable.upgrade' if you want to allow fetching from http.
-}
instance (P.Member CacheEff r, CalamityCommandContext c) => ParameterParser Role c r where
  parse :: Sem (ParserEffs c r) (ParserResult Role)
parse =
    Text
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (ParserResult Role)
-> Sem (ParserEffs c r) (ParserResult Role)
forall c (r :: [(* -> *) -> * -> *]) a.
Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> Sem (ParserEffs c r) a
parseMP (forall a c (r :: [(* -> *) -> * -> *]).
ParameterParser a c r =>
Text
parserName @Role @c @r) (ParsecT SpannedError Text (Sem (Reader c : r)) (ParserResult Role)
 -> Sem (ParserEffs c r) (ParserResult Role))
-> ParsecT
     SpannedError Text (Sem (Reader c : r)) (ParserResult Role)
-> Sem (ParserEffs c r) (ParserResult Role)
forall a b. (a -> b) -> a -> b
$
      ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
-> Text
-> (Snowflake Role -> Sem (Reader c : r) (Maybe Role))
-> ParsecT SpannedError Text (Sem (Reader c : r)) Role
forall (m :: * -> *) s a b.
(Monad m, Stream s) =>
ParsecT SpannedError s m a
-> Text -> (a -> m (Maybe b)) -> ParsecT SpannedError s m b
mapParserMaybeM
        (ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Text
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
forall e (m :: * -> *) a.
MonadParsec e Text m =>
Text -> m (Snowflake a)
ping Text
"@&") ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
-> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
forall a.
ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
-> ParsecT SpannedError Text (Sem (Reader c : r)) a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT SpannedError Text (Sem (Reader c : r)) (Snowflake Role)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake)
        Text
"Couldn't find an Emoji with this id"
        ( \Snowflake Role
rid -> do
            c
ctx <- Sem (Reader c : r) c
forall i (r :: [(* -> *) -> * -> *]).
Member (Reader i) r =>
Sem r i
P.ask
            Maybe Guild
guild <- Maybe (Maybe Guild) -> Maybe Guild
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Maybe (Maybe Guild) -> Maybe Guild)
-> Sem (Reader c : r) (Maybe (Maybe Guild))
-> Sem (Reader c : r) (Maybe Guild)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Snowflake Guild -> Sem (Reader c : r) (Maybe Guild)
forall (r :: [(* -> *) -> * -> *]).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild (Snowflake Guild -> Sem (Reader c : r) (Maybe Guild))
-> Maybe (Snowflake Guild)
-> Sem (Reader c : r) (Maybe (Maybe Guild))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
`traverse` c -> Maybe (Snowflake Guild)
forall c. CalamityCommandContext c => c -> Maybe (Snowflake Guild)
ctxGuildID c
ctx
            Maybe Role -> Sem (Reader c : r) (Maybe Role)
forall a. a -> Sem (Reader c : r) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Role -> Sem (Reader c : r) (Maybe Role))
-> Maybe Role -> Sem (Reader c : r) (Maybe Role)
forall a b. (a -> b) -> a -> b
$ Maybe Guild
guild Maybe Guild
-> Optic' An_AffineTraversal NoIx (Maybe Guild) Role -> Maybe Role
forall k s (is :: IxList) a.
Is k An_AffineFold =>
s -> Optic' k is s a -> Maybe a
^? Prism (Maybe Guild) (Maybe Guild) Guild Guild
forall a b. Prism (Maybe a) (Maybe b) a b
_Just Prism (Maybe Guild) (Maybe Guild) Guild Guild
-> Optic
     A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
-> Optic
     An_AffineTraversal
     NoIx
     (Maybe Guild)
     (Maybe Guild)
     (SnowflakeMap Role)
     (SnowflakeMap Role)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
#roles Optic
  An_AffineTraversal
  NoIx
  (Maybe Guild)
  (Maybe Guild)
  (SnowflakeMap Role)
  (SnowflakeMap Role)
-> Optic
     (IxKind (SnowflakeMap Role))
     NoIx
     (SnowflakeMap Role)
     (SnowflakeMap Role)
     Role
     Role
-> Optic' An_AffineTraversal NoIx (Maybe Guild) Role
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Role)
-> Optic'
     (IxKind (SnowflakeMap Role))
     NoIx
     (SnowflakeMap Role)
     (IxValue (SnowflakeMap Role))
forall m. Ixed m => Index m -> Optic' (IxKind m) NoIx m (IxValue m)
ix Index (SnowflakeMap Role)
Snowflake Role
rid
        )
  parameterDescription :: Text
parameterDescription = Text
"role mention or id"

-- skipN :: (Stream s, Ord e) => Int -> ParsecT e s m ()
-- skipN n = void $ takeP Nothing n

ping :: MonadParsec e T.Text m => T.Text -> m (Snowflake a)
ping :: forall e (m :: * -> *) a.
MonadParsec e Text m =>
Text -> m (Snowflake a)
ping Text
c = Tokens Text -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk (Text
"<" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
c) m (Tokens Text)
-> m (Maybe (Tokens Text)) -> m (Maybe (Tokens Text))
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m (Tokens Text) -> m (Maybe (Tokens Text))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Tokens Text -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk Tokens Text
"!") m (Maybe (Tokens Text)) -> m (Snowflake a) -> m (Snowflake a)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m (Snowflake a)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake m (Snowflake a) -> m (Tokens Text) -> m (Snowflake a)
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Tokens Text -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk Tokens Text
">"

ping' :: MonadParsec e T.Text m => m () -> m (Snowflake a)
ping' :: forall e (m :: * -> *) a.
MonadParsec e Text m =>
m () -> m (Snowflake a)
ping' m ()
m = Tokens Text -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk Tokens Text
"<" m (Tokens Text) -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m ()
m m () -> m (Snowflake a) -> m (Snowflake a)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m (Snowflake a)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake m (Snowflake a) -> m (Tokens Text) -> m (Snowflake a)
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Tokens Text -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk Tokens Text
">"

snowflake :: MonadParsec e T.Text m => m (Snowflake a)
snowflake :: forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake = Word64 -> Snowflake a
forall t. Word64 -> Snowflake t
Snowflake (Word64 -> Snowflake a) -> m Word64 -> m (Snowflake a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Word64
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
decimal

partialEmoji :: MonadParsec e T.Text m => m (Partial Emoji)
partialEmoji :: forall e (m :: * -> *). MonadParsec e Text m => m (Partial Emoji)
partialEmoji = do
  Bool
animated <- Maybe (Tokens Text) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe (Tokens Text) -> Bool) -> m (Maybe (Tokens Text)) -> m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Tokens Text -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk Tokens Text
"<" m (Tokens Text)
-> m (Maybe (Tokens Text)) -> m (Maybe (Tokens Text))
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m (Tokens Text) -> m (Maybe (Tokens Text))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Tokens Text -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk Tokens Text
"a"))
  Text
name <- m (Tokens Text) -> m (Tokens Text) -> m Text -> m Text
forall (m :: * -> *) open close a.
Applicative m =>
m open -> m close -> m a -> m a
between (Tokens Text -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk Tokens Text
":") (Tokens Text -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk Tokens Text
":") (Maybe String -> (Token Text -> Bool) -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP (String -> Maybe String
forall a. a -> Maybe a
Just String
"Emoji name") (Token Text -> Token Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
Token Text
':'))
  Snowflake Emoji
id <- m (Snowflake Emoji)
forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
snowflake
  m (Tokens Text) -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m (Tokens Text) -> m ()) -> m (Tokens Text) -> m ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk Tokens Text
">"
  Partial Emoji -> m (Partial Emoji)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Snowflake Emoji -> Text -> Bool -> Partial Emoji
PartialEmoji Snowflake Emoji
id Text
name Bool
animated)

emoji :: MonadParsec e T.Text m => m (Snowflake a)
emoji :: forall e (m :: * -> *) a. MonadParsec e Text m => m (Snowflake a)
emoji = m () -> m (Snowflake a)
forall e (m :: * -> *) a.
MonadParsec e Text m =>
m () -> m (Snowflake a)
ping' (m (Tokens Text) -> m (Maybe (Tokens Text))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Tokens Text -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk Tokens Text
"a") m (Maybe (Tokens Text)) -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m (Tokens Text) -> m (Tokens Text) -> m () -> m ()
forall (m :: * -> *) open close a.
Applicative m =>
m open -> m close -> m a -> m a
between (Tokens Text -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk Tokens Text
":") (Tokens Text -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk Tokens Text
":") (m (Tokens Text) -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m (Tokens Text) -> m ()) -> m (Tokens Text) -> m ()
forall a b. (a -> b) -> a -> b
$ Maybe String -> (Token Text -> Bool) -> m (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP Maybe String
forall a. Maybe a
Nothing (Token Text -> Token Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
Token Text
':')))

-- trackOffsets :: MonadParsec e s m => m a -> m (a, Int)
-- trackOffsets m = do
--   offs <- getOffset
--   a <- m
--   offe <- getOffset
--   pure (a, offe - offs)

-- item :: MonadParsec e L.Text m => m L.Text
-- item = try quotedString <|> someNonWS

-- manySingle :: MonadParsec e s m => m (Tokens s)
-- manySingle = takeWhileP (Just "Any character") (const True)

-- someSingle :: MonadParsec e s m => m (Tokens s)
-- someSingle = takeWhile1P (Just "any character") (const True)

-- quotedString :: MonadParsec e L.Text m => m L.Text
-- quotedString = try (between (chunk "'") (chunk "'") (takeWhileP (Just "any character") (/= '\''))) <|>
--                between (chunk "\"") (chunk "\"") (takeWhileP (Just "any character") (/= '"'))

-- -- manyNonWS :: (Token s ~ Char, MonadParsec e s m) => m (Tokens s)
-- -- manyNonWS = takeWhileP (Just "Any Non-Whitespace") (not . isSpace)

-- someNonWS :: (Token s ~ Char, MonadParsec e s m) => m (Tokens s)
-- someNonWS = takeWhile1P (Just "any non-whitespace") (not . isSpace)