Search in sources :

Example 1 with AuditLog

use of sx.blah.discord.handle.audit.AuditLog in project Discord4J by Discord4J.

the class Guild method getAuditLog.

private AuditLog getAuditLog(IUser user, ActionType actionType, long before) {
    PermissionUtils.requirePermissions(this, client.getOurUser(), Permissions.VIEW_AUDIT_LOG);
    List<AuditLog> retrieved = new ArrayList<>();
    AuditLogEntryObject[] chunk;
    do {
        String query = "?limit=100&before=" + before;
        if (user != null)
            query += "&user_id=" + Long.toUnsignedString(user.getLongID());
        if (actionType != null)
            query += "&action_type=" + actionType.getRaw();
        AuditLogObject auditLog = ((DiscordClientImpl) client).REQUESTS.GET.makeRequest(DiscordEndpoints.GUILDS + getStringID() + "/audit-logs" + query, AuditLogObject.class);
        chunk = auditLog.audit_log_entries;
        if (chunk.length == 0)
            break;
        retrieved.add(DiscordUtils.getAuditLogFromJSON(this, auditLog));
        before = Long.parseLong(auditLog.audit_log_entries[auditLog.audit_log_entries.length - 1].id);
    } while (chunk.length == 100);
    return new AuditLog(retrieved.stream().map(AuditLog::getEntries).flatMap(Collection::stream).collect(LongMapCollector.toLongMap()));
}
Also used : AuditLogEntryObject(sx.blah.discord.api.internal.json.objects.audit.AuditLogEntryObject) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DiscordClientImpl(sx.blah.discord.api.internal.DiscordClientImpl) AuditLog(sx.blah.discord.handle.audit.AuditLog) AuditLogObject(sx.blah.discord.api.internal.json.objects.audit.AuditLogObject)

Aggregations

CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 DiscordClientImpl (sx.blah.discord.api.internal.DiscordClientImpl)1 AuditLogEntryObject (sx.blah.discord.api.internal.json.objects.audit.AuditLogEntryObject)1 AuditLogObject (sx.blah.discord.api.internal.json.objects.audit.AuditLogObject)1 AuditLog (sx.blah.discord.handle.audit.AuditLog)1