From a21a556c5729be6938c35209459d98ec38be4693 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 2 Aug 2023 15:19:55 +0300 Subject: [PATCH] Include more error states in ping command --- commands.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/commands.go b/commands.go index 051aaf8..f442fa2 100644 --- a/commands.go +++ b/commands.go @@ -290,11 +290,27 @@ func fnPing(ce *WrappedCommandEvent) { ce.Reply("You're not logged into Google Messages.") } } else if ce.User.Client == nil || !ce.User.Client.IsConnected() { - ce.Reply("You're logged in as %s, but you don't have a Google Messages connection.", ce.User.PhoneID) - } else if ce.User.browserInactiveType == "" { - ce.Reply("Logged in as %s and active as primary browser", ce.User.PhoneID) + ce.Reply("Linked to %s, but not connected to Google Messages.", ce.User.PhoneID) + } else if ce.User.longPollingError != nil { + ce.Reply("Linked to %s, but long polling is erroring (%v)", ce.User.PhoneID, ce.User.longPollingError) + } else if ce.User.browserInactiveType != "" { + ce.Reply("Linked to %s, but not active, use `set-active` to reconnect", ce.User.PhoneID) } else { - ce.Reply("Logged in as %s, but not active, use `set-active` to reconnect", ce.User.PhoneID) + modifiers := make([]string, 0, 3) + if ce.User.batteryLow { + modifiers = append(modifiers, "battery low") + } + if ce.User.mobileData { + modifiers = append(modifiers, "using mobile data") + } + if !ce.User.phoneResponding { + modifiers = append(modifiers, "phone not responding") + } + var modifierStr string + if len(modifiers) > 0 { + modifierStr = fmt.Sprintf(" (warnings: %s)", strings.Join(modifiers, ", ")) + } + ce.Reply("Linked to %s and active as primary browser%s", ce.User.PhoneID, modifierStr) } }