simmsb / calamity

A library for writing discord bots in haskell
https://hackage.haskell.org/package/calamity
MIT License
109 stars 11 forks source link

can reply but can't tell with bindSemToIO #60

Closed Miezhiko closed 1 year ago

Miezhiko commented 1 year ago

I try to add two methods

handleFailByLogging $ do
      messageIO <- bindSemToIO messageWithSnowflake
      replyIO   <- bindSemToIO replyWithSnowflake 
      void $ P.embed
           $ forkIO
           $ runKafkaConsumer (cfg ^. #kafkaAddress)
                               messageIO replyIO
messageWithSnowflake ∷ (BotC r)
                    => (Snowflake Channel, Text)
                    -> P.Sem r ()
messageWithSnowflake (chanId, txt) = do
  chanUpgrade <- upgrade chanId
  case chanUpgrade of
    Just chan -> void $ invoke (CreateMessage chan (def & #content ?~ txt))
    Nothing   -> pure ()

replyWithSnowflake ∷ (BotC r, HasID Channel Message)
                  => (Snowflake Message, Text)
                  -> P.Sem r ()
replyWithSnowflake (msgId, txt) = do
  maybeMsgFromId <- getMessage msgId
  case maybeMsgFromId of
    Just msgFromId -> void $ reply @Text msgFromId txt
    Nothing        -> pure ()

also was trying with messageWithSnowflake (chan, txt) = void $ tell @Text chan txt

and with some reason replyIO is working but msgIO is not when I'm trying just to send message on channel, no error messages either but possibly I just can't see prints inside it... what is possibly going wrong or how can I find out

simmsb commented 1 year ago

You don't need the full channel to send a message, so does this work at all?

messageWithSnowflake ∷ (BotC r)
                    => (Snowflake Channel, Text)
                    -> P.Sem r ()
messageWithSnowflake (chanId, txt) = do
  void $ invoke (CreateMessage chanId (def & #content ?~ txt))

you could also try printing the response:

messageWithSnowflake ∷ (BotC r)
                    => (Snowflake Channel, Text)
                    -> P.Sem r ()
messageWithSnowflake (chanId, txt) = do
  r <- invoke (CreateMessage chanId (def & #content ?~ txt))
  print r
Miezhiko commented 1 year ago

first code doesn't work, seems like, print has different type (IO)

simmsb commented 1 year ago
messageWithSnowflake ∷ (BotC r)
                    => (Snowflake Channel, Text)
                    -> P.Sem r ()
messageWithSnowflake (chanId, txt) = do
  r <- invoke (CreateMessage chanId (def & #content ?~ txt))
  P.embed $ print r
Miezhiko commented 1 year ago

sorry, issue was on my side, even not in code but I've used to run old version >_<