isolate debugging messages behind new -Verbose flag (argument, not in config file)
This commit is contained in:
parent
57724ad67c
commit
246d2f12c8
19
NTFServer.go
19
NTFServer.go
@ -27,6 +27,7 @@ type NTFServer struct {
|
|||||||
configFile string
|
configFile string
|
||||||
config NTFConfig
|
config NTFConfig
|
||||||
conns map[string]*libnmdc.HubConnection // hubnick -> hubconn
|
conns map[string]*libnmdc.HubConnection // hubnick -> hubconn
|
||||||
|
verbose bool
|
||||||
|
|
||||||
// Except the coalesce buffer, that requires a background worker.
|
// Except the coalesce buffer, that requires a background worker.
|
||||||
coalesceBufferMut sync.Mutex
|
coalesceBufferMut sync.Mutex
|
||||||
@ -43,12 +44,13 @@ type upstreamMessage struct {
|
|||||||
evt libnmdc.HubEvent
|
evt libnmdc.HubEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNTFServer(configFile string) (*NTFServer, error) {
|
func NewNTFServer(configFile string, verbose bool) (*NTFServer, error) {
|
||||||
ret := NTFServer{
|
ret := NTFServer{
|
||||||
configFile: configFile,
|
configFile: configFile,
|
||||||
hubMessages: make(chan upstreamMessage, 0),
|
hubMessages: make(chan upstreamMessage, 0),
|
||||||
conns: make(map[string]*libnmdc.HubConnection),
|
conns: make(map[string]*libnmdc.HubConnection),
|
||||||
coalesceBuffer: make(map[string]time.Time),
|
coalesceBuffer: make(map[string]time.Time),
|
||||||
|
verbose: verbose,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
@ -76,7 +78,9 @@ func NewNTFServer(configFile string) (*NTFServer, error) {
|
|||||||
|
|
||||||
ret.bot = bot
|
ret.bot = bot
|
||||||
|
|
||||||
bot.Debug = true
|
if ret.verbose {
|
||||||
|
bot.Debug = true
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("Connected to telegram as '%s'", bot.Self.UserName)
|
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) {
|
func (this *NTFServer) HandleHubMessage(msg upstreamMessage) {
|
||||||
|
if this.verbose {
|
||||||
|
log.Printf("Hub: %#v", msg)
|
||||||
|
}
|
||||||
|
|
||||||
switch msg.evt.EventType {
|
switch msg.evt.EventType {
|
||||||
|
|
||||||
case libnmdc.EVENT_SYSTEM_MESSAGE_FROM_CONN, libnmdc.EVENT_CONNECTION_STATE_CHANGED:
|
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(%s): Unhandled(%d): %s", msg.hubNick, msg.evt.EventType, msg.evt.Message)
|
||||||
|
|
||||||
}
|
}
|
||||||
log.Printf("Hub: %#v", msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *NTFServer) HandleMessage(update telegram.Update) {
|
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)
|
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
|
// kickAndDrop deregisters an account and kicks them from the group chat
|
||||||
|
3
main.go
3
main.go
@ -8,9 +8,10 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
configFile := flag.String("ConfigFile", "config.json", "")
|
configFile := flag.String("ConfigFile", "config.json", "")
|
||||||
|
verbose := flag.Bool("Verbose", false, "")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
svr, err := NewNTFServer(*configFile)
|
svr, err := NewNTFServer(*configFile, *verbose)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user