From 246d2f12c86ff98eb13b4ff3f826f78bd031991c Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 3 Jun 2018 18:51:59 +1200 Subject: [PATCH] isolate debugging messages behind new -Verbose flag (argument, not in config file) --- NTFServer.go | 19 ++++++++++++++----- main.go | 3 ++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/NTFServer.go b/NTFServer.go index aab315d..95eaafa 100644 --- a/NTFServer.go +++ b/NTFServer.go @@ -27,6 +27,7 @@ type NTFServer struct { configFile string config NTFConfig conns map[string]*libnmdc.HubConnection // hubnick -> hubconn + verbose bool // Except the coalesce buffer, that requires a background worker. coalesceBufferMut sync.Mutex @@ -43,12 +44,13 @@ type upstreamMessage struct { evt libnmdc.HubEvent } -func NewNTFServer(configFile string) (*NTFServer, error) { +func NewNTFServer(configFile string, verbose bool) (*NTFServer, error) { ret := NTFServer{ configFile: configFile, hubMessages: make(chan upstreamMessage, 0), conns: make(map[string]*libnmdc.HubConnection), coalesceBuffer: make(map[string]time.Time), + verbose: verbose, } // Config @@ -76,7 +78,9 @@ func NewNTFServer(configFile string) (*NTFServer, error) { ret.bot = bot - bot.Debug = true + if ret.verbose { + bot.Debug = true + } log.Printf("Connected to telegram as '%s'", bot.Self.UserName) @@ -263,6 +267,10 @@ func (this *NTFServer) Coalesce(hubNick, message string) bool { } func (this *NTFServer) HandleHubMessage(msg upstreamMessage) { + if this.verbose { + log.Printf("Hub: %#v", msg) + } + switch msg.evt.EventType { case libnmdc.EVENT_SYSTEM_MESSAGE_FROM_CONN, libnmdc.EVENT_CONNECTION_STATE_CHANGED: @@ -298,7 +306,6 @@ func (this *NTFServer) HandleHubMessage(msg upstreamMessage) { log.Printf("Hub(%s): Unhandled(%d): %s", msg.hubNick, msg.evt.EventType, msg.evt.Message) } - log.Printf("Hub: %#v", msg) } func (this *NTFServer) HandleMessage(update telegram.Update) { @@ -325,9 +332,11 @@ func (this *NTFServer) HandleMessage(update telegram.Update) { log.Printf("Message from unknown chat %d (not our supergroup, not a PM, ...)", update.Message.Chat.ID) } - fmt.Printf("%#v\n", update.Message) + if this.verbose { + fmt.Printf("%#v\n", update.Message) - log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) + log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) + } } // kickAndDrop deregisters an account and kicks them from the group chat diff --git a/main.go b/main.go index ec90907..1d257c9 100644 --- a/main.go +++ b/main.go @@ -8,9 +8,10 @@ import ( func main() { configFile := flag.String("ConfigFile", "config.json", "") + verbose := flag.Bool("Verbose", false, "") flag.Parse() - svr, err := NewNTFServer(*configFile) + svr, err := NewNTFServer(*configFile, *verbose) if err != nil { log.Fatal(err.Error()) }