Skip to content

Commit 6eef79a

Browse files
committed
fix: amend issues found in testing
1 parent 402f5d1 commit 6eef79a

8 files changed

Lines changed: 198 additions & 178 deletions

File tree

fred/fred_commands/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ async def handle_docsearch(
230230
self,
231231
ctx_or_interaction: commands.Context | Interaction,
232232
search: str,
233-
ephemeral: bool = False,
233+
ephemeral: bool,
234234
) -> None:
235235
self.logger.info(f"Searching the documentation. {search =}")
236236
client: SearchClient = SearchClient("2FDCZBLZ1A", "28531804beda52a04275ecd964db429d")

fred/fred_commands/bot_meta.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import TYPE_CHECKING
44

5-
from nextcord import Interaction, SlashOption, slash_command
5+
from nextcord import Interaction, SlashOption, slash_command, Emoji
66
from nextcord.ext import application_checks
77

88
from ._baseclass import BaseCmds, commands, config, common
@@ -61,11 +61,13 @@ async def set_latest_info(self, ctx: commands.Context, latest_info: str):
6161
async def get_welcome(self, ctx: commands.Context):
6262
bot: Bot = ctx.bot
6363
await bot.Welcome.send_welcome_message(ctx.author)
64+
await ctx.message.add_reaction("👍")
6465

6566
@BaseCmds.slash_get.subcommand(name="welcome", description="Sends the welcome message to you.")
6667
@application_checks.check(common.l4_only)
6768
async def get_welcome_slash(self, interaction: Interaction):
6869
await self.bot.Welcome.send_welcome_message(interaction.user)
70+
await interaction.send("The current welcome message has been sent to you!", ephemeral=True)
6971

7072
# Set Main Guild Command
7173
@commands.check(common.mod_only)

