simmsb/calamity

can reply but can't tell with bindSemToIO

Miezhiko opened this issue · 4 comments

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

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

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

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

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