    -- | Look up sequences in the Online Encyclopedia of Integer Sequences
    --   Based on the Math.OEIS library
    module Lambdabot.Plugin.Reference.OEIS (oeisPlugin) where

    import Lambdabot.Plugin

    import Math.OEIS
    import Data.Char

    oeisPlugin :: Module ()
    oeisPlugin :: Module ()
    oeisPlugin = Module ()
    forall st. Module st
    newModule
        { moduleCmds = return
            [ (command "oeis")
                { aliases = ["sequence"]
                , help = say "oeis <sequence>. Look up a sequence in the Online Encyclopedia of Integer Sequences"
                , process = ios80 . lookupOEIS'
                }
            ]
        }

    lookupOEIS' :: String -> IO String
    lookupOEIS' :: String -> IO String
    lookupOEIS' String
    a = do
        let a' :: String
    a' = String -> String
    commas (String -> String) -> (String -> String) -> String -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> String
    forall a. [a] -> [a]
    reverse (String -> String) -> (String -> String) -> String -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> Bool) -> String -> String
    forall a. (a -> Bool) -> [a] -> [a]
    dropWhile Char -> Bool
    isSpace (String -> String) -> (String -> String) -> String -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> String
    forall a. [a] -> [a]
    reverse (String -> String) -> (String -> String) -> String -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> Bool) -> String -> String
    forall a. (a -> Bool) -> [a] -> [a]
    dropWhile Char -> Bool
    isSpace (String -> String) -> String -> String
    forall a b. (a -> b) -> a -> b
    $ String
    a
        x <- String -> IO (Maybe OEISSequence)
    searchSequence_IO String
    a'
        case x of
            Maybe OEISSequence
    Nothing -> String -> IO String
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return String
    "Sequence not found."
            Just OEISSequence
    s  -> String -> IO String
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (String -> IO String) -> String -> IO String
    forall a b. (a -> b) -> a -> b
    $ [String] -> String
    unlines [
                [String] -> String
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat (String
    "https://oeis.org/" String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    : Int -> [String] -> [String]
    forall a. Int -> [a] -> [a]
    take Int
    1 (OEISSequence -> [String]
    catalogNums OEISSequence
    s)) String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++
                Char
    ' ' Char -> String -> String
    forall a. a -> [a] -> [a]
    : OEISSequence -> String
    description OEISSequence
    s,
                SequenceData -> String
    forall a. Show a => a -> String
    show (SequenceData -> String) -> SequenceData -> String
    forall a b. (a -> b) -> a -> b
    $ OEISSequence -> SequenceData
    sequenceData OEISSequence
    s]
      where
        commas :: String -> String
    commas []                     = []
        commas (Char
    x:Char
    ' ':String
    xs) | Char -> Bool
    isDigit Char
    x = Char
    x Char -> String -> String
    forall a. a -> [a] -> [a]
    : Char
    ',' Char -> String -> String
    forall a. a -> [a] -> [a]
    : String -> String
    commas String
    xs
        commas (Char
    x:String
    xs)                 = Char
    x Char -> String -> String
    forall a. a -> [a] -> [a]
    : String -> String
    commas String
    xs