Search in sources :

Example 1 with Comparison

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

the class Wii method register.

public void register(MessageContext owner) throws SQLException, MessagingException {
    Table.updateWhere(owner, WIIS, DISCORD_ID, owner.getSenderId(), new Comparison(WII_ID, EQUALS, wiiCode.code));
    Table.updateWhere(owner, WIIS, REGISTRATION_CODE, null, new Comparison(WII_ID, EQUALS, wiiCode.code));
    WiiRegistrationAudit.addWiiRegistrationAudit(owner, this, false);
    EmbedBuilder embed = new EmbedBuilder();
    embed.setColor(Color.GREEN);
    embed.setTitle("Registration Successful");
    embed.setDescription("You have succesfully registered the following wii:\n\n" + this.getIdentifierName());
    ElectronicAddress exciteEmail = Mailbox.ADDRESS;
    owner.sendMessage(embed.build());
    LinkedHashSet<MailResponse> wiiMail = Mailbox.packResponses(new TextualMailResponse((Wii) exciteEmail, this, null).setText("This wii has been registered with\n Excitebot.\n" + "registrant: " + owner.getDiscordAuthor().getIdentifierName() + "\n\n" + "If this is not you, contact a TCG\nadmin immediately.\n\n" + "-The Game Community"));
    Mailbox.sendResponses(wiiMail);
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Comparison(com.gamebuster19901.excite.bot.database.Comparison) TextualMailResponse(com.gamebuster19901.excite.bot.mail.TextualMailResponse) ElectronicAddress(com.gamebuster19901.excite.bot.mail.ElectronicAddress) MailResponse(com.gamebuster19901.excite.bot.mail.MailResponse) TextualMailResponse(com.gamebuster19901.excite.bot.mail.TextualMailResponse)

Example 2 with Comparison

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

the class Wii method getRegistrationCode.

public String getRegistrationCode() {
    try {
        Result result = Table.selectColumnsFromWhere(ConsoleContext.INSTANCE, REGISTRATION_CODE, WIIS, new Comparison(WII_ID, EQUALS, wiiCode));
        if (result.next()) {
            String ret = result.getString(REGISTRATION_CODE);
            if (ret == null) {
                generateRegistrationCode();
                result = Table.selectColumnsFromWhere(ConsoleContext.INSTANCE, REGISTRATION_CODE, WIIS, new Comparison(WII_ID, EQUALS, wiiCode));
                if (result.next()) {
                    return result.getString(REGISTRATION_CODE);
                }
            } else {
                return ret;
            }
        } else {
            generateRegistrationCode();
            result = Table.selectColumnsFromWhere(ConsoleContext.INSTANCE, REGISTRATION_CODE, WIIS, new Comparison(WII_ID, EQUALS, wiiCode));
            if (result.next()) {
                return result.getString(REGISTRATION_CODE);
            }
        }
        throw new AssertionError();
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : Comparison(com.gamebuster19901.excite.bot.database.Comparison) SQLException(java.sql.SQLException) IOError(java.io.IOError) Result(com.gamebuster19901.excite.bot.database.Result)

Example 3 with Comparison

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

the class DiscordUser method getDiscordUsersWithUsername.

@Deprecated
@SuppressWarnings("rawtypes")
public static final DiscordUser[] getDiscordUsersWithUsername(MessageContext context, String username) {
    try {
        ArrayList<DiscordUser> users = new ArrayList<DiscordUser>();
        Result results = Table.selectAllFromWhere(context, DISCORD_USERS, new Comparison(DISCORD_NAME, LIKE, Table.makeSafe(username) + "_____"));
        while (results.next()) {
            users.add(new DiscordUser(results));
        }
        return users.toArray(new DiscordUser[] {});
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : Comparison(com.gamebuster19901.excite.bot.database.Comparison) SQLException(java.sql.SQLException) IOError(java.io.IOError) ArrayList(java.util.ArrayList) Result(com.gamebuster19901.excite.bot.database.Result)

Example 4 with Comparison

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

the class DiscordUser method getRegisteredWiis.

@Nullable
public Wii[] getRegisteredWiis() {
    try {
        HashSet<Wii> wiis = new HashSet<Wii>();
        Result result = Table.selectColumnsFromWhere(ConsoleContext.INSTANCE, WII_ID, WIIS, new Comparison(DISCORD_ID, EQUALS, getID()));
        while (result.next()) {
            wiis.add(Wii.getWii(result.getString(WII_ID)));
        }
        return (Wii[]) wiis.toArray(new Wii[] {});
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : Comparison(com.gamebuster19901.excite.bot.database.Comparison) SQLException(java.sql.SQLException) IOError(java.io.IOError) HashSet(java.util.HashSet) Result(com.gamebuster19901.excite.bot.database.Result) Nullable(javax.annotation.Nullable)

Example 5 with Comparison

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

the class DiscordUser method getDiscordUsersWithUsernameOrID.

@SuppressWarnings("rawtypes")
public static final DiscordUser[] getDiscordUsersWithUsernameOrID(MessageContext context, String usernameOrID) {
    try {
        if (usernameOrID.indexOf("#") != -1) {
            if (usernameOrID.length() > usernameOrID.indexOf('#')) {
                String name = usernameOrID.substring(0, usernameOrID.indexOf('#'));
                String discriminator = usernameOrID.substring(usernameOrID.indexOf('#') + 1, usernameOrID.length());
                DiscordUser user = getDiscordUser(context, name, discriminator);
                if (user != null) {
                    return new DiscordUser[] { user };
                }
            }
            return new DiscordUser[0];
        }
        ArrayList<DiscordUser> users = new ArrayList<DiscordUser>();
        Result results = Table.selectAllFromWhere(context, DISCORD_USERS, new Comparison(DISCORD_NAME, LIKE, Table.makeSafe(usernameOrID) + "_____").or(new Comparison(DISCORD_ID, EQUALS, Table.makeSafe(usernameOrID))));
        while (results.next()) {
            users.add(new DiscordUser(results));
        }
        return users.toArray(new DiscordUser[] {});
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : Comparison(com.gamebuster19901.excite.bot.database.Comparison) SQLException(java.sql.SQLException) IOError(java.io.IOError) ArrayList(java.util.ArrayList) Result(com.gamebuster19901.excite.bot.database.Result)

Aggregations

Comparison (com.gamebuster19901.excite.bot.database.Comparison)12 Result (com.gamebuster19901.excite.bot.database.Result)8 SQLException (java.sql.SQLException)8 IOError (java.io.IOError)7 MessageContext (com.gamebuster19901.excite.bot.command.MessageContext)3 ArrayList (java.util.ArrayList)3 Row (com.gamebuster19901.excite.bot.database.Row)2 HashSet (java.util.HashSet)2 Nullable (javax.annotation.Nullable)2 Player (com.gamebuster19901.excite.Player)1 PreparedStatement (com.gamebuster19901.excite.bot.database.sql.PreparedStatement)1 ResultSet (com.gamebuster19901.excite.bot.database.sql.ResultSet)1 ElectronicAddress (com.gamebuster19901.excite.bot.mail.ElectronicAddress)1 MailResponse (com.gamebuster19901.excite.bot.mail.MailResponse)1 TextualMailResponse (com.gamebuster19901.excite.bot.mail.TextualMailResponse)1 Wii (com.gamebuster19901.excite.bot.user.Wii)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MessagingException (javax.mail.MessagingException)1 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1