Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
ecaf49c
initial work
MattyTheHacker Dec 19, 2024
cc9c12a
bump deps
MattyTheHacker Dec 19, 2024
19976d0
kinda works
MattyTheHacker Dec 19, 2024
360390d
extract functionality to method
MattyTheHacker Dec 20, 2024
28ea9e3
Finalise
MattyTheHacker Dec 20, 2024
b6b6f94
yeet unreachable
MattyTheHacker Dec 20, 2024
f504402
roll back lock file
MattyTheHacker Dec 20, 2024
2eda160
fix ruff warning
MattyTheHacker Dec 20, 2024
a43795c
Add extra try catch just in case.
MattyTheHacker Dec 22, 2024
1cfea65
Merge branch 'main' into threads-with-friends
MattyTheHacker Dec 22, 2024
2c5cee3
Merge branch 'main' into threads-with-friends
MattyTheHacker Jan 1, 2025
ac11a25
Merge branch 'main' into threads-with-friends
MattyTheHacker Jan 1, 2025
219ad1d
Merge branch 'main' into threads-with-friends
MattyTheHacker Jan 2, 2025
134a43d
fix lock file
MattyTheHacker Jan 2, 2025
5d315fc
refactor to make 2 separate commands
MattyTheHacker Jan 2, 2025
6c137f4
add committee lock
MattyTheHacker Jan 2, 2025
5d585e6
Merge branch 'main' into threads-with-friends
MattyTheHacker Jan 2, 2025
7658c9a
Merge branch 'main' into threads-with-friends
MattyTheHacker Jan 2, 2025
5cdfcdc
on todays episode of scope creep !
MattyTheHacker Jan 6, 2025
8eb19fd
Bump python project action version
MattyTheHacker Jan 6, 2025
f6796a5
Update tests.yaml
MattyTheHacker Jan 6, 2025
ce291f9
Merge branch 'bump-action-version' into threads-with-friends
MattyTheHacker Jan 6, 2025
1c8d21b
update deps
MattyTheHacker Jan 23, 2025
fe9c31f
Merge branch 'main' into threads-with-friends
MattyTheHacker Jan 23, 2025
386282f
lock
MattyTheHacker Jan 23, 2025
3a87d23
Merge branch 'main' into threads-with-friends
MattyTheHacker Jan 27, 2025
fc5db72
lock
MattyTheHacker Jan 27, 2025
81347d3
Implement check for @ symbol
MattyTheHacker Mar 1, 2025
2bf3294
Merge branch 'main' into threads-with-friends
MattyTheHacker Mar 1, 2025
d88b5f2
Add config option to disable adding committee to threads
MattyTheHacker Mar 1, 2025
8481b1f
Merge branch 'main' into threads-with-friends
MattyTheHacker Mar 1, 2025
c047597
Merge branch 'main' into threads-with-friends
MattyTheHacker Mar 2, 2025
8dda974
Rename file
MattyTheHacker Mar 2, 2025
e8d47e7
Merge branch 'main' into threads-with-friends
MattyTheHacker Mar 4, 2025
f253b8b
suck my cunt pre commit f*ck off
MattyTheHacker Mar 4, 2025
4cbaa2e
fix
MattyTheHacker Mar 4, 2025
b559f0f
Fix mypy errors AGAIN BECAUSE THE PRE-COMMIT FUCKED IT
MattyTheHacker Mar 4, 2025
a8546e7
Refactor the separate commands for role and user to one
MattyTheHacker Mar 4, 2025
38b88e2
Fix new lines
MattyTheHacker Mar 4, 2025
dcedbf3
Ruff format
MattyTheHacker Mar 4, 2025
933e462
Remove doc string from private method
MattyTheHacker Mar 4, 2025
c5785af
Merge branch 'main' into threads-with-friends
MattyTheHacker Mar 5, 2025
df53007
Implement multiple roles and users adding at once
MattyTheHacker Mar 5, 2025
c5aa18d
Merge branch 'threads-with-friends' of github.com:CSSUoB/TeX-Bot-Py-V…
MattyTheHacker Mar 5, 2025
76a0729
Fix parameter names
MattyTheHacker Mar 5, 2025
54cab7d
Fix bad logic
MattyTheHacker Mar 5, 2025
fabc7a8
Update committee role syntax
MattyTheHacker Mar 6, 2025
6b3d090
Merge branch 'main' into threads-with-friends
MattyTheHacker Mar 17, 2025
02d48fe
Merge branch 'main' into threads-with-friends
MattyTheHacker Mar 18, 2025
d33d3f2
Merge branch 'main' into threads-with-friends
MattyTheHacker Mar 30, 2025
c95eb91
Fixes
MattyTheHacker Mar 30, 2025
dd9ad81
Improve logic
MattyTheHacker Mar 30, 2025
c69ea0c
use ctx.channel directly
MattyTheHacker Mar 30, 2025
2c7fc5c
Update config.py
MattyTheHacker Mar 30, 2025
c2669ea
Update cogs/add_users_to_threads_and_channels.py
MattyTheHacker Mar 30, 2025
22aab60
Fix method call
MattyTheHacker Mar 30, 2025
bab4957
improve method flow
MattyTheHacker Mar 31, 2025
e07c5c8
fix mypy errors
MattyTheHacker Mar 31, 2025
d600493
Merge branch 'main' into threads-with-friends
MattyTheHacker Mar 31, 2025
1cd8418
fix bad loop exit logic
MattyTheHacker Mar 31, 2025
e537f75
Update cogs/add_users_to_threads_and_channels.py
MattyTheHacker Mar 31, 2025
2dadbbe
Update cogs/add_users_to_threads_and_channels.py
MattyTheHacker Mar 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from .source import SourceCommandCog
from .startup import StartupCog
from .stats import StatsCommandsCog
from .strike import ManualModerationCog, StrikeCommandCog, StrikeUserCommandCog
from .strike import ManualModerationCog, StrikeCommandCog, StrikeContextCommandsCog
from .thread_friends import AddUsersToThreadsCog
from .write_roles import WriteRolesCommandCog

