Search in sources :

Example 1 with ActionType

use of net.dv8tion.jda.api.audit.ActionType in project JDA by DV8FromTheWorld.

the class EntityBuilder method createAuditLogEntry.

public AuditLogEntry createAuditLogEntry(GuildImpl guild, DataObject entryJson, DataObject userJson, DataObject webhookJson) {
    final long targetId = entryJson.getLong("target_id", 0);
    final long id = entryJson.getLong("id");
    final int typeKey = entryJson.getInt("action_type");
    final DataArray changes = entryJson.isNull("changes") ? null : entryJson.getArray("changes");
    final DataObject options = entryJson.isNull("options") ? null : entryJson.getObject("options");
    final String reason = entryJson.getString("reason", null);
    final UserImpl user = userJson == null ? null : createUser(userJson);
    final WebhookImpl webhook = webhookJson == null ? null : createWebhook(webhookJson);
    final Set<AuditLogChange> changesList;
    final ActionType type = ActionType.from(typeKey);
    if (changes != null) {
        changesList = new HashSet<>(changes.length());
        for (int i = 0; i < changes.length(); i++) {
            final DataObject object = changes.getObject(i);
            AuditLogChange change = createAuditLogChange(object);
            changesList.add(change);
        }
    } else {
        changesList = Collections.emptySet();
    }
    CaseInsensitiveMap<String, AuditLogChange> changeMap = new CaseInsensitiveMap<>(changeToMap(changesList));
    CaseInsensitiveMap<String, Object> optionMap = options != null ? new CaseInsensitiveMap<>(options.toMap()) : null;
    return new AuditLogEntry(type, typeKey, id, targetId, guild, user, webhook, reason, changeMap, optionMap);
}
Also used : ActionType(net.dv8tion.jda.api.audit.ActionType) AuditLogChange(net.dv8tion.jda.api.audit.AuditLogChange) DataArray(net.dv8tion.jda.api.utils.data.DataArray) CaseInsensitiveMap(org.apache.commons.collections4.map.CaseInsensitiveMap) DataObject(net.dv8tion.jda.api.utils.data.DataObject) AuditLogEntry(net.dv8tion.jda.api.audit.AuditLogEntry) DataObject(net.dv8tion.jda.api.utils.data.DataObject)

Aggregations

ActionType (net.dv8tion.jda.api.audit.ActionType)1 AuditLogChange (net.dv8tion.jda.api.audit.AuditLogChange)1 AuditLogEntry (net.dv8tion.jda.api.audit.AuditLogEntry)1 DataArray (net.dv8tion.jda.api.utils.data.DataArray)1 DataObject (net.dv8tion.jda.api.utils.data.DataObject)1 CaseInsensitiveMap (org.apache.commons.collections4.map.CaseInsensitiveMap)1