Skip to content

Commit 9af9d12

Browse files
Merge main into add-msl-methods
2 parents b5b63c7 + 023cb70 commit 9af9d12

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

cogs/get_token_authorisation.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from utils import CommandChecks, TeXBotBaseCog
1313

1414
if TYPE_CHECKING:
15-
from collections.abc import Iterable, Mapping, Sequence
15+
from collections.abc import Collection, Mapping, Sequence
1616
from logging import Logger
1717
from typing import Final
1818

@@ -89,7 +89,7 @@ async def get_token_authorisation(self, ctx: "TeXBotApplicationContext") -> None
8989

9090
if profile_section_html is None:
9191
logger.warning(
92-
"Couldn't find the profile section of the user"
92+
"Couldn't find the profile section of the user "
9393
"when scraping the website's HTML!",
9494
)
9595
logger.debug("Retrieved HTML: %s", response_html)
@@ -116,17 +116,28 @@ async def get_token_authorisation(self, ctx: "TeXBotApplicationContext") -> None
116116

117117
if parsed_html is None or isinstance(parsed_html, bs4.NavigableString):
118118
NO_ADMIN_TABLE_MESSAGE: Final[str] = (
119-
f"Failed to retrieve the admin table for user: {user_name.string}."
119+
f"Failed to retrieve the admin table for user: {user_name.string}. "
120120
"Please check you have used the correct token!"
121121
)
122122
logger.warning(NO_ADMIN_TABLE_MESSAGE)
123123
await ctx.respond(content=NO_ADMIN_TABLE_MESSAGE)
124124
return
125125

126-
organisations: Iterable[str] = [
126+
organisations: Collection[str] = [
127127
list_item.get_text(strip=True) for list_item in parsed_html.find_all("li")
128128
]
129129

130+
if not organisations:
131+
logger.warning(
132+
(
133+
"Organisations list was unexpectedly empty "
134+
"for the admin access token associated with %s."
135+
),
136+
user_name.text,
137+
)
138+
await ctx.respond(content="Unexpectedly empty organisations error.")
139+
return
140+
130141
logger.debug(
131142
"Admin Token has admin access to: %s as user %s",
132143
organisations,
@@ -135,8 +146,8 @@ async def get_token_authorisation(self, ctx: "TeXBotApplicationContext") -> None
135146

136147
await ctx.respond(
137148
f"Admin token has access to the following MSL Organisations as "
138-
f"{user_name.text}:\n{
139-
', \n'.join(organisation for organisation in organisations)
149+
f"{user_name.text}:\n {
150+
', \n '.join(organisation for organisation in organisations)
140151
}",
141152
ephemeral=True,
142153
)

0 commit comments

Comments
 (0)