Expand Down
105 changes: 69 additions & 36 deletions cogs/thread_friends.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import discord

from exceptions import GuestRoleDoesNotExistError, GuildDoesNotExistError
from utils import TeXBotBaseCog
from utils import CommandChecks, TeXBotBaseCog
from utils.error_capture_decorators import capture_guild_does_not_exist_error

if TYPE_CHECKING:
Expand All @@ -28,35 +28,31 @@ class AddUsersToThreadsCog(TeXBotBaseCog):
"""Cog for adding users to threads."""

@staticmethod
async def autocomplete_get_members_and_roles(ctx: "TeXBotAutocompleteContext") -> "AbstractSet[discord.OptionChoice] | AbstractSet[str]": # noqa: E501
"""
Autocomplete callable that generates the set of available selectable members.

This list of selectable members is used in any of the "induct" slash-command options
that have a member input-type.
"""
async def autocomplete_get_members(ctx: "TeXBotAutocompleteContext") -> "AbstractSet[discord.OptionChoice] | AbstractSet[str]": # noqa: E501
"""Autocomplete callable that generates the set of available selectable members."""
try:
main_guild: discord.Guild = ctx.bot.main_guild
guest_role: discord.Role = await ctx.bot.guest_role
except (GuildDoesNotExistError, GuestRoleDoesNotExistError):
return set()

members: set[discord.Member | discord.Role] = {
member
return {
discord.OptionChoice(name=member.name, value=str(member.id))
for member in main_guild.members
if not member.bot and guest_role in member.roles
}
Comment thread
MattyTheHacker marked this conversation as resolved.
Outdated

members.update(main_guild.roles)

if not ctx.value or ctx.value.startswith("@"):
return {
discord.OptionChoice(name=f"@{member.name}", value=str(member.id))
for member in members
}
@staticmethod
async def autocomplete_get_roles(ctx: "TeXBotAutocompleteContext") -> "AbstractSet[discord.OptionChoice] | AbstractSet[str]": # noqa: E501
"""Autocomplete callable that generates the set of available selectable roles."""
try:
main_guild: discord.Guild = ctx.bot.main_guild
except GuildDoesNotExistError:
return set()

return {
discord.OptionChoice(name=member.name, value=str(member.id)) for member in members
discord.OptionChoice(name=role.name, value=str(role.id))
for role in main_guild.roles
}
Comment thread
MattyTheHacker marked this conversation as resolved.
Outdated

async def add_user_or_role_silently(self, user_or_role: discord.Member | discord.Role, thread: discord.Thread) -> None: # noqa: E501
Expand Down Expand Up @@ -119,10 +115,10 @@ async def on_thread_create(self, thread: discord.Thread) -> None:
description="Adds selected users to a thread.",
)
@discord.option( # type: ignore[no-untyped-call, misc]
name="user_or_role",
description="The user or role to add to the thread.",
name="user",
description="The user to add to the thread.",
input_type=str,
autocomplete=discord.utils.basic_autocomplete(autocomplete_get_members_and_roles), # type: ignore[arg-type]
autocomplete=discord.utils.basic_autocomplete(autocomplete_get_members), # type: ignore[arg-type]
required=True,
parameter_name="user_or_role",
)
Expand All @@ -133,10 +129,10 @@ async def on_thread_create(self, thread: discord.Thread) -> None:
required=False,
parameter_name="silent",
)
async def add_users_to_thread(self, ctx: "TeXBotApplicationContext", user_or_role: str, silent: bool) -> None: # noqa: E501, FBT001
@CommandChecks.check_interaction_user_has_committee_role
@CommandChecks.check_interaction_user_in_main_guild
async def add_user_to_thread(self, ctx: "TeXBotApplicationContext", user_id_str: str, silent: bool) -> None: # noqa: E501, FBT001
"""Add users or roles to a thread."""
main_guild: discord.Guild = ctx.bot.main_guild

