@@ -9,13 +9,14 @@ package logic
9
9
import (
10
10
"errors"
11
11
"fmt"
12
- "github.com/studygolang/studygolang/model"
13
- "github.com/studygolang/studygolang/util"
14
12
"os"
15
13
"regexp"
16
14
"strconv"
17
15
"time"
18
16
17
+ "github.com/studygolang/studygolang/model"
18
+ "github.com/studygolang/studygolang/util"
19
+
19
20
"github.com/gorilla/schema"
20
21
"github.com/polaris1119/goutils"
21
22
"github.com/polaris1119/logger"
@@ -241,6 +242,32 @@ func NeedCaptcha(user *model.Me) bool {
241
242
return false
242
243
}
243
244
245
+ // SpamRecord 控制半夜 Spam
246
+ // 避免误判,只针对最近 3 天内注册的用户
247
+ func SpamRecord (ctx context.Context , user * model.Me , maxNum int ) {
248
+ if time .Now ().Add (- 3 * 24 * time .Hour ).After (user .CreatedAt ) {
249
+ return
250
+ }
251
+
252
+ redis := nosql .NewRedisFromPool ()
253
+ defer redis .Close ()
254
+
255
+ key := getSpamMidNightNumKey (user .Uid )
256
+ publishTimes := goutils .MustInt (redis .GET (key ))
257
+ if publishTimes >= maxNum - 1 {
258
+ DefaultUser .UpdateUserStatus (ctx , user .Uid , model .UserStatusOutage )
259
+
260
+ // 将用户 IP 加入黑名单
261
+ DefaultRisk .AddBlackIPByUID (user .Uid )
262
+
263
+ DefaultUser .DeleteUserContent (ctx , user .Uid )
264
+
265
+ logger .Infoln ("uid=" , user .Uid , "spam, so delete TA's content" )
266
+ } else {
267
+ redis .SET (key , publishTimes + 1 , 86400 )
268
+ }
269
+ }
270
+
244
271
// incrPublishTimes 增加用户发布次数
245
272
func incrPublishTimes (uid int ) {
246
273
redis := nosql .NewRedisFromPool ()
@@ -268,6 +295,10 @@ func getLastPublishTimeKey(uid int) string {
268
295
return "last:publish:time:user:" + strconv .Itoa (uid )
269
296
}
270
297
298
+ func getSpamMidNightNumKey (uid int ) string {
299
+ return "spam:mid:night:num:user:" + strconv .Itoa (uid )
300
+ }
301
+
271
302
func website () string {
272
303
host := "http://"
273
304
if WebsiteSetting .OnlyHttps {
0 commit comments