diff --git a/gocw2.sample.cfg b/gocw2.sample.cfg new file mode 100644 index 0000000..8b33a65 --- /dev/null +++ b/gocw2.sample.cfg @@ -0,0 +1,5 @@ +[rabbit] +user = guest +password = guest +host = localhost:5672 +queue = chatwars \ No newline at end of file diff --git a/main.go b/main.go index 0f325f3..5f81391 100644 --- a/main.go +++ b/main.go @@ -26,11 +26,34 @@ type ChatWarsMessage struct { const user_chtwrsbot = 408101137 -var ownUserID64 = int64(0) -var ownUserID32 = int32(0) +type Config struct { + Rabbit struct { + User string + Password string + Host string + Queue string + } +} + +var ( + config = flag.String("config", "gocw2.cfg", "config file path") + initdb = flag.Bool("initdb", false, "initialize tracker database") + + cfg Config + + ownUserID64 = int64(0) + ownUserID32 = int32(0) +) func main() { - // msgMutex = &sync.Mutex{} + // Parsing config + flag.Parse() + + err = gcfg.ReadFileInto(&cfg, *config) + if err != nil { + log.Fatalf("Failed to parse gcfg data: %s", err) + } + tdlib.SetLogVerbosityLevel(1) tdlib.SetFilePath("./errors.txt") @@ -107,7 +130,7 @@ func ListenCW(c *tdlib.Client) { return false } - conn, err := amqp.Dial("amqp://shoopea:UmDd5g4WRa2MzqOHsG2T@localhost:5672/chatwars") + conn, err := amqp.Dial("amqp://" + cfg.Rabbit.User + ":" + cfg.Rabbit.Password + "@" + cfg.Rabbit.Host + "/" + cfg.Rabbit.Queue) if err != nil { log.Fatal(err) }