Java源码示例:net.dv8tion.jda.api.audit.ActionType

示例1
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 : createFakeUser(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);
}
 
示例2
private void onGuildUnban(GuildUnbanEvent event) {
    modLogBanUnban(ActionType.UNBAN, event.getUser(), event.getGuild());
}
 
示例3
private void onGuildBan(GuildBanEvent event) {
    modLogBanUnban(ActionType.BAN, event.getUser(), event.getGuild());
}
 
示例4
private void modLogBanUnban(ActionType type, User user, Guild guild) {
    if (!guild.getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
        return;
    }

    final DunctebotGuild dbg = new DunctebotGuild(guild, variables);
    final GuildSettings settings = dbg.getSettings();

    if (settings.getLogChannel() < 1) {
        return;
    }

    // If unban and unban logging is disabled
    if (type == ActionType.UNBAN && !settings.isUnbanLogging()) {
        return;
    }

    // If ban and ban logging is disabled
    if (type == ActionType.BAN && !settings.isBanLogging()) {
        return;
    }

    guild.retrieveAuditLogs()
        .cache(false)
        .type(type)
        .limit(5)
        .queue((actions) -> {
            for (final AuditLogEntry action : actions) {
                if (action.getUser() != null && action.getUser().getIdLong() == guild.getSelfMember().getIdLong()) {
                    continue;
                }

                if (action.getTargetIdLong() == user.getIdLong()) {
                    ModerationUtils.modLog(
                        action.getUser(),
                        user,
                        type == ActionType.BAN ? "banned" : "unbanned",
                        action.getReason(),
                        dbg
                    );

                    break;
                }
            }
        });
}