Skip to content

Commit

Permalink
Merge branch 'hotfix' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Rivixer committed Mar 16, 2023
2 parents 45a78fb + cc8ad0a commit a40ef23
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 23 deletions.
2 changes: 1 addition & 1 deletion sggwbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
__author__ = "Wiktor Jaworski"
__license__ = "MIT"
__copyright__ = "Copyright 2023 Wiktor Jaworski"
__version__ = "0.6.0"
__version__ = "0.6.1"
8 changes: 4 additions & 4 deletions sggwbot/assigning_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def _assigning_roles(self, *_) -> None:
after="The assigning_roles embed has been sent.",
catch_errors=True,
)
@InteractionUtils.with_log()
@InteractionUtils.with_log(show_channel=True)
async def _send(self, interaction: Interaction) -> None:
"""Sends a new assigning_roles embed.
Expand All @@ -103,7 +103,7 @@ async def _send(self, interaction: Interaction) -> None:
catch_errors=True,
additional_errors=[UpdateEmbedError],
)
@InteractionUtils.with_log(show_channel=True)
@InteractionUtils.with_log()
async def _update(
self, interaction: Interaction # pylint: disable=unused-argument
) -> None:
Expand All @@ -129,7 +129,7 @@ async def _update(
before="Getting assigning_roles embed json...",
catch_errors=True,
)
@InteractionUtils.with_log(show_channel=True)
@InteractionUtils.with_log()
async def _get_json(self, interaction: Interaction) -> None:
"""Gets the json file representing the assigning_roles embed.
Expand All @@ -151,7 +151,7 @@ async def _get_json(self, interaction: Interaction) -> None:
catch_errors=True,
additional_errors=[UpdateEmbedError],
)
@InteractionUtils.with_log(show_channel=True)
@InteractionUtils.with_log()
async def _set_json(
self,
interaction: Interaction, # pylint: disable=unused-argument
Expand Down
8 changes: 4 additions & 4 deletions sggwbot/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def _calendar(self, *_) -> None:
after="The calendar embed has been sent.",
catch_errors=True,
)
@InteractionUtils.with_log()
@InteractionUtils.with_log(show_channel=True)
async def _send(self, interaction: Interaction) -> None:
"""Sends a new calendar embed.
Expand All @@ -92,7 +92,7 @@ async def _send(self, interaction: Interaction) -> None:
catch_errors=True,
additional_errors=[UpdateEmbedError],
)
@InteractionUtils.with_log(show_channel=True)
@InteractionUtils.with_log()
async def _update(
self, interaction: Interaction # pylint: disable=unused-argument
) -> None:
Expand All @@ -118,7 +118,7 @@ async def _update(
before="Getting calendar embed json...",
catch_errors=True,
)
@InteractionUtils.with_log(show_channel=True)
@InteractionUtils.with_log()
async def _get_json(self, interaction: Interaction) -> None:
"""Gets the json file representing the calendar embed.
Expand All @@ -140,7 +140,7 @@ async def _get_json(self, interaction: Interaction) -> None:
catch_errors=True,
additional_errors=[UpdateEmbedError],
)
@InteractionUtils.with_log(show_channel=True)
@InteractionUtils.with_log()
async def _set_json(
self,
_: Interaction,
Expand Down
8 changes: 4 additions & 4 deletions sggwbot/information.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def _information(self, *_) -> None:
after="The information embed has been sent.",
catch_errors=True,
)
@InteractionUtils.with_log()
@InteractionUtils.with_log(show_channel=True)
async def _send(self, interaction: Interaction) -> None:
"""Sends a new information embed.
Expand All @@ -85,7 +85,7 @@ async def _send(self, interaction: Interaction) -> None:
catch_errors=True,
additional_errors=[UpdateEmbedError],
)
@InteractionUtils.with_log(show_channel=True)
@InteractionUtils.with_log()
async def _update(
self, interaction: Interaction # pylint: disable=unused-argument
) -> None:
Expand All @@ -111,7 +111,7 @@ async def _update(
before="Getting information embed json...",
catch_errors=True,
)
@InteractionUtils.with_log(show_channel=True)
@InteractionUtils.with_log()
async def _get_json(self, interaction: Interaction) -> None:
"""Gets the json file representing the information embed.
Expand All @@ -133,7 +133,7 @@ async def _get_json(self, interaction: Interaction) -> None:
catch_errors=True,
additional_errors=[UpdateEmbedError],
)
@InteractionUtils.with_log(show_channel=True)
@InteractionUtils.with_log()
async def _set_json(
self,
interaction: Interaction, # pylint: disable=unused-argument
Expand Down
46 changes: 44 additions & 2 deletions sggwbot/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from nextcord.message import Attachment, MessageReference

from .console import Console, FontColour
from .errors import AttachmentError
from .errors import AttachmentError, SGGWBotError
from .utils import InteractionUtils

if TYPE_CHECKING:
Expand Down Expand Up @@ -248,7 +248,7 @@ async def _remove(

@_message.subcommand(
name="add_reaction",
description="Add a reaction to a message sent by the bot.",
description="Add a reaction to a message.",
)
@InteractionUtils.with_info(
before="Adding the reaction... {emoji}",
Expand Down Expand Up @@ -276,6 +276,48 @@ async def _add_reaction(

await message.add_reaction(emoji)

@_message.subcommand(
name="add_reactions",
description="Add reactions to a message.",
)
@InteractionUtils.with_info(
before="Adding reactions... {emojis}",
after="Reactions {emojis} have been added.",
catch_errors=True,
additional_errors=[SGGWBotError],
)
@InteractionUtils.with_log(show_channel=True)
async def _add_reactions(
self,
interaction: Interaction,
message_id: str = SlashOption(
description="The ID of the message to add the reaction to.",
required=True,
),
emojis: str = SlashOption(
description="The emojis to add separated by a space.",
required=True,
),
) -> None:
channel = interaction.channel
if not isinstance(channel, TextChannel):
raise ValueError("Cannot edit messages in non-text channels")

message = await channel.fetch_message(int(message_id))

emojis_to_add = emojis.split(" ")
unadded_emojis: dict[str, nextcord.DiscordException] = {}

for emoji in emojis_to_add:
try:
await message.add_reaction(emoji)
except nextcord.DiscordException as e:
unadded_emojis[emoji] = e

if unadded_emojis:
reason = "\n".join(f"{emoji}: {e}" for emoji, e in unadded_emojis.items())
raise SGGWBotError(f"Could not add the following emojis:\n{reason}")

@_message.subcommand(
name="remove_reaction",
description="Remove a reaction from a message sent by the bot.",
Expand Down
8 changes: 4 additions & 4 deletions sggwbot/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def _project(self, *_) -> None:
after="The project embed has been sent.",
catch_errors=True,
)
@InteractionUtils.with_log()
@InteractionUtils.with_log(show_channel=True)
async def _send(self, interaction: Interaction) -> None:
"""Sends a new project embed.
Expand All @@ -97,7 +97,7 @@ async def _send(self, interaction: Interaction) -> None:
catch_errors=True,
additional_errors=[UpdateEmbedError],
)
@InteractionUtils.with_log(show_channel=True)
@InteractionUtils.with_log()
async def _update(
self, interaction: Interaction # pylint: disable=unused-argument
) -> None:
Expand All @@ -123,7 +123,7 @@ async def _update(
before="Getting project embed json...",
catch_errors=True,
)
@InteractionUtils.with_log(show_channel=True)
@InteractionUtils.with_log()
async def _get_json(self, interaction: Interaction) -> None:
"""Gets the json file representing the project embed.
Expand All @@ -145,7 +145,7 @@ async def _get_json(self, interaction: Interaction) -> None:
catch_errors=True,
additional_errors=[UpdateEmbedError],
)
@InteractionUtils.with_log(show_channel=True)
@InteractionUtils.with_log()
async def _set_json(
self,
interaction: Interaction, # pylint: disable=unused-argument
Expand Down
8 changes: 4 additions & 4 deletions sggwbot/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ async def _register(

@nextcord.slash_command(
name="whois",
description="Shows information about a member.",
description="Show information about a member.",
)
@InteractionUtils.with_info(catch_errors=True)
@InteractionUtils.with_log()
async def _whois(
self,
interaction: Interaction,
argument: str = SlashOption(
description="Member's ID, name, surname, index or nick."
description="Member's ID, first name, last name, index or nick."
),
) -> None:
matching_members = self._model.find_matching_members(argument)
Expand Down Expand Up @@ -871,7 +871,7 @@ async def callback(self, interaction: Interaction) -> None:
)
.add_field(name="Name", value=f"{member.name}#{member.discriminator}")
.add_field(name="Nick", value=member.display_name)
.add_field(name="Indeks", value=index)
.add_field(name="Index", value=index)
.add_field(name="ID", value=member.id)
.set_thumbnail(
url=member.avatar.url if member.avatar else member.default_avatar.url
Expand Down Expand Up @@ -1017,7 +1017,7 @@ def __exit__(self, *_) -> None:
pass

async def send_mail(self) -> None:
"""|coro"
"""|coro|
Sends an email with a code.
Expand Down
1 change: 1 addition & 0 deletions tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def test_member_info_to_embed(member1: MemberMock) -> None:
value="Last",
)
.add_field(name="StudentID", value="123456")
.add_field(name="ID", value=member1.id, inline=False)
.add_field(name="Roles", value="<@&456>, <@&123>", inline=False)
.set_thumbnail(url="link.png")
)
Expand Down

0 comments on commit a40ef23

Please sign in to comment.