merge dev.rievo.net/sst/domainCheck into discordBots
This commit is contained in:
parent
4dfeebf561
commit
c0f39ba894
7 changed files with 484 additions and 1 deletions
78
cmd/domaincheckadd/main.go
Normal file
78
cmd/domaincheckadd/main.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"grow.rievo.dev/discordBots/cmd/domaincheckbot/config"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Println("add domains to domains.json")
|
||||
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
|
||||
var newDomains []string
|
||||
|
||||
fmt.Print("domains: ")
|
||||
if scanner.Scan() {
|
||||
|
||||
input := scanner.Text()
|
||||
|
||||
values := strings.Split(input, ",")
|
||||
|
||||
// trim space
|
||||
for i := range values {
|
||||
values[i] = strings.TrimSpace(values[i])
|
||||
}
|
||||
|
||||
// remove empty
|
||||
values = removeEmpty(values)
|
||||
|
||||
// sort
|
||||
sort.SliceStable(values, func(i, j int) bool {
|
||||
return values[i] < values[j]
|
||||
})
|
||||
|
||||
newDomains = values
|
||||
}
|
||||
log.Printf("domains to add: %v\n", newDomains)
|
||||
|
||||
fmt.Print("add to domains.json? [y|N]: ")
|
||||
if scanner.Scan() {
|
||||
input := scanner.Text()
|
||||
if input == "y" || input == "Y" {
|
||||
err := storeDomains(newDomains)
|
||||
if err != nil {
|
||||
log.Fatal("failed storing domains.json")
|
||||
}
|
||||
fmt.Println("domains.json updated")
|
||||
} else {
|
||||
fmt.Println("canceled!")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func storeDomains(domains []string) error {
|
||||
for _, domain := range domains {
|
||||
config.AddDomain(domain)
|
||||
}
|
||||
file, _ := json.MarshalIndent(config.Domains, "", " ")
|
||||
err := os.WriteFile("./cmd/domaincheckbot/config/domain.json", file, 0644)
|
||||
return err
|
||||
}
|
||||
|
||||
func removeEmpty(sliceList []string) []string {
|
||||
var list []string
|
||||
for _, str := range sliceList {
|
||||
if str != "" {
|
||||
list = append(list, str)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue