Add admin command to delete portal and fix some other things
This commit is contained in:
parent
9c8a75583e
commit
adc7257490
19
commands.go
19
commands.go
@ -85,6 +85,8 @@ func (handler *CommandHandler) Handle(roomID types.MatrixRoomID, user *User, mes
|
||||
handler.CommandReconnect(ce)
|
||||
case "delete-session":
|
||||
handler.CommandDeleteSession(ce)
|
||||
case "delete-portal":
|
||||
handler.CommandDeletePortal(ce)
|
||||
case "logout", "disconnect", "sync", "list", "open", "pm":
|
||||
if ce.User.Conn == nil {
|
||||
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.")
|
||||
}
|
||||
|
||||
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.`
|
||||
|
||||
func (handler *CommandHandler) CommandList(ce *CommandEvent) {
|
||||
|
@ -1021,10 +1021,14 @@ func (portal *Portal) Cleanup(puppetsOnly bool) {
|
||||
puppet := portal.bridge.GetPuppetByMXID(member)
|
||||
if puppet != nil {
|
||||
_, err = puppet.Intent().LeaveRoom(portal.MXID)
|
||||
portal.log.Errorln("Error leaving as puppet while cleaning up portal:", err)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Error leaving as puppet while cleaning up portal:", err)
|
||||
}
|
||||
} else if !puppetsOnly {
|
||||
_, err = intent.KickUser(portal.MXID, &mautrix.ReqKickUser{UserID: member, Reason: "Deleting portal"})
|
||||
portal.log.Errorln("Error kicking user while cleaning up portal:", err)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Error kicking user while cleaning up portal:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,9 +38,9 @@ func (ext *ExtendedConn) HandleRawMessage(message *proto.WebMessageInfo) {
|
||||
if protoMsg.GetType() == proto.ProtocolMessage_REVOKE {
|
||||
key := protoMsg.GetKey()
|
||||
deletedMessage := MessageRevocation{
|
||||
Id: key.GetId(),
|
||||
RemoteJid: key.GetRemoteJid(),
|
||||
FromMe: key.GetFromMe(),
|
||||
Id: key.GetId(),
|
||||
RemoteJid: key.GetRemoteJid(),
|
||||
FromMe: key.GetFromMe(),
|
||||
Participant: key.GetParticipant(),
|
||||
}
|
||||
for _, handler := range ext.handlers {
|
||||
|
Loading…
Reference in New Issue
Block a user