add whitelist and replace old blacklist files with one

This commit is contained in:
Andriy Cherniy 2024-01-05 00:44:33 +02:00
parent 8b875882e9
commit d5ae0bcb0c
2 changed files with 21 additions and 19 deletions

4
.gitignore vendored
View file

@ -1,4 +1,4 @@
.env
domains.txt
nicknames.txt
blacklist.txt
whitelist.txt
uabot

36
main.go
View file

@ -67,13 +67,13 @@ func main() {
log.Fatal(err)
}
domainRegexes, err := parseRegexFile(path.Join(ex, "domains.txt"))
blacklistRegexes, err := parseRegexFile(path.Join(ex, "blacklist.txt"))
if err != nil {
log.Fatal(err)
}
nicknameRegexes, err := parseRegexFile(path.Join(ex, "nicknames.txt"))
whitelistRegexes, err := parseRegexFile(path.Join(ex, "whitelist.txt"))
if err != nil {
log.Fatal(err)
@ -213,23 +213,13 @@ notif_loop:
// log.Println(notif)
if notif.Type == "follow" {
acct_parsed := strings.Split(notif.Account.Acct, "@")
// acct_parsed := strings.Split(notif.Account.Acct, "@")
for _, regex := range domainRegexes {
if len(acct_parsed) == 2 && regex.MatchString(acct_parsed[1]) {
for _, regex := range blacklistRegexes {
if regex.MatchString(notif.Account.Acct) {
_, err := masto_client.AccountBlock(ctx, notif.Account.ID)
if err == nil {
matrix_client.SendText(m_id.RoomID(ROOM_ID), fmt.Sprintf("%s заблокований автоматично регексом доменів: %s", notif.Account.Acct, regex.String()))
}
continue notif_loop
}
}
for _, regex := range nicknameRegexes {
if regex.MatchString(acct_parsed[0]) {
_, err := masto_client.AccountBlock(ctx, notif.Account.ID)
if err == nil {
matrix_client.SendText(m_id.RoomID(ROOM_ID), fmt.Sprintf("%s заблокований автоматично регексом нікнеймів: %s", notif.Account.Acct, regex.String()))
matrix_client.SendText(m_id.RoomID(ROOM_ID), fmt.Sprintf("%s заблокований автоматично регулярним виразом: %s", notif.Account.Acct, regex.String()))
}
continue notif_loop
}
@ -265,7 +255,19 @@ actor: %v`, notif.Status.ID, notif.Status.Content, notif.Account.Acct)
}
if ok && notif.Status.Visibility == "public" {
log.Debugf("post %v is public and has subscription", notif.Status.ID)
log.Debugf("post %v is public and user has subscription", notif.Status.ID)
for _, regex := range whitelistRegexes {
if regex.MatchString(notif.Account.Acct) {
_, err = masto_client.Reblog(ctx, notif.Status.ID)
if err != nil {
log.Error(err)
}
log.Debugf("post %v belongs to whitelisted user (%v) by regex: %v", notif.Status.ID, notif.Account.Acct, regex.String())
continue notif_loop
}
}
if err := db.Create(&Post{
PostId: string(notif.Status.ID),
}).Error; err != nil {