Skip to content

Commit

Permalink
feat: Adding support to multiple ids
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Feb 11, 2025
1 parent 026c901 commit 0df2547
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions cmd/sweeper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type configuration struct {
logger *logger.Config
discord *discord.Config

currentUser *string
usernames *[]string
userIDs *[]string
usernames *[]string
}

func newConfiguration() configuration {
Expand All @@ -25,8 +25,8 @@ func newConfiguration() configuration {
logger: logger.Flags(fs, "logger"),
discord: discord.Flags(fs, ""),

currentUser: flags.New("currentUser", "Current User ID to clean").DocPrefix("sweeper").String(fs, "", nil),
usernames: flags.New("username", "Username of messages to clean").DocPrefix("sweeper").StringSlice(fs, nil, nil),
userIDs: flags.New("user", "User ID to clean").DocPrefix("sweeper").StringSlice(fs, nil, nil),
usernames: flags.New("username", "Username to clean").DocPrefix("sweeper").StringSlice(fs, nil, nil),
}

_ = fs.Parse(os.Args[1:])
Expand Down
12 changes: 6 additions & 6 deletions cmd/sweeper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"fmt"
"log/slog"
"runtime"
"strings"
Expand Down Expand Up @@ -62,16 +61,17 @@ func main() {
continue
}

if shouldDelete(*config.currentUser, message, *config.usernames) {
fmt.Println(message.String())
if shouldDelete(message, *config.userIDs, *config.usernames) {
logger.FatalfOnErr(ctx, services.discord.DeleteMessage(ctx, req, message), "delete")
}
}
}

func shouldDelete(currentUser string, message discord.Message, usernames []string) bool {
if message.Author.Bot && strings.Contains(message.Content, currentUser) {
return true
func shouldDelete(message discord.Message, userIDs, usernames []string) bool {
for _, userID := range userIDs {
if message.Author.Bot && strings.Contains(message.Content, userID) {
return true
}
}

for _, username := range usernames {
Expand Down

0 comments on commit 0df2547

Please sign in to comment.