fred/fred_commands/experience.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ async def leaderboard_handler(self, ctx_or_interaction, ephemeral: bool) -> None
163163
data = []
164164
for db_user in results:
165165
fetched_user = self.bot.get_user(db_user.user_id)
166-
if fetched_user is None:
167-
raise LookupError(f"Unable to find user with ID {db_user.user_id}")
166+
# if fetched_user is None:
167+
# raise LookupError(f"Unable to find user with ID {db_user.user_id}")
168168
data.append(
169169
{
170-
"name": fetched_user.global_name,
170+
"name": fetched_user and fetched_user.global_name or f"[{db_user.user_id}]",
171171
"xp": db_user.xp_count,
172172
"rank": db_user.rank,
173173
}
@@ -200,6 +200,7 @@ async def leaderboard_slash(
200200
async def handle_level(
201201
self,
202202
ctx_or_interaction: commands.Context | Interaction,
203+
*,
203204
ephemeral: bool,
204205
target_user: User = None,
205206
) -> None:
@@ -243,7 +244,7 @@ async def level(self, ctx: commands.Context, target_user: commands.UserConverter
243244
Response: Either your level or the level of the user specified
244245
Notes: the user parameter can be the user's @ mention or their UID, like 506192269557366805
245246
"""
246-
await self.handle_level(ctx, target_user, ephemeral=False)
247+
await self.handle_level(ctx, target_user=target_user, ephemeral=False)
247248

248249
@nextcord.slash_command(
249250
name="level",
@@ -255,7 +256,7 @@ async def level_slash(
255256
target_user: User = SlashOption(description="The user to get the level of", required=False),
256257
ephemeral: bool = SlashOption(description="Only you can see the response", default=True),
257258
):
258-
await self.handle_level(interaction, target_user, ephemeral=ephemeral)
259+
await self.handle_level(interaction, target_user=target_user, ephemeral=ephemeral)
259260

260261
@BaseCmds.add.command(name="level_role")
261262
async def add_level_role(self, ctx: commands.Context, role: commands.RoleConverter, rank: int):

fred/fred_commands/help.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def media_only(cls: Type[FredHelpEmbed]) -> FredHelpEmbed:
326326
for chan in config.MediaOnlyChannels.selectBy():
327327
desc += f"- <#{chan.channel_id}>\n"
328328

329-
desc += "\n*All other messages will get deleted (if it doesn't, I might be down :( )*"
329+
desc += "\n*All other messages will get deleted (if not, I might be down :( )*"
330330

331331
return cls("Media-Only Channels", desc, usage="media_only")
332332

@@ -390,5 +390,5 @@ def commands(cls: Type[FredHelpEmbed], index: int = 0) -> FredHelpEmbed:
390390
return cls(title, desc, usage="commands [page]")
391391

392392
except IndexError:
393-
desc = f"There aren't that many commands! Try a number less than {index}."
393+
desc = f"There aren't that many commands! Try Fga number less than {index}."
394394
return cls(title, desc, usage="commands [page]")

fred/libraries/common.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from io import BytesIO
66
from typing import TYPE_CHECKING, Optional
77

8-
from nextcord import User, Message, Member, Guild, NotFound, File
8+
from nextcord import User, Message, Member, Guild, NotFound, File, Interaction
99
from nextcord.ext import commands
1010
from nextcord.ext.commands import Context
1111
from uwuipy import Uwuipy
@@ -43,28 +43,42 @@ async def get_guild_member(guild: Guild, user_id: int) -> Optional[Member]:
4343
return None
4444

4545

46-
def is_bot_author(user_id: int) -> bool:
47-
logger.info("Checking if someone is the author", extra={"user_id": user_id})
48-
return user_id == 227473074616795137
46+
async def l4_only(ctx: Context | Interaction) -> bool:
47+
return await permission_check(ctx, level=4)
4948

5049

51-
async def l4_only(ctx: Context) -> bool:
52-
logger.info("Checking if someone is a T3", extra=user_info(ctx.author))
53-
return is_bot_author(ctx.author.id) or await permission_check(ctx, level=4)
54-
55-
56-
async def mod_only(ctx: Context) -> bool:
57-
logger.info("Checking if someone is a Moderator", extra=user_info(ctx.author))
58-
return is_bot_author(ctx.author.id) or await permission_check(ctx, level=6)
50+
async def mod_only(ctx: Context | Interaction) -> bool:
51+
return await permission_check(ctx, level=6)
5952

6053

6154
@singledispatch
6255
async def permission_check(_ctx_or_member, *, level: int) -> bool: ...
6356

6457

58+
@permission_check.register
59+
async def _permission_check_itr(itr: Interaction, *, level: int) -> bool:
60+
logger.info(f"Checking if a user (from an Interaction) has permission level {level}", extra=user_info(itr.user))
61+
main_guild_id = config.Misc.fetch("main_guild_id")
62+
main_guild = await itr.client.fetch_guild(main_guild_id)
63+
64+
if main_guild is None:
65+
raise LookupError(f"Unable to retrieve the guild {main_guild_id}. Is this the guild you meant?")
66+
67+
if (main_guild_member := await get_guild_member(main_guild, itr.user.id)) is None:
68+
logger.warning(
69+
"Checked permissions for someone but they weren't in the main guild",
70+
extra=user_info(itr.user),
71+
)
72+
return False
73+
74+
return await _permission_check_member(main_guild_member, threshold_level=level)
75+
76+
6577
@permission_check.register
6678
async def _permission_check_ctx(ctx: Context, *, level: int) -> bool:
6779

80+
logger.info(f"Checking if a user (from a Context) has permission level {level}", extra=user_info(ctx.author))
81+
6882
main_guild_id = config.Misc.fetch("main_guild_id")
6983
main_guild = await ctx.bot.fetch_guild(main_guild_id)
7084

@@ -84,6 +98,9 @@ async def _permission_check_ctx(ctx: Context, *, level: int) -> bool:
8498
@permission_check.register
8599
async def _permission_check_member(member: Member, *, threshold_level: int) -> bool:
86100
"""Checks permissions for a member assuming they are in the main guild."""
101+
102+
logger.info(f"Checking if a user (from a Member) has permission level {threshold_level}", extra=user_info(member))
103+
87104
logpayload = user_info(member)
88105
logpayload["level"] = threshold_level
89106

@@ -96,8 +113,8 @@ async def _permission_check_member(member: Member, *, threshold_level: int) -> b
96113
extra=logpayload,
97114
)
98115

99-
perm_roles = config.PermissionRoles.fetch_ge_lvl(threshold_level)
100116
user_roles = {role.id for role in member.roles}
117+
perm_roles = config.PermissionRoles.fetch_ge_lvl(threshold_level)
101118
user_roles_above_threshold = {role for role in perm_roles if role.role_id in user_roles}
102119

103120
if user_roles_above_threshold:

fred/libraries/createembed.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ def format_commit(commit: dict) -> tuple[str, str]:
101101
f'{change_summary_icons} - by {attribution} {ts} [{hash_id}]({commit["url"]})\n',
102102
)
103103

104+
104105
def _append_legend_footer(embed: nextcord.Embed) -> None:
105106
embed.set_footer(text="Use the `" + config.Misc.fetch("prefix") + "legend` to learn what the icons mean!")
106107

108+
107109
# data format: https://docs.github.com/en/webhooks/webhook-events-and-payloads#push
108110
def push(data: dict) -> nextcord.Embed:
109111
if data["forced"]:

0 commit comments

Comments
 (0)