aboutsummaryrefslogtreecommitdiffstats
path: root/src/Plugin
diff options
context:
space:
mode:
Diffstat (limited to 'src/Plugin')
-rw-r--r--src/Plugin/Base.hs5
-rw-r--r--src/Plugin/GitHubCommit.hs25
2 files changed, 26 insertions, 4 deletions
diff --git a/src/Plugin/Base.hs b/src/Plugin/Base.hs
index c85f53a..b752fd1 100644
--- a/src/Plugin/Base.hs
+++ b/src/Plugin/Base.hs
@@ -4,9 +4,12 @@ module Plugin.Base
, Plugin(..)
) where
+import Database.SQLite.Simple
+
import Message
-type PluginAction = Message -> String
+-- TODO: Replace Connection with a type class
+type PluginAction = Message -> Connection -> IO String
data Plugin = Plugin
{ matchRegex :: String
diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs
index 4175fb8..ec6684d 100644
--- a/src/Plugin/GitHubCommit.hs
+++ b/src/Plugin/GitHubCommit.hs
@@ -1,7 +1,11 @@
+{-# LANGUAGE OverloadedStrings #-}
+
module Plugin.GitHubCommit
( gitHubCommit
) where
+import Database.SQLite.Simple
+import Database.SQLite.Simple.FromRow
import Text.Regex.TDFA
import qualified Message as M
@@ -12,16 +16,31 @@ gitHubCommit = Plugin
, perform = gitHubCommitAction
}
+-- gitHubCommitAction :: IO PluginAction
+-- gitHubCommitAction :: M.Message -> Connection -> IO String
gitHubCommitAction :: PluginAction
-gitHubCommitAction message =
- "https://github.com/" ++ M.text message =~ matchRegex gitHubCommit
+gitHubCommitAction message dbConn = do
+ rs <- query_ dbConn "SELECT id, channel, repo_url \
+ \ FROM plugin_github_commit_channel_repo_urls \
+ \ LIMIT 1" :: IO [ChannelRepoUrl]
+ return $ response rs
+ where
+ response [] = ""
+ response (r:rs) =
+ repoUrl r ++ "/commits/" ++ M.text message =~ matchRegex gitHubCommit
+-- TODO: Make an Either type for plugins to return errors
type Id = Int
type RepoUrl = String
-- | A type to match the database table for this plugin.
-data ChannelRepoUrl = ChannelRepoUrl Id M.Channel RepoUrl deriving (Show)
+-- data ChannelRepoUrl = ChannelRepoUrl Id M.Channel RepoUrl deriving (Show)
+data ChannelRepoUrl = ChannelRepoUrl
+ { id :: Id
+ , channel :: M.Channel
+ , repoUrl :: RepoUrl
+ } deriving (Show)
instance FromRow ChannelRepoUrl where
fromRow = ChannelRepoUrl <$> field <*> field <*> field