Skip to content

Commit

Permalink
スパム判定修正
Browse files Browse the repository at this point in the history
  • Loading branch information
tukeJonny committed Oct 30, 2023
1 parent 787d666 commit 6a64df8
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions webapp/go/livecomment_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,33 @@ func postLivecommentHandler(c echo.Context) error {
}
defer tx.Rollback()

// FIXME: 改悪
// SELECT word FROM ng_words
// SELECT COUNT(*) FROM (SELECT 'I am hoge' AS text) AS texts INNER JOIN (SELECT CONCAT('%', 'am', '%') AS pattern) AS patterns ON texts.text LIKE patterns.pattern;

var hitSpam int
query := `
SELECT COUNT(*) AS cnt
FROM ng_words AS w
CROSS JOIN
(SELECT ? AS text) AS t
WHERE t.text LIKE CONCAT('%', w.word, '%');
`
if err = tx.GetContext(ctx, &hitSpam, query, req.Comment); err != nil {
// スパム判定
var ngwords []*NGWord
if err := tx.SelectContext(ctx, &ngwords, "SELECT * FROM ng_words"); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
c.Logger().Infof("[hitSpam=%d] comment = %s", hitSpam, req.Comment)
if hitSpam >= 1 {
return echo.NewHTTPError(http.StatusBadRequest, "このコメントがスパム判定されました")

var hitSpam int
for _, ngword := range ngwords {
query := `
SELECT COUNT(*)
FROM
(SELECT ? AS text) AS texts
INNER JOIN
(SELECT CONCAT('%', ?, '%') AS pattern) AS patterns
ON texts.text LIKE patterns.pattern;
`
if err := tx.GetContext(ctx, &hitSpam, query, req.Comment, ngword.Word); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
c.Logger().Infof("[hitSpam=%d] comment = %s", hitSpam, req.Comment)
if hitSpam >= 1 {
return echo.NewHTTPError(http.StatusBadRequest, "このコメントがスパム判定されました")
}
}

// FIXME: 視聴者からのスパム報告と突合して検査するとボーナス加点

now := time.Now().Unix()
livecommentModel := LivecommentModel{
UserId: int64(userId),
Expand Down

0 comments on commit 6a64df8

Please sign in to comment.