Repository: Rapptz/discord.py
File: discord/guild.py (Python)

Code before:
        :class:`AuditLogEntry`
            The audit log entry.
        """

        async def _before_strategy(retrieve, before, limit):
            before_id = before.id if before else None
            data = await self._state.http.get_audit_logs(
                self.id, limit=retrieve, user_id=user_id, action_type=action, before=before_id
            )

            entries = data.get('audit_log_entries', [])

            if data and entries:
                if limit is not None:
                    limit -= len(data)

                before = Object(id=int(entries[-1]['id']))

            return (
                data.get('users', []),
                data.get('integrations', []),
                data.get('application_commands', []),
                entries,
                after,
                limit,
            )

        async def _after_strategy(retrieve, after, limit):
            after_id = after.id if after else None
            data = await self._state.http.get_audit_logs(
                self.id, limit=retrieve, user_id=user_id, action_type=action, after=after_id
            )

            entries = data.get('audit_log_entries', [])

            if data and entries:
                if limit is not None:
                    limit -= len(data)

                after = Object(id=int(entries[0]['id']))

            return (
                data.get('users', []),
                data.get('integrations', []),
                data.get('application_commands', []),
                entries,
                after,
                limit,
            )

        if user is not MISSING:

Review comment (refactor):
Maybe refactor this to only pass `data` and then handle the keys elsewhere.

Code after:
        :class:`AuditLogEntry`
            The audit log entry.
        """

        async def _before_strategy(retrieve, before, limit):
            before_id = before.id if before else None
            data = await self._state.http.get_audit_logs(
                self.id, limit=retrieve, user_id=user_id, action_type=action, before=before_id
            )

            entries = data.get('audit_log_entries', [])

            if data and entries:
                if limit is not None:
                    limit -= len(entries)

                before = Object(id=int(entries[-1]['id']))

            return data, entries, after, limit

        async def _after_strategy(retrieve, after, limit):
            after_id = after.id if after else None
            data = await self._state.http.get_audit_logs(
                self.id, limit=retrieve, user_id=user_id, action_type=action, after=after_id
            )

            entries = data.get('audit_log_entries', [])

            if data and entries:
                if limit is not None:
                    limit -= len(entries)

                after = Object(id=int(entries[0]['id']))

            return data, entries, after, limit

        if user is not MISSING:
            user_id = user.id
        else:
            user_id = None

        if action:
            action = action.value

        if isinstance(before, datetime.datetime):
            before = Object(id=utils.time_snowflake(before, high=False))
        if isinstance(after, datetime.datetime):
            after = Object(id=utils.time_snowflake(after, high=True))

        if oldest_first is MISSING:
            reverse = after is not MISSING