From 9f3892465e13359c3c71d9b355513fb1cab3fbaa Mon Sep 17 00:00:00 2001 From: RandomChars <random@chars.jp> Date: Sun, 1 Aug 2021 13:50:17 +0900 Subject: [PATCH] add some debug messages --- config.go | 2 +- handler.go | 9 ++++++++- instance.go | 2 ++ main.go | 21 +++++++++++++++++---- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/config.go b/config.go index 670bf5a..0d5c866 100644 --- a/config.go +++ b/config.go @@ -25,7 +25,7 @@ type configPayload struct { } func init() { - flag.StringVar(&configPath, "-t", "server.conf", "Specify configuration file location.") + flag.StringVar(&configPath, "c", "server.conf", "Specify configuration file location.") } func parse() { diff --git a/handler.go b/handler.go index 11e2d22..d896a86 100644 --- a/handler.go +++ b/handler.go @@ -16,26 +16,31 @@ var allowedChannels map[string]bool func handleChatInitiate(context *multiplexer.Context) { // Lookup channel in allowed map if context.Channel == nil || !allowedChannels[context.Channel.ID] { + log.Debug("Chat initiate skipped on irrelevant channel.") return } // Get event var event *discordgo.VoiceStateUpdate if e, ok := context.Event.(*discordgo.VoiceStateUpdate); !ok { + log.Debug("Chat initiate skipped on incorrect event.") return } else { event = e } if event.VoiceState != nil { if event.VoiceState.ChannelID == "" { + log.Debug("Chat initiate skipped on empty channel ID.") return } } else { + log.Debug("Chat initiate skipped on nil voice state.") return } // Lookup already existing channel if instancesUser[event.UserID] != nil { + log.Debug("Chat initiate skipped on existing channel owner.") return } @@ -53,12 +58,14 @@ func handleChatInitiate(context *multiplexer.Context) { member = u } if member == nil { + log.Debug("Chat initiate skipped on nil member.") return } // Create new instance instance := newInstance(member) if instance == nil { + log.Debug("Chat initiate skipped on nil instance.") return } @@ -70,7 +77,7 @@ func handleChatInitiate(context *multiplexer.Context) { instance.Channel.ID, context.Guild.Name, context.Guild.ID, - ) + ) // Move user to newly created volatile channel if err := session.GuildMemberMove(event.GuildID, event.UserID, &instance.Channel.ID); err != nil { diff --git a/instance.go b/instance.go index 77e762f..e237f63 100644 --- a/instance.go +++ b/instance.go @@ -63,11 +63,13 @@ func newInstance(member *discordgo.Member) *chatInstance { func setupInstance(member *discordgo.Member) *chatInstance { channelID := guildMap[member.GuildID] if channelID == "" { + log.Debug("Instance setup skipped on empty channel ID.") return nil } parentID := categoryMap[channelID] if parentID == "" { + log.Debug("Instance setup skipped on emptu parent ID.") return nil } diff --git a/main.go b/main.go index d3b19c0..eb9bb35 100644 --- a/main.go +++ b/main.go @@ -12,14 +12,27 @@ import ( "syscall" ) -var session *discordgo.Session -var m = multiplexer.New() -var system = multiplexer.NewCategory("System", "System-related utilities.") +var ( + session *discordgo.Session + m = multiplexer.New() + system = multiplexer.NewCategory("System", "System-related utilities.") + verbose bool +) + +func init() { + flag.BoolVar(&verbose, "v", false, "Start up with debug logging.") +} func main() { flag.Parse() parse() + if verbose { + log.SetLevel(logrus.DebugLevel) + } else { + log.SetLevel(logrus.InfoLevel) + } + // Set discordgo log handler discordgo.Logger = func(msgL, _ int, format string, a ...interface{}) { var level logrus.Level @@ -56,7 +69,7 @@ func main() { // Open session func() { - open: + open: if err := session.Open(); err != nil { if session.Identify.Intents == discordgo.IntentsAll { log.Warnf("Wasn't able to start with full intents, some stuff might not work (%s)", err) -- GitLab