git.iko.soy/rowtype-yoga/royo
on main help sign in
Only run messageUpdateHandler on code evaluations
f4722cePureFunctor
src/Discord/DiscordJS.purs+1
@@ -40,6 +40,7 @@ type Message =
40 { channel ∷ Channel
40 { channel ∷ Channel
41 , content ∷ String {- not really... -}
41 , content ∷ String {- not really... -}
42 , author ∷ User
42 , author ∷ User
43+ , id ∷ String {- Snowflake ~ String -}
43 }
44 }
44
45
45foreign import removeAllReactionsImpl ∷ Message -> Effect (Promise Unit)
46foreign import removeAllReactionsImpl ∷ Message -> Effect (Promise Unit)
src/Royo/Discord/Bot.purs+6−6
@@ -12,7 +12,7 @@ import Data.String (Pattern(..), contains, drop, length, stripPrefix, stripSuffi
12import Data.String.NonEmpty.Internal (NonEmptyString(..))
12import Data.String.NonEmpty.Internal (NonEmptyString(..))
13import Data.String.NonEmpty.Internal as NES
13import Data.String.NonEmpty.Internal as NES
14import Data.String.Utils (startsWith)
14import Data.String.Utils (startsWith)
15−import Discord.DiscordJS (ChannelType(..), DiscordToken, Message, createDMChannel, getChannelType, login, newClient, onMessage, onMessageUpdate, react, removeAllReactions, sendString)
15+import Discord.DiscordJS (DiscordToken, Message, createDMChannel, login, newClient, onMessage, onMessageUpdate, react, sendString)
16import Effect.Aff (Aff, attempt, launchAff_, message)
16import Effect.Aff (Aff, attempt, launchAff_, message)
17import Effect.Class (liftEffect)
17import Effect.Class (liftEffect)
18import Effect.Class.Console (log)
18import Effect.Class.Console (log)
@@ -45,9 +45,9 @@ runBot yogaToken discordToken = do
45 client # onMessageUpdate (launchAff_ `map map map` messageUpdatedHandler) # liftEffect
45 client # onMessageUpdate (launchAff_ `map map map` messageUpdatedHandler) # liftEffect
46 where
46 where
47 messageUpdatedHandler _ msg = printErrors msg do
47 messageUpdatedHandler _ msg = printErrors msg do
48− when (getChannelType msg.channel == TextChannel) $ removeAllReactions msg
48+ when (isMention msg.content) do
49− msg # react rewindEmoji
49+ msg # react rewindEmoji
50− messageHandler msg
50+ messageHandler msg
51
51
52 messageHandler msg@{ content, channel } = printErrors msg do
52 messageHandler msg@{ content, channel } = printErrors msg do
53 when (isMention content) do
53 when (isMention content) do
@@ -59,10 +59,10 @@ runBot yogaToken discordToken = do
59 case res of
59 case res of
60 Left cr -> sendCompileProblem msg code cr
60 Left cr -> sendCompileProblem msg code cr
61 Right rr -> case NES.fromString rr.stdout, NES.fromString rr.stderr of
61 Right rr -> case NES.fromString rr.stdout, NES.fromString rr.stderr of
62− Just stdout, _ -> do
62+ Just _, _ -> do
63 msg # react robotMuscleEmoji
63 msg # react robotMuscleEmoji
64 channel # sendString (NonEmptyString (prepareOutput rr.stdout))
64 channel # sendString (NonEmptyString (prepareOutput rr.stdout))
65− Nothing, Just stderr -> do
65+ Nothing, Just _ -> do
66 msg # react sirenEmoji
66 msg # react sirenEmoji
67 sendRunProblem msg code rr.stderr
67 sendRunProblem msg code rr.stderr
68 _, _ -> channel # sendString (NonEmptyString "Something is weird")
68 _, _ -> channel # sendString (NonEmptyString "Something is weird")