forked from indes/flowerss-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 将v2版本的bot filter 转换成v3版本的middleware
- Loading branch information
Showing
3 changed files
with
32 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package middleware | ||
|
||
import ( | ||
"fmt" | ||
|
||
tb "gopkg.in/telebot.v3" | ||
|
||
"github.com/indes/flowerss-bot/internal/config" | ||
) | ||
|
||
func UserFilter() tb.MiddlewareFunc { | ||
return func(next tb.HandlerFunc) tb.HandlerFunc { | ||
return func(c tb.Context) error { | ||
if len(config.AllowUsers) == 0 { | ||
return next(c) | ||
} | ||
userID := c.Sender().ID | ||
for _, allowUserID := range config.AllowUsers { | ||
if allowUserID == userID { | ||
return next(c) | ||
} | ||
} | ||
return fmt.Errorf("deny user %d", userID) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters