Skip to content

Commit

Permalink
Merge branch 'update_nextcord_version' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Rivixer committed Feb 8, 2024
2 parents 7246b44 + 685b6d3 commit 369ecbd
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 84 deletions.
Binary file modified requirements.txt
Binary file not shown.
4 changes: 2 additions & 2 deletions sggwbot/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from sggwbot.console import Console, FontColour
from sggwbot.errors import ExceptionData, UpdateEmbedError
from sggwbot.models import ControllerWithEmbed, EmbedModel, Model
from sggwbot.utils import InteractionUtils, MemberUtils, wait_until_midnight
from sggwbot.utils import InteractionUtils, wait_until_midnight

if TYPE_CHECKING:
from nextcord.embeds import Embed
Expand Down Expand Up @@ -873,7 +873,7 @@ async def callback(self, interaction: Interaction) -> None:
description, date, time, prefix, location
)

msg = f"{MemberUtils.convert_to_string(member)} "
msg = f"{member} "
match self.modal_type:
case EventModalType.ADD:
msg += "added a new event "
Expand Down
8 changes: 3 additions & 5 deletions sggwbot/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from sggwbot.console import Console, FontColour
from sggwbot.errors import AttachmentError
from sggwbot.utils import InteractionUtils, MemberUtils
from sggwbot.utils import InteractionUtils

if TYPE_CHECKING:
from sggw_bot import SGGWBot
Expand Down Expand Up @@ -48,19 +48,17 @@ async def _convert_attachment_to_embed(attachment: Attachment) -> Embed:

@commands.Cog.listener(name="on_message")
async def _on_message(self, message: nextcord.Message) -> None:
member_fullname = MemberUtils.convert_to_string(message.author)

if message.content != "":
Console.specific(
message.content,
f"{message.author.display_name}/{member_fullname}/{message.channel}",
f"{message.author.display_name}/{message.author}/{message.channel}",
FontColour.CYAN,
)
if message.attachments:
for attachment in message.attachments:
Console.specific(
attachment.url,
f"{message.author.display_name}/{member_fullname}/{message.channel}",
f"{message.author.display_name}/{message.author}/{message.channel}",
FontColour.CYAN,
)

Expand Down
19 changes: 6 additions & 13 deletions sggwbot/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from sggwbot.console import Console, FontColour
from sggwbot.errors import ExceptionData, RegistrationError
from sggwbot.models import Model
from sggwbot.utils import InteractionUtils, Matcher, MemberUtils, SmartDict
from sggwbot.utils import InteractionUtils, Matcher, SmartDict

if TYPE_CHECKING:
from nextcord.guild import Guild
Expand Down Expand Up @@ -793,12 +793,9 @@ def to_embed(self) -> Embed:
"""Converts the member data to an embed."""
member = self.member

member_info = MemberUtils.convert_to_string(member)
member_info += f" ({member.mention})"

embed = Embed(
title="User information:",
description=member_info,
description=f"{member} ({member.mention})",
colour=member.top_role.colour,
).set_thumbnail(
url=member.avatar.url if member.avatar else member.default_avatar.url
Expand Down Expand Up @@ -895,10 +892,9 @@ async def callback(self, interaction: Interaction) -> None:

member = interaction.user
assert isinstance(member, Member)
member_name = MemberUtils.convert_to_string(member)

Console.specific(
f"User {member_name} has subbited a registration request, "
f"User {member} has subbited a registration request, "
f"providing the following reason: {info_input.value}.",
"Registration",
FontColour.CYAN,
Expand All @@ -912,7 +908,7 @@ async def callback(self, interaction: Interaction) -> None:
description=member.mention,
color=Colour.blurple(),
)
.add_field(name="Name", value=member_name)
.add_field(name="Name", value=f"{member}")
.add_field(name="Reason", value=info_input.value, inline=False)
.add_field(name="ID", value=member.id, inline=False)
.set_thumbnail(
Expand Down Expand Up @@ -1056,15 +1052,14 @@ async def callback(self, interaction: Interaction) -> None:
member = self._member_data.member
index = self._member_data.index
bot_channel = self._bot.get_bot_channel()
member_name = MemberUtils.convert_to_string(member)

embed = (
Embed(
title="New registration!",
description=member.mention,
colour=Colour.fuchsia(),
)
.add_field(name="Name", value=member_name)
.add_field(name="Name", value=f"{member}")
.add_field(name="Index", value=index)
.add_field(name="ID", value=member.id, inline=False)
.set_thumbnail(
Expand Down Expand Up @@ -1187,10 +1182,8 @@ def _mail_text(self) -> MIMEText:
with open(path, "r", encoding="utf-8") as f:
text = f.read()

display_name = MemberUtils.convert_to_string(self._member)

text = (
text.replace("{{USER_DISPLAY_NAME}}", display_name)
text.replace("{{USER_DISPLAY_NAME}}", f"{self._member.display_name}")
.replace("{{REGISTRATION_CODE}}", self._code_model.code)
.replace("{{DISCORD_NAME}}", self._member.guild.name)
.replace("{{CODE_EXPIRATION}}", self._code_model.expire)
Expand Down
11 changes: 5 additions & 6 deletions sggwbot/role_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import json
from dataclasses import dataclass, field
from pathlib import Path
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Concatenate, ParamSpec
from typing import (TYPE_CHECKING, Any, Awaitable, Callable, Concatenate,
ParamSpec)

import nextcord
from nextcord.application_command import SlashOption
Expand All @@ -38,7 +39,7 @@

from sggwbot.errors import UpdateEmbedError
from sggwbot.models import ControllerWithEmbed, EmbedModel, Model
from sggwbot.utils import Console, FontColour, InteractionUtils, MemberUtils
from sggwbot.utils import Console, FontColour, InteractionUtils

if TYPE_CHECKING:
from nextcord.member import Member
Expand Down Expand Up @@ -285,15 +286,13 @@ async def change_role():
added_role = await controller.change_role(emoji, member)
if added_role is not None:
Console.specific(
f"{MemberUtils.convert_to_string(member)} "
f"changed their group to {added_role.name}.",
f"{member} changed their group to {added_role.name}.",
"roles",
colour=FontColour.GREEN,
)
else:
Console.specific(
f"{MemberUtils.convert_to_string(member)} "
f"reset {controller.model.identifier} roles.",
f"{member} reset {controller.model.identifier} roles.",
"roles",
colour=FontColour.GREEN,
)
Expand Down
28 changes: 1 addition & 27 deletions sggwbot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ async def wrapper(
command_name = InteractionUtils._command_name(interaction)
user: Member = interaction.user # type: ignore

user_info = f"{user.display_name} "
user_info += f"({MemberUtils.convert_to_string(user)})"
user_info = f"{user.display_name} ({user})"

kwargs_info = " ".join(
f"{k}:{v}" for k, v in kwargs.items() if v is not None
Expand Down Expand Up @@ -255,31 +254,6 @@ async def catch_error(exc: Exception, exc_data: ExceptionData) -> None:
return decorator


class MemberUtils(ABC): # pylint: disable=too-few-public-methods
"""A class containing utility methods for members."""

@staticmethod
def convert_to_string(member: Member | User) -> str:
"""Returns the name of a member with an optional discriminator,
if the member doesn't have a unique name.
Parameters
----------
member: :class:`nextcord.Member`
The member to get the name of.
Returns
-------
:class:`str`
The name of the member with an optional discriminator.
"""

name = member.name
if member.discriminator != "0":
name += f"#{member.discriminator}"
return name


class PathUtils(ABC): # pylint: disable=too-few-public-methods
"""A class containing utility methods for paths."""

Expand Down
7 changes: 6 additions & 1 deletion tests/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class AvatarMock:
class MemberMock:
name: str
nick: str
discriminator: str
id: int
roles: list[RoleMock]
discriminator: str | None = None
avatar: AvatarMock | None = None
_guild: GuildMock | None = None

Expand All @@ -72,6 +72,11 @@ def __post_init__(self) -> None:
if not self.roles:
self.roles = [DefaultRole()]

def __str__(self) -> str:
if self.discriminator:
return f"{self.name}#{self.discriminator}"
return self.name

def __hash__(self) -> int:
return self.id

Expand Down
30 changes: 0 additions & 30 deletions tests/test_member_utils.py

This file was deleted.

0 comments on commit 369ecbd

Please sign in to comment.