forked from MirrorHub/mautrix-whatsapp
Check for WhatsApp web updates on bridge startup
This commit is contained in:
parent
c82a96dccc
commit
e31788541a
3 changed files with 26 additions and 3 deletions
2
go.mod
2
go.mod
|
@ -10,7 +10,7 @@ require (
|
||||||
github.com/prometheus/client_golang v1.11.1
|
github.com/prometheus/client_golang v1.11.1
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
github.com/tidwall/gjson v1.14.0
|
github.com/tidwall/gjson v1.14.0
|
||||||
go.mau.fi/whatsmeow v0.0.0-20220309134402-6c95a0dfb20d
|
go.mau.fi/whatsmeow v0.0.0-20220312175208-0c4681a6ff52
|
||||||
golang.org/x/image v0.0.0-20220302094943-723b81ca9867
|
golang.org/x/image v0.0.0-20220302094943-723b81ca9867
|
||||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
|
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
|
||||||
google.golang.org/protobuf v1.27.1
|
google.golang.org/protobuf v1.27.1
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -122,8 +122,8 @@ github.com/tidwall/sjson v1.2.4 h1:cuiLzLnaMeBhRmEv00Lpk3tkYrcxpmbU81tAY4Dw0tc=
|
||||||
github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM=
|
github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM=
|
||||||
go.mau.fi/libsignal v0.0.0-20220308120827-0d87a03fd7c7 h1:L09XYQRGJwC6KbJumz3cD/6JTUAPNZHfnu8hroqm1KE=
|
go.mau.fi/libsignal v0.0.0-20220308120827-0d87a03fd7c7 h1:L09XYQRGJwC6KbJumz3cD/6JTUAPNZHfnu8hroqm1KE=
|
||||||
go.mau.fi/libsignal v0.0.0-20220308120827-0d87a03fd7c7/go.mod h1:LjEYzdnRUcRArJJUUHQUfMU1A+WzEM73qBTirXluuaY=
|
go.mau.fi/libsignal v0.0.0-20220308120827-0d87a03fd7c7/go.mod h1:LjEYzdnRUcRArJJUUHQUfMU1A+WzEM73qBTirXluuaY=
|
||||||
go.mau.fi/whatsmeow v0.0.0-20220309134402-6c95a0dfb20d h1:pjPvv93XTsXVFMypsIdSYisbsAPDZLJ4y11XL1sqQ7k=
|
go.mau.fi/whatsmeow v0.0.0-20220312175208-0c4681a6ff52 h1:CVJ4dVzluwsUFI8zBLQBlrtYHuMcEYM6oLeAbplCrI4=
|
||||||
go.mau.fi/whatsmeow v0.0.0-20220309134402-6c95a0dfb20d/go.mod h1:nH4IwHZf+Ks61nM5p71jZqLXiT0NpG+0uR/WqzCqHH8=
|
go.mau.fi/whatsmeow v0.0.0-20220312175208-0c4681a6ff52/go.mod h1:nH4IwHZf+Ks61nM5p71jZqLXiT0NpG+0uR/WqzCqHH8=
|
||||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
|
23
main.go
23
main.go
|
@ -20,6 +20,7 @@ import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -30,6 +31,7 @@ import (
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
|
"go.mau.fi/whatsmeow"
|
||||||
waProto "go.mau.fi/whatsmeow/binary/proto"
|
waProto "go.mau.fi/whatsmeow/binary/proto"
|
||||||
"go.mau.fi/whatsmeow/store"
|
"go.mau.fi/whatsmeow/store"
|
||||||
"go.mau.fi/whatsmeow/store/sqlstore"
|
"go.mau.fi/whatsmeow/store/sqlstore"
|
||||||
|
@ -318,6 +320,7 @@ func (bridge *Bridge) Start() {
|
||||||
go bridge.AS.Start()
|
go bridge.AS.Start()
|
||||||
bridge.Log.Debugln("Starting event processor")
|
bridge.Log.Debugln("Starting event processor")
|
||||||
go bridge.EventProcessor.Start()
|
go bridge.EventProcessor.Start()
|
||||||
|
go bridge.CheckWhatsAppUpdate()
|
||||||
go bridge.UpdateBotProfile()
|
go bridge.UpdateBotProfile()
|
||||||
if bridge.Crypto != nil {
|
if bridge.Crypto != nil {
|
||||||
go bridge.Crypto.Start()
|
go bridge.Crypto.Start()
|
||||||
|
@ -334,6 +337,26 @@ func (bridge *Bridge) Start() {
|
||||||
bridge.AS.Ready = true
|
bridge.AS.Ready = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bridge *Bridge) CheckWhatsAppUpdate() {
|
||||||
|
bridge.Log.Debugfln("Checking for WhatsApp web update")
|
||||||
|
resp, err := whatsmeow.CheckUpdate(http.DefaultClient)
|
||||||
|
if err != nil {
|
||||||
|
bridge.Log.Warnfln("Failed to check for WhatsApp web update: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if store.GetWAVersion() == resp.ParsedVersion {
|
||||||
|
bridge.Log.Debugfln("Bridge is using latest WhatsApp web protocol")
|
||||||
|
} else if store.GetWAVersion().LessThan(resp.ParsedVersion) {
|
||||||
|
if resp.IsBelowHard || resp.IsBelowSoft || resp.IsBroken {
|
||||||
|
bridge.Log.Warnfln("Bridge is using outdated WhatsApp web protocol and may no longer function (%s, latest is %s)", store.GetWAVersion(), resp.ParsedVersion)
|
||||||
|
} else {
|
||||||
|
bridge.Log.Debugfln("Bridge is using outdated WhatsApp web protocol (%s, latest is %s)", store.GetWAVersion(), resp.ParsedVersion)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bridge.Log.Debugfln("Bridge is using newer than latest WhatsApp web protocol")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) Loop() {
|
func (bridge *Bridge) Loop() {
|
||||||
for {
|
for {
|
||||||
bridge.SleepAndDeleteUpcoming()
|
bridge.SleepAndDeleteUpcoming()
|
||||||
|
|
Loading…
Reference in a new issue