Delete guild portals too in delete-all-portals
This commit is contained in:
26
commands.go
26
commands.go
@@ -30,6 +30,7 @@ import (
|
|||||||
"github.com/skip2/go-qrcode"
|
"github.com/skip2/go-qrcode"
|
||||||
|
|
||||||
"maunium.net/go/mautrix"
|
"maunium.net/go/mautrix"
|
||||||
|
"maunium.net/go/mautrix/appservice"
|
||||||
"maunium.net/go/mautrix/bridge/commands"
|
"maunium.net/go/mautrix/bridge/commands"
|
||||||
"maunium.net/go/mautrix/event"
|
"maunium.net/go/mautrix/event"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
@@ -426,14 +427,15 @@ var cmdDeleteAllPortals = &commands.FullHandler{
|
|||||||
|
|
||||||
func fnDeleteAllPortals(ce *WrappedCommandEvent) {
|
func fnDeleteAllPortals(ce *WrappedCommandEvent) {
|
||||||
portals := ce.Bridge.GetAllPortals()
|
portals := ce.Bridge.GetAllPortals()
|
||||||
if len(portals) == 0 {
|
guilds := ce.Bridge.GetAllGuilds()
|
||||||
|
if len(portals) == 0 && len(guilds) == 0 {
|
||||||
ce.Reply("Didn't find any portals")
|
ce.Reply("Didn't find any portals")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
leave := func(portal *Portal) {
|
leave := func(mxid id.RoomID, intent *appservice.IntentAPI) {
|
||||||
if len(portal.MXID) > 0 {
|
if len(mxid) > 0 {
|
||||||
_, _ = portal.MainIntent().KickUser(portal.MXID, &mautrix.ReqKickUser{
|
_, _ = intent.KickUser(mxid, &mautrix.ReqKickUser{
|
||||||
Reason: "Deleting portal",
|
Reason: "Deleting portal",
|
||||||
UserID: ce.User.MXID,
|
UserID: ce.User.MXID,
|
||||||
})
|
})
|
||||||
@@ -442,17 +444,21 @@ func fnDeleteAllPortals(ce *WrappedCommandEvent) {
|
|||||||
customPuppet := ce.Bridge.GetPuppetByCustomMXID(ce.User.MXID)
|
customPuppet := ce.Bridge.GetPuppetByCustomMXID(ce.User.MXID)
|
||||||
if customPuppet != nil && customPuppet.CustomIntent() != nil {
|
if customPuppet != nil && customPuppet.CustomIntent() != nil {
|
||||||
intent := customPuppet.CustomIntent()
|
intent := customPuppet.CustomIntent()
|
||||||
leave = func(portal *Portal) {
|
leave = func(mxid id.RoomID, _ *appservice.IntentAPI) {
|
||||||
if len(portal.MXID) > 0 {
|
if len(mxid) > 0 {
|
||||||
_, _ = intent.LeaveRoom(portal.MXID)
|
_, _ = intent.LeaveRoom(mxid)
|
||||||
_, _ = intent.ForgetRoom(portal.MXID)
|
_, _ = intent.ForgetRoom(mxid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ce.Reply("Found %d portals, deleting...", len(portals))
|
ce.Reply("Found %d channel portals and %d guild portals, deleting...", len(portals), len(guilds))
|
||||||
for _, portal := range portals {
|
for _, portal := range portals {
|
||||||
portal.Delete()
|
portal.Delete()
|
||||||
leave(portal)
|
leave(portal.MXID, portal.MainIntent())
|
||||||
|
}
|
||||||
|
for _, guild := range guilds {
|
||||||
|
guild.Delete()
|
||||||
|
leave(guild.MXID, ce.Bot)
|
||||||
}
|
}
|
||||||
ce.Reply("Finished deleting portal info. Now cleaning up rooms in background.")
|
ce.Reply("Finished deleting portal info. Now cleaning up rooms in background.")
|
||||||
|
|
||||||
|
|||||||
@@ -315,3 +315,14 @@ func (guild *Guild) RemoveMXID() {
|
|||||||
guild.BridgingMode = database.GuildBridgeNothing
|
guild.BridgingMode = database.GuildBridgeNothing
|
||||||
guild.Update()
|
guild.Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (guild *Guild) Delete() {
|
||||||
|
guild.Guild.Delete()
|
||||||
|
guild.bridge.guildsLock.Lock()
|
||||||
|
delete(guild.bridge.guildsByID, guild.ID)
|
||||||
|
if guild.MXID != "" {
|
||||||
|
delete(guild.bridge.guildsByMXID, guild.MXID)
|
||||||
|
}
|
||||||
|
guild.bridge.guildsLock.Unlock()
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -1210,15 +1210,6 @@ func (portal *Portal) HandleMatrixLeave(brSender bridge.User) {
|
|||||||
func (portal *Portal) HandleMatrixKick(brSender bridge.User, brTarget bridge.Ghost) {}
|
func (portal *Portal) HandleMatrixKick(brSender bridge.User, brTarget bridge.Ghost) {}
|
||||||
func (portal *Portal) HandleMatrixInvite(brSender bridge.User, brTarget bridge.Ghost) {}
|
func (portal *Portal) HandleMatrixInvite(brSender bridge.User, brTarget bridge.Ghost) {}
|
||||||
|
|
||||||
func (portal *Portal) leave(sender *User) {
|
|
||||||
if portal.MXID == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
intent := portal.bridge.GetPuppetByID(sender.DiscordID).IntentFor(portal)
|
|
||||||
intent.LeaveRoom(portal.MXID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (portal *Portal) Delete() {
|
func (portal *Portal) Delete() {
|
||||||
portal.Portal.Delete()
|
portal.Portal.Delete()
|
||||||
portal.bridge.portalsLock.Lock()
|
portal.bridge.portalsLock.Lock()
|
||||||
|
|||||||
Reference in New Issue
Block a user