-
Notifications
You must be signed in to change notification settings - Fork 9
policyeval/commands: Fall back to continuwuityadmin when blocking rooms #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
timedoutuk
wants to merge
3
commits into
main
Choose a base branch
from
nexy7574/c10y-room-blocking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ import ( | |
| "crypto/sha256" | ||
| "encoding/base64" | ||
| "encoding/json" | ||
| "errors" | ||
|
|
||
| "fmt" | ||
| "regexp" | ||
| "slices" | ||
|
|
@@ -926,27 +928,27 @@ var cmdRoomInfo = &CommandHandler{ | |
| }), | ||
| } | ||
|
|
||
| func formatDeleteResult(resp synapseadmin.RespDeleteRoomResult) string { | ||
| func formatDeleteResult(kicked, failed []id.UserID, aliases []id.RoomAlias) string { | ||
| var parts []string | ||
| if len(resp.KickedUsers) > 10 { | ||
| parts = append(parts, fmt.Sprintf("* Kicked %d users", len(resp.KickedUsers))) | ||
| if len(kicked) > 10 { | ||
| parts = append(parts, fmt.Sprintf("* Kicked %d users", len(kicked))) | ||
| } else { | ||
| kickedUsers := make([]string, len(resp.KickedUsers)) | ||
| for i, user := range resp.KickedUsers { | ||
| kickedUsers := make([]string, len(kicked)) | ||
| for i, user := range kicked { | ||
| kickedUsers[i] = format.MarkdownMention(user) | ||
| } | ||
| parts = append(parts, fmt.Sprintf("* Kicked users: %s", strings.Join(kickedUsers, ", "))) | ||
| } | ||
| if len(resp.FailedToKickUsers) > 0 { | ||
| failedUsers := make([]string, len(resp.FailedToKickUsers)) | ||
| for i, user := range resp.FailedToKickUsers { | ||
| if len(failed) > 0 { | ||
| failedUsers := make([]string, len(failed)) | ||
| for i, user := range failed { | ||
| failedUsers[i] = format.MarkdownMention(user) | ||
| } | ||
| parts = append(parts, fmt.Sprintf("* Failed to kick users: %s", strings.Join(failedUsers, ", "))) | ||
| } | ||
| if len(resp.LocalAliases) > 0 { | ||
| localAliases := make([]string, len(resp.LocalAliases)) | ||
| for i, alias := range resp.LocalAliases { | ||
| if len(aliases) > 0 { | ||
| localAliases := make([]string, len(aliases)) | ||
| for i, alias := range aliases { | ||
| localAliases[i] = format.SafeMarkdownCode(alias) | ||
| } | ||
| parts = append(parts, fmt.Sprintf("* Deleted local aliases: %s", strings.Join(localAliases, ", "))) | ||
|
|
@@ -970,7 +972,9 @@ var cmdRoomDeleteStatus = &CommandHandler{ | |
| if err != nil { | ||
| ce.Reply("Failed to get delete status for %s: %v", format.SafeMarkdownCode(args.DeleteID), err) | ||
| } else if resp.Status == "complete" { | ||
| ce.Reply("Deletion is complete:\n\n%s", formatDeleteResult(resp.ShutdownRoom)) | ||
| ce.Reply("Deletion is complete:\n\n%s", formatDeleteResult( | ||
| resp.ShutdownRoom.KickedUsers, resp.ShutdownRoom.FailedToKickUsers, resp.ShutdownRoom.LocalAliases, | ||
| )) | ||
| } else if resp.Status == "failed" { | ||
| ce.Reply("Deletion failed: %s", resp.Error) | ||
| } else { | ||
|
|
@@ -1060,9 +1064,26 @@ var cmdRoomDelete = &CommandHandler{ | |
| resp, err := ce.Meta.Bot.SynapseAdmin.DeleteRoomSync(ce.Ctx, roomID, req) | ||
| _, _ = ce.Meta.Bot.RedactEvent(ce.Ctx, ce.RoomID, reactionID) | ||
| if err != nil { | ||
| if errors.Is(err, mautrix.MUnrecognized) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be moved 2 lines up (between DeleteRoomSync and RedactEvent). |
||
| resp2, err := ce.Meta.Bot.ContinuwuityAdmin.BanRoom(ce.Ctx, roomID) | ||
| if err != nil { | ||
| ce.Reply("Failed to ban room %s: %v", format.SafeMarkdownCode(roomID), err) | ||
| return | ||
| } | ||
| ce.Reply( | ||
| "Successfully banned room %s\n\n%s", | ||
| format.SafeMarkdownCode(roomID), | ||
| formatDeleteResult(resp2.KickedUsers, resp2.FailedKickedUsers, resp2.LocalAliases), | ||
| ) | ||
| return | ||
| } | ||
| ce.Reply("Failed to delete room %s: %v", format.SafeMarkdownCode(roomID), err) | ||
| } else { | ||
| ce.Reply("Successfully deleted room %s\n\n%s", format.SafeMarkdownCode(roomID), formatDeleteResult(resp)) | ||
| ce.Reply( | ||
| "Successfully deleted room %s\n\n%s", | ||
| format.SafeMarkdownCode(roomID), | ||
| formatDeleteResult(resp.KickedUsers, resp.FailedToKickUsers, resp.LocalAliases), | ||
| ) | ||
| } | ||
| } | ||
| }), | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes can be undone after mautrix/go#452 (comment)