Skip to content

Commit

Permalink
Merge pull request #82 from bitvora/dev-ignoreList
Browse files Browse the repository at this point in the history
ignore follow list for people who follow spammers
  • Loading branch information
barrydeen authored Jan 4, 2025
2 parents f90926d + 9a74359 commit 929e6f8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ ARCHIVAL_SYNC="FALSE"
ARCHIVE_REACTIONS="FALSE" # optional, reactions take up a lot of space and compute

# optional, certain note kinds older than this many days will be deleted
MAX_AGE_DAYS=365
MAX_AGE_DAYS=365

# comma delimited list of pubkeys who follow bots and ruin the WoT
IGNORE_FOLLOWS_LIST=""
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ REFRESH_INTERVAL_HOURS=24 # interval in hours to refresh the web of trust
MINIMUM_FOLLOWERS=3 #how many followers before they're allowed in the WoT
ARCHIVAL_SYNC="FALSE" # set to TRUE to archive every note from every person in the WoT (not recommended)
ARCHIVE_REACTIONS="FALSE" # set to TRUE to archive every reaction from every person in the WoT (not recommended)
IGNORE_FOLLOWS_LIST="" # comma separated list of pubkeys who follow too many bots and ruin the WoT
```

### 4. Build the project
Expand Down
30 changes: 30 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"os"
"strconv"
"strings"
"time"

"github.com/fiatjaf/eventstore"
Expand Down Expand Up @@ -38,6 +39,7 @@ type Config struct {
RelayIcon string
MaxAgeDays int
ArchiveReactions bool
IgnoredPubkeys []string
}

var pool *nostr.SimplePool
Expand Down Expand Up @@ -209,6 +211,11 @@ func LoadConfig() Config {
os.Setenv("ARCHIVE_REACTIONS", "FALSE")
}

ignoredPubkeys := []string{}
if ignoreList := os.Getenv("IGNORE_FOLLOWS_LIST"); ignoreList != "" {
ignoredPubkeys = splitAndTrim(ignoreList)
}

minimumFollowers, _ := strconv.Atoi(os.Getenv("MINIMUM_FOLLOWERS"))
maxAgeDays, _ := strconv.Atoi(os.Getenv("MAX_AGE_DAYS"))

Expand All @@ -227,6 +234,7 @@ func LoadConfig() Config {
ArchivalSync: getEnv("ARCHIVAL_SYNC") == "TRUE",
MaxAgeDays: maxAgeDays,
ArchiveReactions: getEnv("ARCHIVE_REACTIONS") == "TRUE",
IgnoredPubkeys: ignoredPubkeys,
}

return config
Expand Down Expand Up @@ -290,6 +298,11 @@ func refreshTrustNetwork(ctx context.Context, relay *khatru.Relay) {
log.Println("🔍 fetching owner's follows")
for ev := range pool.SubManyEose(timeoutCtx, seedRelays, filters) {
for _, contact := range ev.Event.Tags.GetAll([]string{"p"}) {
pubkey := contact[1]
if isIgnored(pubkey, config.IgnoredPubkeys) {
fmt.Println("ignoring follows from pubkey: ", pubkey)
continue
}
pubkeyFollowerCount[contact[1]]++ // Increment follower count for the pubkey
appendOneHopNetwork(contact[1])
}
Expand Down Expand Up @@ -523,3 +536,20 @@ func getDB() badger.BadgerBackend {
Path: getEnv("DB_PATH"),
}
}

func splitAndTrim(input string) []string {
items := strings.Split(input, ",")
for i, item := range items {
items[i] = strings.TrimSpace(item)
}
return items
}

func isIgnored(pubkey string, ignoredPubkeys []string) bool {
for _, ignored := range ignoredPubkeys {
if pubkey == ignored {
return true
}
}
return false
}

0 comments on commit 929e6f8

Please sign in to comment.