Reviewed-on: #12 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
77 lines
1.7 KiB
Go
77 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.kundeng.us/phoenix/textsender-models/pkg/contact"
|
|
"git.kundeng.us/phoenix/textsender-models/pkg/message"
|
|
|
|
"git.kundeng.us/phoenix/sender/config"
|
|
"git.kundeng.us/phoenix/sender/messaging"
|
|
"git.kundeng.us/phoenix/sender/util"
|
|
"git.kundeng.us/phoenix/sender/version"
|
|
)
|
|
|
|
func main() {
|
|
myArgs := os.Args
|
|
argCount := len(myArgs)
|
|
|
|
if config.IsVersionFlagPresent() {
|
|
fmt.Println(config.App_Name)
|
|
fmt.Println(version.String())
|
|
return
|
|
} else if argCount < 4 {
|
|
fmt.Printf("Argument count: %v\n", argCount)
|
|
fmt.Println("Provide argument to config file and number file")
|
|
os.Exit(-1)
|
|
}
|
|
|
|
configPath, numberPath, messagePath := util.GetPaths(myArgs)
|
|
|
|
fmt.Printf("Config file path: %s\n", configPath)
|
|
fmt.Println("Numbers file path:", numberPath)
|
|
fmt.Println("Message path:", messagePath)
|
|
|
|
cfg, _ := config.ParseConfig(configPath)
|
|
cfg.PrintConfig()
|
|
|
|
numbers := util.ParseNumbers(numberPath)
|
|
prepMessage := util.ParseMessage(messagePath)
|
|
|
|
if len(numbers) == 0 || prepMessage.IsEmpty() {
|
|
if len(numbers) == 0 {
|
|
fmt.Println("No numbers to send")
|
|
os.Exit(-1)
|
|
} else {
|
|
fmt.Println("No message to send")
|
|
os.Exit(-1)
|
|
}
|
|
}
|
|
|
|
fmt.Println("")
|
|
prepMessage.Print()
|
|
|
|
convertedContacts, err := util.Convert(numbers, 1)
|
|
if err != nil {
|
|
fmt.Println("Error converting numbers: Error:", err)
|
|
os.Exit(-1)
|
|
}
|
|
|
|
convertedMessage, err := util.Convert(prepMessage, 0)
|
|
if err != nil {
|
|
fmt.Println("Error converting message")
|
|
os.Exit(-1)
|
|
}
|
|
|
|
if contacts, ok := convertedContacts.([]contact.Contact); ok {
|
|
if msg, ok := convertedMessage.(message.Message); ok {
|
|
messaging.SendMessages(cfg, contacts, msg, 5)
|
|
} else {
|
|
fmt.Println("Could not convert message")
|
|
}
|
|
} else {
|
|
fmt.Println("Could not convert numbers")
|
|
}
|
|
}
|