mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-14 09:23:51 +01:00
Add command to change disappearing timer
This commit is contained in:
parent
b6ec252fcd
commit
0ed0f61ced
4 changed files with 46 additions and 4 deletions
41
commands.go
41
commands.go
|
@ -87,6 +87,17 @@ func (ce *CommandEvent) Reply(msg string, args ...interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ce *CommandEvent) React(key string) {
|
||||||
|
intent := ce.Bot
|
||||||
|
if ce.Portal != nil && ce.Portal.IsPrivateChat() {
|
||||||
|
intent = ce.Portal.MainIntent()
|
||||||
|
}
|
||||||
|
_, err := intent.SendReaction(ce.RoomID, ce.EventID, key)
|
||||||
|
if err != nil {
|
||||||
|
ce.Handler.log.Warnfln("Failed to react to command from %s: %v", ce.User.MXID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle handles messages to the bridge
|
// Handle handles messages to the bridge
|
||||||
func (handler *CommandHandler) Handle(roomID id.RoomID, eventID id.EventID, user *User, message string, replyTo id.EventID) {
|
func (handler *CommandHandler) Handle(roomID id.RoomID, eventID id.EventID, user *User, message string, replyTo id.EventID) {
|
||||||
args := strings.Fields(message)
|
args := strings.Fields(message)
|
||||||
|
@ -143,7 +154,8 @@ func (handler *CommandHandler) CommandMux(ce *CommandEvent) {
|
||||||
handler.CommandLogout(ce)
|
handler.CommandLogout(ce)
|
||||||
case "toggle":
|
case "toggle":
|
||||||
handler.CommandToggle(ce)
|
handler.CommandToggle(ce)
|
||||||
case "set-relay", "unset-relay", "login-matrix", "sync", "list", "search", "open", "pm", "invite-link", "resolve", "resolve-link", "join", "create", "accept", "backfill":
|
case "set-relay", "unset-relay", "login-matrix", "sync", "list", "search", "open", "pm", "invite-link", "resolve",
|
||||||
|
"resolve-link", "join", "create", "accept", "backfill", "disappearing-timer":
|
||||||
if !ce.User.HasSession() {
|
if !ce.User.HasSession() {
|
||||||
ce.Reply("You are not logged in. Use the `login` command to log into WhatsApp.")
|
ce.Reply("You are not logged in. Use the `login` command to log into WhatsApp.")
|
||||||
return
|
return
|
||||||
|
@ -181,6 +193,8 @@ func (handler *CommandHandler) CommandMux(ce *CommandEvent) {
|
||||||
handler.CommandAccept(ce)
|
handler.CommandAccept(ce)
|
||||||
case "backfill":
|
case "backfill":
|
||||||
handler.CommandBackfill(ce)
|
handler.CommandBackfill(ce)
|
||||||
|
case "disappearing-timer":
|
||||||
|
handler.CommandDisappearingTimer(ce)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
ce.Reply("Unknown command, use the `help` command for help.")
|
ce.Reply("Unknown command, use the `help` command for help.")
|
||||||
|
@ -750,6 +764,7 @@ func (handler *CommandHandler) CommandHelp(ce *CommandEvent) {
|
||||||
cmdPrefix + cmdResolveLinkHelp,
|
cmdPrefix + cmdResolveLinkHelp,
|
||||||
cmdPrefix + cmdJoinHelp,
|
cmdPrefix + cmdJoinHelp,
|
||||||
cmdPrefix + cmdCreateHelp,
|
cmdPrefix + cmdCreateHelp,
|
||||||
|
cmdPrefix + cmdDisappearingTimerHelp,
|
||||||
cmdPrefix + cmdSetPowerLevelHelp,
|
cmdPrefix + cmdSetPowerLevelHelp,
|
||||||
cmdPrefix + cmdDeletePortalHelp,
|
cmdPrefix + cmdDeletePortalHelp,
|
||||||
cmdPrefix + cmdDeleteAllPortalsHelp,
|
cmdPrefix + cmdDeleteAllPortalsHelp,
|
||||||
|
@ -1211,3 +1226,27 @@ func (handler *CommandHandler) CommandLogoutMatrix(ce *CommandEvent) {
|
||||||
}
|
}
|
||||||
ce.Reply("Successfully removed custom puppet")
|
ce.Reply("Successfully removed custom puppet")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cmdDisappearingTimerHelp = `disappearing-timer <off/1d/7d/90d> - Set future messages in the room to disappear after the given time.`
|
||||||
|
|
||||||
|
func (handler *CommandHandler) CommandDisappearingTimer(ce *CommandEvent) {
|
||||||
|
duration, ok := whatsmeow.ParseDisappearingTimerString(ce.Args[0])
|
||||||
|
if !ok {
|
||||||
|
ce.Reply("Invalid timer '%s'", ce.Args[0])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
prevExpirationTime := ce.Portal.ExpirationTime
|
||||||
|
ce.Portal.ExpirationTime = uint32(duration.Seconds())
|
||||||
|
err := ce.User.Client.SetDisappearingTimer(ce.Portal.Key.JID, duration)
|
||||||
|
if err != nil {
|
||||||
|
ce.Reply("Failed to set disappearing timer: %v", err)
|
||||||
|
ce.Portal.ExpirationTime = prevExpirationTime
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ce.Portal.Update()
|
||||||
|
if !ce.Portal.IsPrivateChat() && !ce.Bridge.Config.Bridge.DisappearingMessagesInGroups {
|
||||||
|
ce.Reply("Disappearing timer changed successfully, but this bridge is not configured to disappear messages in group chats.")
|
||||||
|
} else {
|
||||||
|
ce.React("✅")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -10,7 +10,7 @@ require (
|
||||||
github.com/prometheus/client_golang v1.12.2-0.20220514081015-5d584e2717ef
|
github.com/prometheus/client_golang v1.12.2-0.20220514081015-5d584e2717ef
|
||||||
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.1
|
github.com/tidwall/gjson v1.14.1
|
||||||
go.mau.fi/whatsmeow v0.0.0-20220515081149-cea8dab19fc9
|
go.mau.fi/whatsmeow v0.0.0-20220515110043-a0a87653cff0
|
||||||
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9
|
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9
|
||||||
golang.org/x/net v0.0.0-20220513224357-95641704303c
|
golang.org/x/net v0.0.0-20220513224357-95641704303c
|
||||||
google.golang.org/protobuf v1.28.0
|
google.golang.org/protobuf v1.28.0
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -62,8 +62,8 @@ github.com/yuin/goldmark v1.4.12 h1:6hffw6vALvEDqJ19dOJvJKOoAOKe4NDaTqvd2sktGN0=
|
||||||
github.com/yuin/goldmark v1.4.12/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.12/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
go.mau.fi/libsignal v0.0.0-20220425070825-c40c839ee6a0 h1:3IQF2bgAyibdo77hTejwuJe4jlypj9QaE4xCQuxrThM=
|
go.mau.fi/libsignal v0.0.0-20220425070825-c40c839ee6a0 h1:3IQF2bgAyibdo77hTejwuJe4jlypj9QaE4xCQuxrThM=
|
||||||
go.mau.fi/libsignal v0.0.0-20220425070825-c40c839ee6a0/go.mod h1:kBOXTvYyDG/q1Ihgvd4J6WenGPh7wtEGvPKF6vmf5ak=
|
go.mau.fi/libsignal v0.0.0-20220425070825-c40c839ee6a0/go.mod h1:kBOXTvYyDG/q1Ihgvd4J6WenGPh7wtEGvPKF6vmf5ak=
|
||||||
go.mau.fi/whatsmeow v0.0.0-20220515081149-cea8dab19fc9 h1:mYmfIeKdlvWHwOMz2SIkC4N35JDc5TXIxLHhdISZZ1I=
|
go.mau.fi/whatsmeow v0.0.0-20220515110043-a0a87653cff0 h1:VtmnDmyjGRaKP6i8cjvn8rHq+qolMdToXNQMEEtheM0=
|
||||||
go.mau.fi/whatsmeow v0.0.0-20220515081149-cea8dab19fc9/go.mod h1:iUBgOLNaqShLrR17u0kIiRptIGFH+nbT1tRhaWBEX/c=
|
go.mau.fi/whatsmeow v0.0.0-20220515110043-a0a87653cff0/go.mod h1:iUBgOLNaqShLrR17u0kIiRptIGFH+nbT1tRhaWBEX/c=
|
||||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9 h1:NUzdAbFtCJSXU20AOXgeqaUwg8Ypg4MPYmL+d+rsB5c=
|
golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9 h1:NUzdAbFtCJSXU20AOXgeqaUwg8Ypg4MPYmL+d+rsB5c=
|
||||||
golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
|
|
|
@ -497,6 +497,9 @@ func (portal *Portal) convertMessage(intent *appservice.IntentAPI, source *User,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) UpdateGroupDisappearingMessages(sender *types.JID, timestamp time.Time, timer uint32) {
|
func (portal *Portal) UpdateGroupDisappearingMessages(sender *types.JID, timestamp time.Time, timer uint32) {
|
||||||
|
if portal.ExpirationTime == timer {
|
||||||
|
return
|
||||||
|
}
|
||||||
portal.ExpirationTime = timer
|
portal.ExpirationTime = timer
|
||||||
portal.Update()
|
portal.Update()
|
||||||
intent := portal.MainIntent()
|
intent := portal.MainIntent()
|
||||||
|
|
Loading…
Reference in a new issue