Skip to content

Commit 438ca32

Browse files
don't use a property api request
1 parent 4236b13 commit 438ca32

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

botstrap.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,14 @@ def __init__(self, *, guild_id: int | str, bot_token: str):
101101
def _raise_for_status(response: Response) -> None:
102102
response.raise_for_status()
103103

104-
@property
105-
def guild_info(self) -> dict[str, Any]:
104+
def get_guild_info(self) -> dict[str, Any]:
106105
"""Fetches the guild's information."""
107106
if self._guild_info is None:
108107
response = self.get(f"/guilds/{self.guild_id}")
109108
self._guild_info = cast("dict[str, Any]", response.json())
110109
return self._guild_info
111110

112-
@property
113-
def guild_channels(self) -> list[dict[str, Any]]:
111+
def get_guild_channels(self) -> list[dict[str, Any]]:
114112
"""Fetches the guild's channels."""
115113
if self._guild_channels is None:
116114
response = self.get(f"/guilds/{self.guild_id}/channels")
@@ -119,13 +117,12 @@ def guild_channels(self) -> list[dict[str, Any]]:
119117

120118
def get_channel(self, id_: int | str) -> dict[str, Any]:
121119
"""Fetches a channel by its ID."""
122-
for channel in self.guild_channels:
120+
for channel in self.get_guild_channels():
123121
if channel["id"] == str(id_):
124122
return channel
125123
raise KeyError(f"Channel with ID {id_} not found.")
126124

127-
@property
128-
def app_info(self) -> dict[str, Any]:
125+
def get_app_info(self) -> dict[str, Any]:
129126
"""Fetches the application's information."""
130127
if self._app_info is None:
131128
response = self.get("/applications/@me")
@@ -139,7 +136,7 @@ def upgrade_application_flags_if_necessary(self) -> bool:
139136
Returns a boolean defining whether changes were made.
140137
"""
141138
# Fetch first to modify, not overwrite
142-
current_flags = self.app_info.get("flags", 0)
139+
current_flags = self.get_app_info().get("flags", 0)
143140
new_flags = current_flags | 1 << 15 | 1 << 19
144141

145142
if new_flags != current_flags:
@@ -152,7 +149,7 @@ def upgrade_application_flags_if_necessary(self) -> bool:
152149
def check_if_in_guild(self) -> bool:
153150
"""Check if the bot is a member of the guild."""
154151
try:
155-
_ = self.guild_info
152+
self.get_guild_info()
156153
except HTTPStatusError as e:
157154
if e.response.status_code == 403 or e.response.status_code == 404:
158155
return False
@@ -165,7 +162,7 @@ def upgrade_server_to_community_if_necessary(
165162
announcements_channel_id: int | str,
166163
) -> bool:
167164
"""Fetches server info & upgrades to COMMUNITY if necessary."""
168-
payload = self.guild_info
165+
payload = self.get_guild_info()
169166

170167
if COMMUNITY_FEATURE not in payload["features"]:
171168
log.info("This server is currently not a community, upgrading.")
@@ -181,7 +178,7 @@ def get_all_roles(self) -> dict[str, int]:
181178
"""Fetches all the roles in a guild."""
182179
result = SilencedDict(name="Roles dictionary")
183180

184-
roles = self.guild_info["roles"]
181+
roles = self.get_guild_info()["roles"]
185182

186183
for role in roles:
187184
name = "_".join(part.lower() for part in role["name"].split(" ")).replace("-", "_")
@@ -196,7 +193,7 @@ def get_all_channels_and_categories(self) -> tuple[dict[str, str], dict[str, str
196193
channels = SilencedDict(name="Channels dictionary")
197194
categories = SilencedDict(name="Categories dictionary")
198195

199-
for channel in self.guild_channels:
196+
for channel in self.get_guild_channels():
200197
channel_type = channel["type"]
201198
name = "_".join(part.lower() for part in channel["name"].split(" ")).replace("-", "_")
202199
if re.match(off_topic_channel_name_regex, name):
@@ -297,7 +294,7 @@ def upgrade_client(self) -> bool:
297294
def check_guild_membership(self) -> None:
298295
"""Check the bot is in the required guild."""
299296
if not self.client.check_if_in_guild():
300-
client_id = self.client.app_info["id"]
297+
client_id = self.client.get_app_info()["id"]
301298
log.error("The bot is not a member of the configured guild with ID %s.", self.guild_id)
302299
log.warning(
303300
"Please invite with the following URL and rerun this script: "

0 commit comments

Comments
 (0)