-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: autoban when using baneed words (#5)
* build: fix local import inside format command * build: update golangci config * build(deps): bump dependencies version * feat(wip): add autoban support * feat: implement auto ban feature
- Loading branch information
Showing
8 changed files
with
363 additions
and
317 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
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,36 @@ | ||
package bot | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/andersfylling/disgord" | ||
"github.com/rs/zerolog/log" | ||
|
||
"github.com/desmos-labs/hephaestus/types" | ||
) | ||
|
||
// AutoBanMessage bans the user if the message contains banned words | ||
func (b *Bot) AutoBanMessage(s disgord.Session, data *disgord.MessageCreate) { | ||
if !b.containsBannedWords(data.Message.Content) { | ||
return | ||
} | ||
|
||
// Ban the user | ||
err := s.Guild(data.Message.GuildID).Member(data.Message.Author.ID).Ban(&disgord.BanMember{ | ||
DeleteMessageDays: 7, | ||
Reason: "Scam", | ||
}) | ||
if err != nil { | ||
log.Error().Err(err).Str(types.LogUser, data.Message.Author.Username).Msg("error while banning user") | ||
return | ||
} | ||
} | ||
|
||
func (b *Bot) containsBannedWords(msg string) bool { | ||
for _, bannedWord := range b.cfg.BannedWords { | ||
if strings.Contains(strings.ToLower(msg), strings.ToLower(bannedWord)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
Oops, something went wrong.