Browse Source

Do requested changes

Co-Authored-By: dolfies <[email protected]>
pull/10386/head
Soheab 5 months ago
parent
commit
a07ed32e9e
  1. 6
      discord/abc.py
  2. 30
      discord/invite.py
  3. 7
      discord/utils.py

6
discord/abc.py

@ -1284,7 +1284,7 @@ class GuildChannel:
target_application_id: Optional[int] = None,
guest: bool = False,
roles: Optional[Sequence[Snowflake]] = None,
users: Optional[Sequence[Snowflake]] = None,
target_users: Optional[Sequence[Snowflake]] = None,
) -> Invite:
"""|coro|
@ -1334,7 +1334,7 @@ class GuildChannel:
assign roles with higher permissions than the bot.
.. versionadded:: 2.7
users: Optional[Sequence[:class:`~discord.abc.Snowflake`]]
target_users: Optional[Sequence[:class:`~discord.abc.Snowflake`]]
A list of users that are allowed to join via this invite.
Requires the :attr:`~discord.Permissions.manage_guild` permission.
@ -1374,7 +1374,7 @@ class GuildChannel:
target_application_id=target_application_id,
flags=flags.value if flags else None,
role_ids=[role.id for role in roles or []],
user_ids=[user.id for user in users or []],
user_ids=[user.id for user in target_users or []],
)
return Invite.from_incomplete(data=data, state=self._state)

30
discord/invite.py

@ -26,7 +26,7 @@ from __future__ import annotations
from typing import List, Optional, Sequence, Union, TYPE_CHECKING
from .asset import Asset
from .utils import parse_time, snowflake_time, _get_as_snowflake, MISSING
from .utils import parse_time, snowflake_time, _get_as_snowflake, MISSING, _get_target_ids_from_csv
from .object import Object
from .mixins import Hashable
from .enums import (
@ -89,7 +89,7 @@ class InviteUsersJob:
The total number of users in the job.
processed_users: :class:`int`
The number of users that have been processed so far.
created_at: :class:`datetime.datetime`
created_at: Optional[:class:`datetime.datetime`]
The time the job was created.
error_message: Optional[:class:`str`]
The error message.
@ -654,7 +654,7 @@ class Invite(Hashable):
data = await self._state.http.delete_invite(self.code, reason=reason)
return self.from_incomplete(state=self._state, data=data)
async def fetch_target_users(self) -> list[int]:
async def target_users(self) -> list[int]:
"""|coro|
Fetches the users that are allowed to join via this invite.
@ -676,11 +676,10 @@ class Invite(Hashable):
Fetching the target users failed.
"""
string = await self._state.http.get_invite_target_users(self.code)
users = string.lstrip('Users\n').split('\n')
return [int(user_id) for user_id in users if user_id]
res = await self._state.http.get_invite_target_users(self.code)
return _get_target_ids_from_csv(res)
async def fetch_target_users_job_status(self) -> InviteUsersJob:
async def target_users_job_status(self) -> InviteUsersJob:
"""|coro|
Fetches the status of the target users job for this invite.
@ -689,7 +688,7 @@ class Invite(Hashable):
Returns
--------
:class:`InviteJobStatus`
:class:`InviteUsersJob`
The status of the target users job.
Raises
@ -708,19 +707,24 @@ class Invite(Hashable):
async def edit(
self,
*,
users: Sequence[Snowflake] = MISSING,
target_users: Sequence[Snowflake] = MISSING,
) -> None:
"""|coro|
Edits the invite.
Requires the :attr:`~Permissions.manage_guild` permission.
Parameters
-----------
users: List[:class:`~discord.abc.Snowflake`]
A list of users that should be able to use this invite.
Requires the :attr:`~Permissions.manage_guild` permission.
.. note::
You cannot clear the list of target users once set.
There must be at least one user in the list.
Raises
-------
Forbidden
@ -731,5 +735,5 @@ class Invite(Hashable):
Editing the invite failed.
"""
if users is not MISSING:
await self._state.http.edit_invite_target_users(self.code, user_ids=[user.id for user in users])
if target_users:
await self._state.http.edit_invite_target_users(self.code, user_ids=[user.id for user in target_users])

7
discord/utils.py

@ -26,6 +26,7 @@ from __future__ import annotations
import array
import asyncio
import csv
from textwrap import TextWrapper
from typing import (
Any,
@ -1535,6 +1536,12 @@ def _format_call_duration(duration: datetime.timedelta) -> str:
return formatted
def _get_target_ids_from_csv(res: str) -> List[int]:
reader = csv.reader(res.splitlines())
first_column = [row[0] for row in reader]
return [int(i) for i in first_column[1:]]
class _RawReprMixin:
__slots__: Tuple[str, ...] = ()

Loading…
Cancel
Save