diff --git a/discord/guild.py b/discord/guild.py index bdd3bc1f20..489521ca8e 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3167,7 +3167,6 @@ def audit_logs( limit: int | None = 100, before: SnowflakeTime | None = None, after: SnowflakeTime | None = None, - oldest_first: bool | None = None, user: Snowflake = None, action: AuditLogAction = None, ) -> AuditLogIterator: @@ -3175,6 +3174,9 @@ def audit_logs( You must have the :attr:`~Permissions.view_audit_log` permission to use this. + See `gateway `_ + for more information about the `before` and `after` parameters. + Parameters ---------- limit: Optional[:class:`int`] @@ -3187,9 +3189,6 @@ def audit_logs( Retrieve entries after this date or entry. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. - oldest_first: :class:`bool` - If set to ``True``, return entries in oldest->newest order. Defaults to ``True`` if - ``after`` is specified, otherwise ``False``. user: :class:`abc.Snowflake` The moderator to filter entries from. action: :class:`AuditLogAction` @@ -3234,7 +3233,6 @@ def audit_logs( before=before, after=after, limit=limit, - oldest_first=oldest_first, user_id=user_id, action_type=action, ) diff --git a/discord/iterators.py b/discord/iterators.py index de442aa0fb..29e432328c 100644 --- a/discord/iterators.py +++ b/discord/iterators.py @@ -419,7 +419,6 @@ def __init__( limit=None, before=None, after=None, - oldest_first=None, user_id=None, action_type=None, ): @@ -428,7 +427,6 @@ def __init__( if isinstance(after, datetime.datetime): after = Object(id=time_snowflake(after, high=True)) - self.reverse = after is not None if oldest_first is None else oldest_first self.guild = guild self.loop = guild._state.loop self.request = guild._state.http.get_audit_logs @@ -444,46 +442,28 @@ def __init__( self.entries = asyncio.Queue() - if self.reverse: - self._strategy = self._after_strategy - if self.before: - self._filter = lambda m: int(m["id"]) < self.before.id - else: - self._strategy = self._before_strategy - if self.after and self.after != OLDEST_OBJECT: - self._filter = lambda m: int(m["id"]) > self.after.id + self._strategy = self._strategy_exec - async def _before_strategy(self, retrieve): + async def _strategy_exec(self, retrieve): before = self.before.id if self.before else None - data: AuditLogPayload = await self.request( - self.guild.id, - limit=retrieve, - user_id=self.user_id, - action_type=self.action_type, - before=before, - ) - - entries = data.get("audit_log_entries", []) - if len(data) and entries: - if self.limit is not None: - self.limit -= retrieve - self.before = Object(id=int(entries[-1]["id"])) - return data.get("users", []), entries - - async def _after_strategy(self, retrieve): after = self.after.id if self.after else None data: AuditLogPayload = await self.request( self.guild.id, limit=retrieve, user_id=self.user_id, action_type=self.action_type, + before=before, after=after, ) + entries = data.get("audit_log_entries", []) if len(data) and entries: if self.limit is not None: self.limit -= retrieve - self.after = Object(id=int(entries[0]["id"])) + if self.before or not self.after: + self.before = Object(id=int(entries[-1]["id"])) + if self.after or not self.before: + self.after = Object(id=int(entries[0]["id"])) return data.get("users", []), entries async def next(self) -> AuditLogEntry: @@ -512,8 +492,6 @@ async def _fill(self): if len(data) < 100: self.limit = 0 # terminate the infinite loop - if self.reverse: - data = reversed(data) if self._filter: data = filter(self._filter, data)