add whitelist and replace old blacklist files with one
This commit is contained in:
		
							parent
							
								
									8b875882e9
								
							
						
					
					
						commit
						d5ae0bcb0c
					
				
					 2 changed files with 21 additions and 19 deletions
				
			
		
							
								
								
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							|  | @ -1,4 +1,4 @@ | ||||||
| .env | .env | ||||||
| domains.txt | blacklist.txt | ||||||
| nicknames.txt | whitelist.txt | ||||||
| uabot | uabot | ||||||
|  |  | ||||||
							
								
								
									
										36
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								main.go
									
									
									
									
									
								
							|  | @ -67,13 +67,13 @@ func main() { | ||||||
| 		log.Fatal(err) | 		log.Fatal(err) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	domainRegexes, err := parseRegexFile(path.Join(ex, "domains.txt")) | 	blacklistRegexes, err := parseRegexFile(path.Join(ex, "blacklist.txt")) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Fatal(err) | 		log.Fatal(err) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	nicknameRegexes, err := parseRegexFile(path.Join(ex, "nicknames.txt")) | 	whitelistRegexes, err := parseRegexFile(path.Join(ex, "whitelist.txt")) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Fatal(err) | 		log.Fatal(err) | ||||||
|  | @ -213,23 +213,13 @@ notif_loop: | ||||||
| 		// log.Println(notif)
 | 		// log.Println(notif)
 | ||||||
| 
 | 
 | ||||||
| 		if notif.Type == "follow" { | 		if notif.Type == "follow" { | ||||||
| 			acct_parsed := strings.Split(notif.Account.Acct, "@") | 			// acct_parsed := strings.Split(notif.Account.Acct, "@")
 | ||||||
| 
 | 
 | ||||||
| 			for _, regex := range domainRegexes { | 			for _, regex := range blacklistRegexes { | ||||||
| 				if len(acct_parsed) == 2 && regex.MatchString(acct_parsed[1]) { | 				if regex.MatchString(notif.Account.Acct) { | ||||||
| 					_, err := masto_client.AccountBlock(ctx, notif.Account.ID) | 					_, err := masto_client.AccountBlock(ctx, notif.Account.ID) | ||||||
| 					if err == nil { | 					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 |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			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())) |  | ||||||
| 					} | 					} | ||||||
| 					continue notif_loop | 					continue notif_loop | ||||||
| 				} | 				} | ||||||
|  | @ -265,7 +255,19 @@ actor: %v`, notif.Status.ID, notif.Status.Content, notif.Account.Acct) | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			if ok && notif.Status.Visibility == "public" { | 			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{ | 				if err := db.Create(&Post{ | ||||||
| 					PostId: string(notif.Status.ID), | 					PostId: string(notif.Status.ID), | ||||||
| 				}).Error; err != nil { | 				}).Error; err != nil { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue