forked from MirrorHub/mautrix-whatsapp
Add admin command to delete portal and fix some other things
This commit is contained in:
parent
9c8a75583e
commit
adc7257490
3 changed files with 28 additions and 5 deletions
19
commands.go
19
commands.go
|
@ -85,6 +85,8 @@ func (handler *CommandHandler) Handle(roomID types.MatrixRoomID, user *User, mes
|
||||||
handler.CommandReconnect(ce)
|
handler.CommandReconnect(ce)
|
||||||
case "delete-session":
|
case "delete-session":
|
||||||
handler.CommandDeleteSession(ce)
|
handler.CommandDeleteSession(ce)
|
||||||
|
case "delete-portal":
|
||||||
|
handler.CommandDeletePortal(ce)
|
||||||
case "logout", "disconnect", "sync", "list", "open", "pm":
|
case "logout", "disconnect", "sync", "list", "open", "pm":
|
||||||
if ce.User.Conn == nil {
|
if ce.User.Conn == nil {
|
||||||
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.")
|
||||||
|
@ -277,6 +279,23 @@ func (handler *CommandHandler) CommandSync(ce *CommandEvent) {
|
||||||
ce.Reply("Imported contacts successfully.")
|
ce.Reply("Imported contacts successfully.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (handler *CommandHandler) CommandDeletePortal(ce *CommandEvent) {
|
||||||
|
if !ce.User.Admin {
|
||||||
|
ce.Reply("Only bridge admins can delete portals")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
portal := ce.Bridge.GetPortalByMXID(ce.RoomID)
|
||||||
|
if portal == nil {
|
||||||
|
ce.Reply("You must be in a portal room to use that command")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
portal.log.Infoln(ce.User.MXID, "requested deletion of portal.")
|
||||||
|
portal.Delete()
|
||||||
|
portal.Cleanup(false)
|
||||||
|
}
|
||||||
|
|
||||||
const cmdListHelp = `list - Get a list of all contacts and groups.`
|
const cmdListHelp = `list - Get a list of all contacts and groups.`
|
||||||
|
|
||||||
func (handler *CommandHandler) CommandList(ce *CommandEvent) {
|
func (handler *CommandHandler) CommandList(ce *CommandEvent) {
|
||||||
|
|
|
@ -1021,13 +1021,17 @@ func (portal *Portal) Cleanup(puppetsOnly bool) {
|
||||||
puppet := portal.bridge.GetPuppetByMXID(member)
|
puppet := portal.bridge.GetPuppetByMXID(member)
|
||||||
if puppet != nil {
|
if puppet != nil {
|
||||||
_, err = puppet.Intent().LeaveRoom(portal.MXID)
|
_, err = puppet.Intent().LeaveRoom(portal.MXID)
|
||||||
|
if err != nil {
|
||||||
portal.log.Errorln("Error leaving as puppet while cleaning up portal:", err)
|
portal.log.Errorln("Error leaving as puppet while cleaning up portal:", err)
|
||||||
|
}
|
||||||
} else if !puppetsOnly {
|
} else if !puppetsOnly {
|
||||||
_, err = intent.KickUser(portal.MXID, &mautrix.ReqKickUser{UserID: member, Reason: "Deleting portal"})
|
_, err = intent.KickUser(portal.MXID, &mautrix.ReqKickUser{UserID: member, Reason: "Deleting portal"})
|
||||||
|
if err != nil {
|
||||||
portal.log.Errorln("Error kicking user while cleaning up portal:", err)
|
portal.log.Errorln("Error kicking user while cleaning up portal:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (portal *Portal) HandleMatrixLeave(sender *User) {
|
func (portal *Portal) HandleMatrixLeave(sender *User) {
|
||||||
if portal.IsPrivateChat() {
|
if portal.IsPrivateChat() {
|
||||||
|
|
Loading…
Reference in a new issue