Handle contact and battery events
This commit is contained in:
parent
d4e812b968
commit
f4ce80f98e
2
go.mod
2
go.mod
@ -19,4 +19,4 @@ require (
|
||||
maunium.net/go/mautrix v0.5.5
|
||||
)
|
||||
|
||||
replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.3.2
|
||||
replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.3.3
|
||||
|
2
go.sum
2
go.sum
@ -113,6 +113,8 @@ github.com/tidwall/sjson v1.1.1 h1:7h1vk049Jnd5EH9NyzNiEuwYW4b5qgreBbqRC19AS3U=
|
||||
github.com/tidwall/sjson v1.1.1/go.mod h1:yvVuSnpEQv5cYIrO+AT6kw4QVfd5SDZoGIS7/5+fZFs=
|
||||
github.com/tulir/go-whatsapp v0.3.2 h1:SPNyB/yxaYY1Sca75OttsrsPNMPZzpjhwTzJy6Dx9ig=
|
||||
github.com/tulir/go-whatsapp v0.3.2/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
|
||||
github.com/tulir/go-whatsapp v0.3.3 h1:R/SRdgjG1rdmegxx1CE2KmVBKzI8xvC9EE+NNApb4rA=
|
||||
github.com/tulir/go-whatsapp v0.3.3/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
|
||||
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-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
|
||||
|
28
user.go
28
user.go
@ -59,6 +59,7 @@ type User struct {
|
||||
CommunityID string
|
||||
|
||||
cleanDisconnection bool
|
||||
batteryWarningsSent int
|
||||
|
||||
chatListReceived chan struct{}
|
||||
syncPortalsDone chan struct{}
|
||||
@ -672,6 +673,33 @@ func (user *User) putMessage(message PortalMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
func (user *User) HandleNewContact(contact whatsapp.Contact) {
|
||||
user.log.Debugfln("Contact message: %+v", contact)
|
||||
go func() {
|
||||
puppet := user.bridge.GetPuppetByJID(contact.Jid)
|
||||
puppet.UpdateName(user, contact)
|
||||
}()
|
||||
}
|
||||
|
||||
func (user *User) HandleBatteryMessage(battery whatsapp.BatteryMessage) {
|
||||
user.log.Debugfln("Battery message: %+v", battery)
|
||||
var notice string
|
||||
if !battery.Plugged && battery.Percentage < 15 && user.batteryWarningsSent < 1 {
|
||||
notice = fmt.Sprintf("Phone battery low (%d remaining)", battery.Percentage)
|
||||
user.batteryWarningsSent = 1
|
||||
} else if !battery.Plugged && battery.Percentage < 5 && user.batteryWarningsSent < 1 {
|
||||
notice = fmt.Sprintf("Phone battery very low (%d remaining)", battery.Percentage)
|
||||
user.batteryWarningsSent = 2
|
||||
} else {
|
||||
user.batteryWarningsSent = 0
|
||||
}
|
||||
if notice != "" {
|
||||
go func() {
|
||||
_, _ = user.bridge.Bot.SendNotice(user.GetManagementRoom(), notice)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func (user *User) HandleTextMessage(message whatsapp.TextMessage) {
|
||||
user.putMessage(PortalMessage{message.Info.RemoteJid, user, message, message.Info.Timestamp})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user