masakazu-bot 0.1.0.0 → 0.2.0.0
raw patch · 3 files changed
+22/−17 lines, 3 filesdep −regex-compat
Dependencies removed: regex-compat
Files
- Main.hs +18/−15
- README.md +1/−0
- masakazu-bot.cabal +3/−2
Main.hs view
@@ -11,28 +11,25 @@ import Data.DateTime import qualified Data.ByteString.Char8 as B import Control.Lens-import Text.Regex import Text.Regex.Posix import qualified Data.Text as T import System.Environment-import Web.Twitter.Conduit-import Web.Twitter.Conduit.Types+import Web.Twitter.Conduit ( call , update , inReplyToStatusId , StreamingAPI ( SStatus ) ) import Web.Twitter.Conduit.Stream-import Web.Twitter.Types+import Web.Twitter.Conduit.Monad+import Web.Twitter.Types ( statusId , statusText , statusUser , userScreenName ) import Web.Authenticate.OAuth import Control.Monad.Logger import Control.Monad import Control.Monad.IO.Class ( liftIO )-import Control.Concurrent-import Database.Persist-import Database.Persist.Sqlite+import Database.Persist ( insert_ , selectList , SelectOpt ( Desc ) , Entity ( Entity ) )+import Database.Persist.Sqlite ( runSqlite , runMigration ) import Database.Persist.TH share [ mkPersist sqlSettings , mkMigrate "migrateAll" ] [persistLowerCase| Memo memo T.Text time DateTime default=CURRENT_TIME- UniqueMemo memo |] dbName = "memo.sqlite3"@@ -59,24 +56,27 @@ return $ setCredential tokens' credential' def pingPongImpl ( SStatus status ) = do- case ( T.unpack ( Web.Twitter.Types.statusText status ) =~ ( "@minamiyama1994_ " :: String ) ) :: ( String , String , String ) of+ case ( T.unpack ( statusText status ) =~ ( "@minamiyama1994_ " :: String ) ) :: ( String , String , String ) of ( "" , _ , "ping" ) -> do- call $ ( Web.Twitter.Conduit.update $ T.pack $ "@" ++ ( T.unpack $ Web.Twitter.Types.userScreenName $ Web.Twitter.Types.statusUser status ) ++ " pong" ) & inReplyToStatusId ?~ Web.Twitter.Types.statusId status+ call $ ( update $ T.pack $ "@" ++ ( T.unpack $ userScreenName $ statusUser status ) ++ " pong" ) & inReplyToStatusId ?~ statusId status return ( ) ( "" , _ , "now" ) -> do current <- liftIO getCurrentTime- call $ ( Web.Twitter.Conduit.update $ T.pack $ "@" ++ ( T.unpack $ Web.Twitter.Types.userScreenName $ Web.Twitter.Types.statusUser status ) ++ " Now is " ++ show current ) & inReplyToStatusId ?~ Web.Twitter.Types.statusId status+ call $ ( update $ T.pack $ "@" ++ ( T.unpack $ userScreenName $ statusUser status ) ++ " Now is " ++ show current ) & inReplyToStatusId ?~ statusId status return ( )- ( "" , _ , 'm' : 'e' : 'm' : 'o' : ' ' : memo ) -> if ( Web.Twitter.Types.userScreenName $ Web.Twitter.Types.statusUser status ) == "minamiyama1994"+ ( "" , _ , "help" ) -> do+ call $ ( update $ T.pack $ "@" ++ ( T.unpack $ userScreenName $ statusUser status ) ++ " Please see https://github.com/minamiyama1994/chomado-bot-on-haskell/blob/minamiyama1994/README.md" ) & inReplyToStatusId ?~ statusId status+ return ( )+ ( "" , _ , 'm' : 'e' : 'm' : 'o' : ' ' : memo ) -> if ( userScreenName $ statusUser status ) == "minamiyama1994" then do current <- liftIO getCurrentTime liftIO $ runSqlite dbName $ insert_ $ Memo ( T.pack memo ) current- call $ Web.Twitter.Conduit.update $ T.pack $ "#南山まさかずメモ " ++ memo+ call $ update $ T.pack $ "#南山まさかずメモ " ++ memo return ( ) else return ( ) ( "" , _ , "list memo" ) -> do memos <- liftIO $ runSqlite dbName $ selectList [ ] [ Desc MemoTime ]- forM_ memos $ \ ( Database.Persist.Sqlite.Entity _ ( Memo memo time ) ) -> call $ Web.Twitter.Conduit.update $ T.pack $ "#南山まさかずメモ " ++ T.unpack memo ++ " at " ++ show time+ forM_ memos $ \ ( Entity _ ( Memo memo time ) ) -> call $ update $ T.pack $ "#南山まさかずメモ " ++ T.unpack memo ++ " at " ++ show time _ -> return ( ) pingPongImpl _ = return ( ) @@ -88,4 +88,7 @@ runSqlite dbName $ do runMigration migrateAll info <- twInfo- runNoLoggingT . runTW info $ pingPong+ runNoLoggingT . runTW info $ do+ current <- liftIO getCurrentTime+ call $ update $ T.pack $ "南山まさかずbotが起動しました : " ++ show current+ pingPong
README.md view
@@ -12,3 +12,4 @@ * [reply example](https://twitter.com/minamiyama1994/status/489739070562508801) * [response example](https://twitter.com/minamiyama1994_/status/489739074102501376) * memo management of @minamiyama1994+* show help
masakazu-bot.cabal view
@@ -2,7 +2,7 @@ -- further documentation, see http://haskell.org/cabal/users-guide/ name: masakazu-bot-version: 0.1.0.0+version: 0.2.0.0 synopsis: @minamiyama1994_bot on haskell -- description: homepage: https://github.com/minamiyama1994/chomado-bot-on-haskell/tree/minamiyama1994@@ -20,7 +20,8 @@ main-is: Main.hs -- other-modules: -- other-extensions: - build-depends: base >=4.6 && <4.7 , twitter-conduit == 0.0.5.* , transformers == 0.3.* , monad-logger == 0.3.* , authenticate-oauth == 1.5.* , twitter-types == 0.3.* , datetime == 0.2.* , conduit == 1.1.* , text == 0.11.* , regex-posix == 0.95.* , regex-compat == 0.95.* , lens == 4.2.* , bytestring == 0.10.* , persistent-sqlite == 1.3.* , persistent-template == 1.3.* , persistent == 1.3.*+ build-depends: base >=4.6 && <4.7 , twitter-conduit == 0.0.5.* , transformers == 0.3.* , monad-logger == 0.3.* , authenticate-oauth == 1.5.* , twitter-types == 0.3.* , datetime == 0.2.* , conduit == 1.1.* , text == 0.11.* , regex-posix == 0.95.* , lens == 4.2.* , bytestring == 0.10.* , persistent-sqlite == 1.3.* , persistent-template == 1.3.* , persistent == 1.3.* -- hs-source-dirs: default-language: Haskell2010+ ghc-options: -Wall -Wall