By | Chris Done |
At | 2013-06-15 |
Title | Bring min level into code. |
Description |
Edit file src/Hpaste/Model/Paste.hs 33188 → 33188
23 23 ,validNick)
24 24 where
25 25 26 26 import Hpaste.Types
27 27 import Hpaste.Model.Announcer
+ 28 import Hpaste.Model.Spam
28 29 29 30 import Control.Applicative ((<$>),(<|>))
30 31 import Control.Exception as E
31 32 import Control.Monad
32 33 import Control.Monad.Env
… … … … 51 52 -- | Count public pastes.
52 53 countPublicPastes :: Maybe String -> HPModel Integer
53 54 countPublicPastes mauthor = do
54 55 rows <- single ["SELECT COUNT(*)"
55 56 ,"FROM public_toplevel_paste"
- 56 ,"WHERE (? IS NULL) OR (author = ?)"]
- 57 (mauthor,mauthor)
+ 57 ,"WHERE (? IS NULL) OR (author = ?) AND spamrating < ?"]
+ 58 (mauthor,mauthor,spamMinLevel)
58 59 return $ fromMaybe 0 rows
59 60 60 61 -- | Get the latest pastes.
61 62 getLatestPastes :: HPModel [Paste]
62 63 getLatestPastes =
- 63 queryNoParams ["SELECT ",pasteFields
- 64 ,"FROM public_toplevel_paste"
- 65 ,"ORDER BY id DESC"
- 66 ,"LIMIT 20"]
+ 64 query ["SELECT ",pasteFields
+ 65 ,"FROM public_toplevel_paste"
+ 66 ,"WHERE spamrating < ?"
+ 67 ,"ORDER BY id DESC"
+ 68 ,"LIMIT 20"]
+ 69 (Only spamMinLevel)
67 70 68 71 -- | Get some paginated pastes.
69 72 getSomePastes :: Maybe String -> Pagination -> HPModel [Paste]
70 73 getSomePastes mauthor Pagination{..} =
71 74 query ["SELECT",pasteFields
72 75 ,"FROM public_toplevel_paste"
- 73 ,"WHERE (? IS NULL) OR (author = ?)"
+ 76 ,"WHERE (? IS NULL) OR (author = ?) AND spamrating < ?"
74 77 ,"ORDER BY id DESC"
75 78 ,"OFFSET " ++ show (max 0 (pnPage - 1) * pnLimit)
76 79 ,"LIMIT " ++ show pnLimit]
- 77 (mauthor,mauthor)
+ 80 (mauthor,mauthor,spamMinLevel)
78 81 79 82 -- | Get a paste by its id.
80 83 getPasteById :: PasteId -> HPModel (Maybe Paste)
81 84 getPasteById pid =
82 85 listToMaybe <$> query ["SELECT ",pasteFields
… … … … 129 132 (pasteSubmitTitle,pasteSubmitAuthor,pasteSubmitPaste
130 133 ,pasteSubmitChannel,pasteSubmitLanguage,ann_pid,rev_pid,spamrating)
131 134 when (lang == Just "haskell") $ just res $ createHints ps
132 135 just (pasteSubmitChannel >>= lookupChan) $ \chan ->
133 136 just res $ \pid -> do
- 134 announcePaste pasteSubmitType (channelName chan) ps pid
+ 137 unless (spamrating < spamMinLevel) $
+ 138 announcePaste pasteSubmitType (channelName chan) ps pid
135 139 return (pasteSubmitId <|> res)
136 140 137 141 where lookupChan cid = find ((==cid).channelId) chans
138 142 lookupLang lid = find ((==lid).languageId) langs
139 143 lang = pasteSubmitLanguage >>= (fmap languageName . lookupLang)
… … … … Edit file src/Hpaste/Model/Spam.hs 33188 → 33188
32 32 [(n :: Double,_)] -> round (n*10)
33 33 _ -> 50
34 34 35 35 -- | Mark something as definitely spam.
36 36 definitelySpam :: PasteSubmit -> Bool
- 37 definitelySpam ps =
- 38 T.isInfixOf "stooorage" (allText ps)
+ 37 definitelySpam ps = False
+ 38 -- T.isInfixOf "stooorage" (allText ps)
39 39 40 40 -- | Multiple the rating by weights specific to hpaste.
41 41 weighted :: PasteSubmit -> Integer -> Integer
42 42 weighted ps n = foldr ($) n weights where
43 43 weights = [if T.isInfixOf "http://" text || T.isInfixOf "https://" text
… … … … 48 48 text = allText ps
49 49 50 50 -- | Get the text of the paste.
51 51 allText :: PasteSubmit -> Text
52 52 allText PasteSubmit{..} = T.toLower $ pasteSubmitTitle <> " " <> pasteSubmitPaste
+ 53 + 54 spamMaxLevel = 100
+ 55 spamMinLevel = 60
… … … … Edit file src/Hpaste/Controller/Paste.hs 33188 → 33188
94 94 case val of
95 95 Nothing -> return ()
96 96 Just PasteSubmit{pasteSubmitSpamTrap=Just{}} -> goHome
97 97 Just paste -> do
98 98 spamrating <- io $ spamRating paste
- 99 if spamrating >= 100
+ 99 if spamrating >= spamMaxLevel
100 100 then goHome
101 101 else do
102 102 resetCache Key.Home
103 103 maybe (return ()) (resetCache . Key.Paste . fromIntegral) $ pasteSubmitId paste
104 104 pid <- model $ createPaste languages channels paste spamrating
… … … …