-
-
Notifications
You must be signed in to change notification settings - Fork 753
Fix error in botstrap when attempting to upgrade to community server #3528
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
wookie184
wants to merge
2
commits into
main
Choose a base branch
from
wookie/fix-botstrap-community-patch
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.
+34
−21
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -82,10 +82,6 @@ def __getitem__(self, item: str): | |||||
| sys.exit(-1) | ||||||
|
|
||||||
|
|
||||||
| class BotstrapError(Exception): | ||||||
| """Raised when an error occurs during the botstrap process.""" | ||||||
|
|
||||||
|
|
||||||
| class DiscordClient(Client): | ||||||
| """An HTTP client to communicate with Discord's APIs.""" | ||||||
|
|
||||||
|
|
@@ -167,17 +163,22 @@ def upgrade_server_to_community_if_necessary( | |||||
| announcements_channel_id: int | str, | ||||||
| ) -> bool: | ||||||
| """Fetches server info & upgrades to COMMUNITY if necessary.""" | ||||||
| payload = self.get_guild_info() | ||||||
|
|
||||||
| if COMMUNITY_FEATURE not in payload["features"]: | ||||||
| log.info("This server is currently not a community, upgrading.") | ||||||
| payload["features"].append(COMMUNITY_FEATURE) | ||||||
| payload["rules_channel_id"] = rules_channel_id | ||||||
| payload["public_updates_channel_id"] = announcements_channel_id | ||||||
| self._guild_info = self.patch(f"/guilds/{self.guild_id}", json=payload).json() | ||||||
| log.info("Server %s has been successfully updated to a community.", self.guild_id) | ||||||
| return True | ||||||
| return False | ||||||
| guild_info = self.get_guild_info() | ||||||
|
|
||||||
| if COMMUNITY_FEATURE in guild_info["features"]: | ||||||
| return False | ||||||
|
|
||||||
| log.info("This server is currently not a community, upgrading.") | ||||||
|
|
||||||
| payload = { | ||||||
| "features": guild_info["features"] + [COMMUNITY_FEATURE], | ||||||
| "rules_channel_id": rules_channel_id, | ||||||
| "public_updates_channel_id": announcements_channel_id, | ||||||
| } | ||||||
| self._guild_info = self.patch(f"/guilds/{self.guild_id}", json=payload).json() | ||||||
|
|
||||||
| log.info("Server %s has been successfully updated to a community.", self.guild_id) | ||||||
| return True | ||||||
|
|
||||||
| def get_all_roles(self) -> dict[str, int]: | ||||||
| """Fetches all the roles in a guild.""" | ||||||
|
|
@@ -330,20 +331,32 @@ def check_guild_membership(self) -> None: | |||||
| """Check the bot is in the required guild.""" | ||||||
| if not self.client.check_if_in_guild(): | ||||||
| log.error("The bot is not a member of the configured guild with ID %s.", self.guild_id) | ||||||
| log.warning( | ||||||
| log.info( | ||||||
| "Please invite with the following URL and rerun this script: " | ||||||
| "https://discord.com/oauth2/authorize?client_id=%s&guild_id=%s&scope=bot+applications.commands&permissions=8", | ||||||
| self.client_id, | ||||||
| self.guild_id, | ||||||
| ) | ||||||
| raise BotstrapError("Bot is not a member of the configured guild.") | ||||||
| sys.exit(1) | ||||||
|
|
||||||
| def upgrade_guild(self, announcements_channel_id: str, rules_channel_id: str) -> bool: | ||||||
| """Upgrade the guild to a community if necessary.""" | ||||||
| return self.client.upgrade_server_to_community_if_necessary( | ||||||
| rules_channel_id=rules_channel_id, | ||||||
| announcements_channel_id=announcements_channel_id, | ||||||
| ) | ||||||
| try: | ||||||
| return self.client.upgrade_server_to_community_if_necessary( | ||||||
| rules_channel_id=rules_channel_id, | ||||||
| announcements_channel_id=announcements_channel_id, | ||||||
| ) | ||||||
| except HTTPStatusError as e: | ||||||
| if e.response.status_code == 403: | ||||||
| log.error("Unable to upgrade to community guild as he bot does not have Administrator permissions") | ||||||
| log.info( | ||||||
| "Please re-invite with the following URL and rerun this script: " | ||||||
|
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.
Suggested change
This wording might be a bit more understandable to non-native English speakers. |
||||||
| "https://discord.com/oauth2/authorize?client_id=%s&guild_id=%s&scope=bot+applications.commands&permissions=8", | ||||||
| self.client_id, | ||||||
| self.guild_id, | ||||||
| ) | ||||||
| sys.exit(1) | ||||||
| raise | ||||||
|
|
||||||
| def get_roles(self) -> dict[str, Any]: | ||||||
| """Get a config map of all of the roles in the guild.""" | ||||||
|
|
||||||
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.