Search in sources :

Example 6 with Audit

use of com.gamebuster19901.excite.bot.audit.Audit in project ExciteBot by TheGameCommunity.

the class WiiRegistrationAudit method addWiiRegistrationAudit.

public static WiiRegistrationAudit addWiiRegistrationAudit(MessageContext registrant, Wii wii, boolean unregister) {
    Audit parent;
    if (!unregister) {
        parent = Audit.addAudit(registrant, AuditType.WII_REGISTRATION_AUDIT, registrant.getAuthor().getIdentifierName() + " registered " + wii.getWiiCode().hyphenate());
    } else {
        parent = Audit.addAudit(registrant, AuditType.WII_REGISTRATION_AUDIT, registrant.getAuthor().getIdentifierName() + " unregistered " + wii.getWiiCode().hyphenate());
    }
    PreparedStatement st;
    try {
        st = Insertion.insertInto(Table.AUDIT_WII_REGISTER).setColumns(AUDIT_ID, WII_ID, DISCORD_ID, UNREGISTER).to(parent.getID(), wii.getWiiCode().toString(), registrant.getSenderId(), unregister).prepare(true);
        st.execute();
        WiiRegistrationAudit ret = getWiiRegistrationAuditByID(ConsoleContext.INSTANCE, parent.getID());
        ret.parentData = parent;
        return ret;
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : SQLException(java.sql.SQLException) IOError(java.io.IOError) PreparedStatement(com.gamebuster19901.excite.bot.database.sql.PreparedStatement)

Example 7 with Audit

use of com.gamebuster19901.excite.bot.audit.Audit in project ExciteBot by TheGameCommunity.

the class Ban method addBan.

@SuppressWarnings({ "rawtypes", "deprecation" })
public static Ban addBan(MessageContext context, Banee banee, String reason, Duration banDuration, Instant banExpire, long pardon) {
    Audit parent = Audit.addAudit(context, AuditType.BAN, reason);
    PreparedStatement st;
    context.sendMessage(banee.getClass().getCanonicalName());
    try {
        st = Insertion.insertInto(AUDIT_BANS).setColumns(AUDIT_ID, BAN_DURATION, BAN_EXPIRE, BANNED_ID, BANNED_USERNAME).to(parent.getID(), banDuration, banExpire, banee.getID(), banee.getName()).prepare(context, true);
        st.execute();
        Ban ret = getBanByAuditId(context, parent.getID());
        ret.parentData = parent;
        return ret;
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : Audit(com.gamebuster19901.excite.bot.audit.Audit) SQLException(java.sql.SQLException) IOError(java.io.IOError) PreparedStatement(com.gamebuster19901.excite.bot.database.sql.PreparedStatement)

Example 8 with Audit

use of com.gamebuster19901.excite.bot.audit.Audit in project ExciteBot by TheGameCommunity.

the class Audit method createAudit.

@Nullable
@SuppressWarnings({ "rawtypes", "unchecked" })
protected static Audit createAudit(MessageContext context, Row row) throws SQLException {
    AuditType type = AuditType.getType(row);
    long auditID = row.getLong(AUDIT_ID);
    Class<? extends Audit> auditTypeClazz = AuditType.getType(row).getType();
    try {
        Constructor<? extends Audit> constructor = auditTypeClazz.getDeclaredConstructor(Row.class);
        constructor.setAccessible(true);
        Result result = Table.selectAllFromJoinedUsingWhere(new MessageContext(context.getAuthor()), AUDITS, type.getTable(), AUDIT_ID, new Comparison(AUDIT_ID, EQUALS, auditID));
        result.next();
        if (result.cursorValid()) {
            Row resultRow = result.getRow();
            return constructor.newInstance(resultRow);
        }
        return null;
    } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        throw new AssertionError(e);
    }
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) Result(com.gamebuster19901.excite.bot.database.Result) Comparison(com.gamebuster19901.excite.bot.database.Comparison) MessageContext(com.gamebuster19901.excite.bot.command.MessageContext) Row(com.gamebuster19901.excite.bot.database.Row) Nullable(javax.annotation.Nullable)

Example 9 with Audit

use of com.gamebuster19901.excite.bot.audit.Audit in project ExciteBot by TheGameCommunity.

the class Audit method addAudit.

@Deprecated
@SuppressWarnings("rawtypes")
protected static Audit addAudit(MessageContext executor, MessageContext context, AuditType type, String description, Instant dateIssued) {
    PreparedStatement ps;
    try {
        ps = Insertion.insertInto(AUDITS).setColumns(AUDIT_TYPE, ISSUER_ID, ISSUER_NAME, DESCRIPTION, DATE_ISSUED).to(type, context.getAuthor().getID(), context.getAuthor().getName(), description, Instant.now()).prepare(executor, true);
        ps.execute();
        ResultSet results = ps.getGeneratedKeys();
        results.next();
        long auditID = results.getLong(GENERATED_KEY);
        Row row = Table.selectAllFromWhere(executor, AUDITS, new Comparison(AUDIT_ID, EQUALS, auditID)).getRow(true);
        return new Audit(row, type);
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : Comparison(com.gamebuster19901.excite.bot.database.Comparison) SQLException(java.sql.SQLException) IOError(java.io.IOError) ResultSet(com.gamebuster19901.excite.bot.database.sql.ResultSet) PreparedStatement(com.gamebuster19901.excite.bot.database.sql.PreparedStatement) Row(com.gamebuster19901.excite.bot.database.Row)

Example 10 with Audit

use of com.gamebuster19901.excite.bot.audit.Audit in project ExciteBot by TheGameCommunity.

the class CommandAudit method addCommandAudit.

@SuppressWarnings("rawtypes")
public static CommandAudit addCommandAudit(MessageContext context, String command) {
    Audit parent = Audit.addAudit(ConsoleContext.INSTANCE, context, AuditType.COMMAND_AUDIT, command);
    PreparedStatement st;
    try {
        String serverName = null;
        long serverID = 0;
        String channelName = null;
        long channelID = 0;
        long messageID = 0;
        boolean isGuildMessage = context.isGuildMessage();
        boolean isPrivateMessage = context.isPrivateMessage();
        boolean isConsoleMessage = context.isConsoleMessage();
        boolean isAdmin = context.isAdmin();
        boolean isOperator = context.isOperator();
        if (isPrivateMessage || isConsoleMessage) {
            channelName = context.getDiscordAuthor().getName();
            channelID = context.getSenderId();
        } else {
            serverName = context.getServer().getName();
            serverID = context.getServer().getID();
            channelName = context.getChannel().getName();
            channelID = context.getChannel().getIdLong();
            messageID = context.getMessage().getIdLong();
        }
        st = Insertion.insertInto(AUDIT_COMMANDS).setColumns(AUDIT_ID, SERVER_NAME, SERVER_ID, CHANNEL_NAME, CHANNEL_ID, MESSAGE_ID, IS_GUILD_MESSAGE, IS_PRIVATE_MESSAGE, IS_CONSOLE_MESSAGE, IS_ADMIN, IS_OPERATOR).to(parent.getID(), serverName, serverID, channelName, channelID, messageID, isGuildMessage, isPrivateMessage, isConsoleMessage, isAdmin, isOperator).prepare(ConsoleContext.INSTANCE, true);
        st.execute();
        CommandAudit ret = getCommandAuditByID(ConsoleContext.INSTANCE, parent.getID());
        ret.parentData = parent;
        return ret;
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : SQLException(java.sql.SQLException) IOError(java.io.IOError) PreparedStatement(com.gamebuster19901.excite.bot.database.sql.PreparedStatement)

Aggregations

PreparedStatement (com.gamebuster19901.excite.bot.database.sql.PreparedStatement)14 IOError (java.io.IOError)14 SQLException (java.sql.SQLException)14 Audit (com.gamebuster19901.excite.bot.audit.Audit)2 MessageContext (com.gamebuster19901.excite.bot.command.MessageContext)2 Comparison (com.gamebuster19901.excite.bot.database.Comparison)2 Row (com.gamebuster19901.excite.bot.database.Row)2 ElectronicAddress (com.gamebuster19901.excite.bot.mail.ElectronicAddress)2 Nullable (javax.annotation.Nullable)2 AuditType (com.gamebuster19901.excite.bot.audit.AuditType)1 Result (com.gamebuster19901.excite.bot.database.Result)1 ResultSet (com.gamebuster19901.excite.bot.database.sql.ResultSet)1 AddFriendResponse (com.gamebuster19901.excite.bot.mail.AddFriendResponse)1 EmailAddress (com.gamebuster19901.excite.bot.mail.EmailAddress)1 RefundResponse (com.gamebuster19901.excite.bot.mail.RefundResponse)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 InternetAddress (javax.mail.internet.InternetAddress)1