mirror of
https://gitlab.com/upRootNutrition/website.git
synced 2025-06-16 04:25:11 -05:00
feat: push for isaac
This commit is contained in:
parent
5ada6b4d25
commit
e6b3e90698
27 changed files with 377 additions and 4 deletions
|
@ -1,4 +1,41 @@
|
|||
-- allows "string literals" to be Text
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Main where
|
||||
|
||||
import Control.Monad (void, when)
|
||||
import Data.Text (Text, isPrefixOf, toLower)
|
||||
import Data.Text.IO as TIO
|
||||
import Discord
|
||||
import Discord.Requests as R
|
||||
import Discord.Types
|
||||
import UnliftIO.Concurrent
|
||||
|
||||
-- | Replies "pong" to every message that starts with "ping"
|
||||
main :: IO ()
|
||||
main = putStrLn "Hello, World!"
|
||||
main = do
|
||||
userFacingError <-
|
||||
runDiscord $
|
||||
def
|
||||
{ discordToken = "Bot ZZZZZZZZZZZZZZZZZZZ",
|
||||
discordOnEvent = eventHandler,
|
||||
discordOnLog = \s -> TIO.putStrLn s >> TIO.putStrLn ""
|
||||
} -- if you see OnLog error, post in the discord / open an issue
|
||||
TIO.putStrLn userFacingError
|
||||
|
||||
-- userFacingError is an unrecoverable error
|
||||
-- put normal 'cleanup' code in discordOnEnd (see examples)
|
||||
|
||||
eventHandler :: Event -> DiscordHandler ()
|
||||
eventHandler event = case event of
|
||||
MessageCreate m -> when (isPing m && not (fromBot m)) $ do
|
||||
void $ restCall (R.CreateReaction (messageChannelId m, messageId m) "eyes")
|
||||
threadDelay (2 * 10 ^ 6)
|
||||
void $ restCall (R.CreateMessage (messageChannelId m) "Pong!")
|
||||
_ -> return ()
|
||||
|
||||
fromBot :: Message -> Bool
|
||||
fromBot = userIsBot . messageAuthor
|
||||
|
||||
isPing :: Message -> Bool
|
||||
isPing = ("ping" `isPrefixOf`) . toLower . messageContent
|
Loading…
Add table
Add a link
Reference in a new issue