Search in sources :

Example 6 with PreparedStatement

use of com.gamebuster19901.excite.bot.database.sql.PreparedStatement in project ExciteBot by TheGameCommunity.

the class LogInAudit method addLoginAudit.

public static LogInAudit addLoginAudit(MessageContext context, Player player) {
    Audit parent = Audit.addAudit(context, AuditType.LOG_IN_AUDIT, getMessage(player));
    PreparedStatement st;
    try {
        st = Insertion.insertInto(Table.AUDIT_PROFILE_LOGINS).setColumns(AUDIT_ID).to(parent.getID()).prepare(context, true);
        st.execute();
        LogInAudit ret = getLoginAuditByAuditID(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 PreparedStatement

use of com.gamebuster19901.excite.bot.database.sql.PreparedStatement in project ExciteBot by TheGameCommunity.

the class MailAudit method addMailAudit.

@SuppressWarnings("rawtypes")
public static MailAudit addMailAudit(MessageContext context, MailReplyResponse message, boolean incoming, File file) {
    ElectronicAddress from = message.getResponder();
    ElectronicAddress to = message.getRespondee();
    String description = from.getEmail() + " sent mail to " + to.getEmail();
    String mailType = "GENERIC";
    if (message instanceof AddFriendResponse) {
        description = from.getEmail() + " sent a friend request to " + to.getEmail();
        mailType = "FRIEND_REQUEST";
    } else if (message instanceof RefundResponse) {
        description = "refunded " + ((RefundResponse) message).getReward() + " to " + to.getEmail();
        mailType = "REFUND";
    }
    Audit parent = Audit.addAudit(context, AuditType.MAIL_AUDIT, description);
    PreparedStatement st;
    try {
        st = Insertion.insertInto(Table.MAIL).setColumns(AUDIT_ID, SENDER, RECIPIENT, INCOMING, MAIL_TYPE, FILE).to(parent.getID(), from.getEmail(), to.getEmail(), incoming, mailType, file.getAbsolutePath()).prepare(context, true);
        st.execute();
        MailAudit ret = getMailAuditByAuditID(ConsoleContext.INSTANCE, parent.getID());
        ret.parentData = parent;
        return ret;
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : AddFriendResponse(com.gamebuster19901.excite.bot.mail.AddFriendResponse) SQLException(java.sql.SQLException) IOError(java.io.IOError) ElectronicAddress(com.gamebuster19901.excite.bot.mail.ElectronicAddress) PreparedStatement(com.gamebuster19901.excite.bot.database.sql.PreparedStatement) RefundResponse(com.gamebuster19901.excite.bot.mail.RefundResponse)

Example 8 with PreparedStatement

use of com.gamebuster19901.excite.bot.database.sql.PreparedStatement 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 9 with PreparedStatement

use of com.gamebuster19901.excite.bot.database.sql.PreparedStatement in project ExciteBot by TheGameCommunity.

the class DiscordUser method getAllAdmins.

public static DiscordUser[] getAllAdmins() {
    try {
        PreparedStatement st = ConsoleContext.INSTANCE.getConnection().prepareStatement("SELECT * FROM discord_users INNER JOIN admins ON(discord_users.discordID = admins.discordID);");
        Result results = st.query();
        int columns = results.getColumnCount();
        DiscordUser[] operators = new DiscordUser[columns];
        for (int i = 0; i < columns; i++) {
            results.next();
            operators[i] = new DiscordUser(results);
        }
        return operators;
    } catch (SQLException e) {
        throw new AssertionError(e);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(com.gamebuster19901.excite.bot.database.sql.PreparedStatement) Result(com.gamebuster19901.excite.bot.database.Result)

Example 10 with PreparedStatement

use of com.gamebuster19901.excite.bot.database.sql.PreparedStatement in project ExciteBot by TheGameCommunity.

the class DiscordServer method addServer.

@SuppressWarnings({ "rawtypes", "resource" })
public static DiscordServer addServer(MessageContext context, long guildId, String name) throws SQLException {
    PreparedStatement ps = context.getConnection().prepareStatement("INSERT INTO " + DISCORD_SERVERS + " (" + SERVER_ID + ", " + SERVER_NAME + ") VALUES (?, ?)");
    ps.setLong(1, guildId);
    ps.setString(2, name);
    ps.execute();
    return getServer(context, guildId);
}
Also used : PreparedStatement(com.gamebuster19901.excite.bot.database.sql.PreparedStatement)

Aggregations

PreparedStatement (com.gamebuster19901.excite.bot.database.sql.PreparedStatement)19 SQLException (java.sql.SQLException)17 IOError (java.io.IOError)15 Audit (com.gamebuster19901.excite.bot.audit.Audit)2 Result (com.gamebuster19901.excite.bot.database.Result)2 ElectronicAddress (com.gamebuster19901.excite.bot.mail.ElectronicAddress)2 AuditType (com.gamebuster19901.excite.bot.audit.AuditType)1 MessageContext (com.gamebuster19901.excite.bot.command.MessageContext)1 Comparison (com.gamebuster19901.excite.bot.database.Comparison)1 Row (com.gamebuster19901.excite.bot.database.Row)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 Nullable (javax.annotation.Nullable)1 InternetAddress (javax.mail.internet.InternetAddress)1 ErrorResponseException (net.dv8tion.jda.api.exceptions.ErrorResponseException)1