if not isinstance(ctx.channel, discord.Thread):
await self.command_send_error(
ctx=ctx,
Expand All @@ -147,32 +143,68 @@ async def add_users_to_thread(self, ctx: "TeXBotApplicationContext", user_or_rol
thread: discord.Thread = ctx.channel

try:
user_object: discord.Member = await self.bot.get_member_from_str_id(user_or_role)
user_to_add: discord.Member = await self.bot.get_member_from_str_id(user_id_str)
except ValueError:
pass
logger.debug("User ID: %s is not a valid ID.", user_id_str)
await ctx.respond(content=f"The user: {user_id_str} is not valid.")
return

if silent:
await self.add_user_or_role_silently(user_to_add, thread)
else:
if silent:
await self.add_user_or_role_silently(user_object, thread)
else:
await self.add_user_or_role_with_ping(user_object, thread)
await self.add_user_or_role_with_ping(user_to_add, thread)

await ctx.respond(
content=f"User {user_to_add.mention} has been added to the thread.",
ephemeral=True,
)

@discord.slash_command( # type: ignore[no-untyped-call, misc]
name="add_role_to_thread",
description="Adds the selected role and it's users to a thread.",
)
@discord.option( # type: ignore[no-untyped-call, misc]
name="role",
description="The role to add to the thread.",
input_type=str,
autocomplete=discord.utils.basic_autocomplete(autocomplete_get_roles), # type: ignore[arg-type]
required=True,
parameter_name="user_or_role",
)
@discord.option( # type: ignore[no-untyped-call, misc]
name="silent",
description="Whether the users being added should be pinged or not.",
input_type=bool,
required=False,
parameter_name="silent",
)
@CommandChecks.check_interaction_user_has_committee_role
@CommandChecks.check_interaction_user_in_main_guild
async def add_role_to_thread(self, ctx: "TeXBotApplicationContext", user_or_role: str, silent: bool) -> None: # noqa: E501, FBT001
"""Add users or roles to a thread."""
main_guild: discord.Guild = ctx.bot.main_guild

await ctx.respond(
content=f"User {user_object.mention} has been added to the thread."
if not isinstance(ctx.channel, discord.Thread):
await self.command_send_error(
ctx=ctx,
message="This command can only be used in a thread.",
)
return

thread: discord.Thread = ctx.channel

try:
role_id: int = int(user_or_role)
except ValueError:
logger.debug("Role or User ID: %s is not a valid ID.", user_or_role)
await ctx.respond(content=f"The role or user: {user_or_role} is not valid.")
logger.debug("Role ID: %s is not a valid ID.", user_or_role)
await ctx.respond(content=f"The role: {user_or_role} is not valid.")
return

role_object: discord.Role | None = discord.utils.get(main_guild.roles, id=role_id)
if role_object is None:
await self.command_send_error(
ctx=ctx,
message=f"The role or user: <@{role_id}> is not valid or couldn't be found.",
message=f"The role: <@{role_id}> is not valid or couldn't be found.",
)
return

Expand All @@ -182,5 +214,6 @@ async def add_users_to_thread(self, ctx: "TeXBotApplicationContext", user_or_rol
await self.add_user_or_role_with_ping(role_object, thread)

await ctx.respond(
content=f"Role {role_object.mention} has been added to the thread."
content=f"Role {role_object.mention} has been added to the thread.",
ephemeral=True,
)
Loading