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, target_application_id: Optional[int] = None,
guest: bool = False, guest: bool = False,
roles: Optional[Sequence[Snowflake]] = None, roles: Optional[Sequence[Snowflake]] = None,
users: Optional[Sequence[Snowflake]] = None, target_users: Optional[Sequence[Snowflake]] = None,
) -> Invite: ) -> Invite:
"""|coro| """|coro|
@ -1334,7 +1334,7 @@ class GuildChannel:
assign roles with higher permissions than the bot. assign roles with higher permissions than the bot.
.. versionadded:: 2.7 .. 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. A list of users that are allowed to join via this invite.
Requires the :attr:`~discord.Permissions.manage_guild` permission. Requires the :attr:`~discord.Permissions.manage_guild` permission.
@ -1374,7 +1374,7 @@ class GuildChannel:
target_application_id=target_application_id, target_application_id=target_application_id,
flags=flags.value if flags else None, flags=flags.value if flags else None,
role_ids=[role.id for role in roles or []], 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) 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 typing import List, Optional, Sequence, Union, TYPE_CHECKING
from .asset import Asset 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 .object import Object
from .mixins import Hashable from .mixins import Hashable
from .enums import ( from .enums import (
@ -89,7 +89,7 @@ class InviteUsersJob:
The total number of users in the job. The total number of users in the job.
processed_users: :class:`int` processed_users: :class:`int`
The number of users that have been processed so far. 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. The time the job was created.
error_message: Optional[:class:`str`] error_message: Optional[:class:`str`]
The error message. The error message.
@ -654,7 +654,7 @@ class Invite(Hashable):
data = await self._state.http.delete_invite(self.code, reason=reason) data = await self._state.http.delete_invite(self.code, reason=reason)
return self.from_incomplete(state=self._state, data=data) 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| """|coro|
Fetches the users that are allowed to join via this invite. Fetches the users that are allowed to join via this invite.
@ -676,11 +676,10 @@ class Invite(Hashable):
Fetching the target users failed. Fetching the target users failed.
""" """
string = await self._state.http.get_invite_target_users(self.code) res = await self._state.http.get_invite_target_users(self.code)
users = string.lstrip('Users\n').split('\n') return _get_target_ids_from_csv(res)
return [int(user_id) for user_id in users if user_id]
async def fetch_target_users_job_status(self) -> InviteUsersJob: async def target_users_job_status(self) -> InviteUsersJob:
"""|coro| """|coro|
Fetches the status of the target users job for this invite. Fetches the status of the target users job for this invite.
@ -689,7 +688,7 @@ class Invite(Hashable):
Returns Returns
-------- --------
:class:`InviteJobStatus` :class:`InviteUsersJob`
The status of the target users job. The status of the target users job.
Raises Raises
@ -708,19 +707,24 @@ class Invite(Hashable):
async def edit( async def edit(
self, self,
*, *,
users: Sequence[Snowflake] = MISSING, target_users: Sequence[Snowflake] = MISSING,
) -> None: ) -> None:
"""|coro| """|coro|
Edits the invite. Edits the invite.
Requires the :attr:`~Permissions.manage_guild` permission.
Parameters Parameters
----------- -----------
users: List[:class:`~discord.abc.Snowflake`] users: List[:class:`~discord.abc.Snowflake`]
A list of users that should be able to use this invite. 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 Raises
------- -------
Forbidden Forbidden
@ -731,5 +735,5 @@ class Invite(Hashable):
Editing the invite failed. Editing the invite failed.
""" """
if users is not MISSING: if target_users:
await self._state.http.edit_invite_target_users(self.code, user_ids=[user.id for user in 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 array
import asyncio import asyncio
import csv
from textwrap import TextWrapper from textwrap import TextWrapper
from typing import ( from typing import (
Any, Any,
@ -1535,6 +1536,12 @@ def _format_call_duration(duration: datetime.timedelta) -> str:
return formatted 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: class _RawReprMixin:
__slots__: Tuple[str, ...] = () __slots__: Tuple[str, ...] = ()

Loading…
Cancel
Save