From acec267e6fc29c3142191a1e0402a66cacb60274 Mon Sep 17 00:00:00 2001 From: Antoine COMBET Date: Fri, 4 Feb 2022 22:24:41 +0100 Subject: [PATCH] Started work --- .gitignore | 2 ++ LICENSE | 26 ++++++++++++++++++++++++++ README.org | 6 ++++++ app/Main.hs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ botiut.cabal | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 122 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 app/Main.hs create mode 100644 botiut.cabal diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..046a308 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +dist-newstyle +*.secret \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6bc5399 --- /dev/null +++ b/LICENSE @@ -0,0 +1,26 @@ +Copyright © 2022 Antoine "Annwan" COMBET + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.org b/README.org index 804a36e..f33c8a4 100644 --- a/README.org +++ b/README.org @@ -1,3 +1,9 @@ #+title: botiut #+author: Annwan +** TODO List [0/3] +- [ ] Framework +- [ ] Time table [0/2] + - [ ] =edt= command + - [ ] Messages in channel +- [ ] Reminders diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..8f06d15 --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,50 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Main where + +import Control.Monad + +import qualified Data.Text as T +import qualified Data.Text.IO as TIO + +import UnliftIO (liftIO) + +import Discord +import Discord.Types +import qualified Discord.Requests as R + +cmdPrefix :: T.Text +cmdPrefix = "%" + +main :: IO () +main = do + tok <- TIO.readFile "./auth.secret" + err <- runDiscord $ def { discordToken = tok + , discordOnStart = onDiscordStart + , discordOnEnd = liftIO $ putStrLn "Ended" + , discordOnEvent = onDiscordEvent + , discordOnLog = + \s -> TIO.putStrLn s >> TIO.putStrLn "" + } + TIO.putStrLn err + +onDiscordStart :: DiscordHandler () +onDiscordStart = undefined + +onDiscordEvent :: Event -> DiscordHandler () +onDiscordEvent (MessageCreate m) = when (not (fromBot m) && isCommand m) $ do + let content = messageContent m + let elements = T.words content + case head elements of + _ -> unknownCommand m elements + return () +onDiscordEvent _ = return () + +fromBot :: Message -> Bool +fromBot = userIsBot . messageAuthor + +unknownCommand :: Message -> [Text] -> DiscordHandler () +unknownCommand = + +isCommand :: Message ->Bool +isCommand = (cmdPrefix `T.isPrefixOf`) . messageContent diff --git a/botiut.cabal b/botiut.cabal new file mode 100644 index 0000000..cb23917 --- /dev/null +++ b/botiut.cabal @@ -0,0 +1,38 @@ +cabal-version: 2.4 +name: botiut +version: 0.1.0.0 + +-- A short (one-line) description of the package. +synopsis: A discord bot + +-- A longer description of the package. +description: A discord bot + +-- A URL where users can report bugs. +-- bug-reports: + +-- The license under which the package is released. +license: BSD-3-Clause +author: Antoine "Annwan" COMBET +maintainer: annwan@outlook.fr + +-- category: +extra-source-files: + README.org + +executable botiut + main-is: Main.hs + + -- Modules included in this executable, other than Main. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + -- other-extensions: + build-depends: + base ^>=4.15.0.0 + , discord-haskell + , control-event + , text + , unliftio + hs-source-dirs: app + default-language: Haskell2010