Search in sources :

Example 6 with DiscordUser

use of com.gamebuster19901.excite.bot.user.DiscordUser in project ExciteBot by TheGameCommunity.

the class DiscordUser method addDiscordUser.

@SuppressWarnings("rawtypes")
private static DiscordUser addDiscordUser(MessageContext context, long discordID, String name) throws SQLException {
    PreparedStatement ps = null;
    try {
        ps = context.getConnection().prepareStatement("INSERT INTO " + DISCORD_USERS + " (" + DISCORD_ID + ", " + DISCORD_NAME + ", " + LAST_NOTIFICATION + ") VALUES (?, ?, ?);");
        Table.insertValue(ps, 1, discordID);
        Table.insertValue(ps, 2, name);
        Table.insertValue(ps, 3, TimeUtils.PLAYER_EPOCH);
        ps.execute();
    } catch (Exception e) {
        ConsoleUser.getConsoleUser().sendMessage(ps.toString());
        throw new IOError(e);
    }
    return getDiscordUser(context, discordID);
}
Also used : IOError(java.io.IOError) PreparedStatement(com.gamebuster19901.excite.bot.database.sql.PreparedStatement) SQLException(java.sql.SQLException) ErrorResponseException(net.dv8tion.jda.api.exceptions.ErrorResponseException)

Example 7 with DiscordUser

use of com.gamebuster19901.excite.bot.user.DiscordUser in project ExciteBot by TheGameCommunity.

the class DiscordUser method notifyDiscordUsers.

public static void notifyDiscordUsers() throws SQLException {
    int count = Wiimmfi.getAcknowledgedPlayerCount();
    Result result = Table.selectAllFrom(ConsoleContext.INSTANCE, DISCORD_USERS);
    while (result.next()) {
        int threshold = result.getInt(THRESHOLD);
        if (count < threshold) {
            new DiscordUser(result).setDippedBelowThreshold(true);
            continue;
        } else {
            if (Instant.parse(result.getString(LAST_NOTIFICATION)).plus(Duration.parse(result.getString(FREQUENCY))).isBefore(Instant.now())) {
                if (result.getBoolean(BELOW_THRESHOLD)) {
                    DiscordUser user = new DiscordUser(result);
                    if (!result.getBoolean(NOTIFY_CONTINUOUSLY)) {
                        user.setDippedBelowThreshold(false);
                    }
                    if (threshold != -1) {
                        for (Player player : Wiimmfi.getOnlinePlayers()) {
                            if (player.getDiscord() == result.getLong(DISCORD_ID)) {
                                return;
                            }
                        }
                        user.sendMessage("Players Online" + Wiimmfi.getOnlinePlayerList(user.sendDetailedPM()));
                        user.setLastNotification();
                    }
                }
            }
        }
    }
}
Also used : Player(com.gamebuster19901.excite.Player) Result(com.gamebuster19901.excite.bot.database.Result)

Example 8 with DiscordUser

use of com.gamebuster19901.excite.bot.user.DiscordUser in project ExciteBot by TheGameCommunity.

the class DiscordUser method getAllOperators.

public static DiscordUser[] getAllOperators() {
    try {
        PreparedStatement st = ConsoleContext.INSTANCE.getConnection().prepareStatement("SELECT * FROM discord_users INNER JOIN operators ON(discord_users.discordID = operators.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 9 with DiscordUser

use of com.gamebuster19901.excite.bot.user.DiscordUser in project ExciteBot by TheGameCommunity.

the class RankChangeAudit method addRankChange.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static RankChangeAudit addRankChange(MessageContext context, DiscordUser promotee, String rank, boolean added) {
    Audit parent = Audit.addAudit(ConsoleContext.INSTANCE, context, AuditType.RANK_CHANGE_AUDIT, getMessage(context, new MessageContext(promotee), rank, added));
    PreparedStatement st;
    try {
        st = Insertion.insertInto(AUDIT_RANK_CHANGES).setColumns(AUDIT_ID, PROMOTEE, PROMOTEE_ID).to(parent.getID(), promotee, promotee.getID()).prepare(ConsoleContext.INSTANCE, true);
        st.execute();
        RankChangeAudit ret = getRankChangeAuditByID(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) MessageContext(com.gamebuster19901.excite.bot.command.MessageContext)

Example 10 with DiscordUser

use of com.gamebuster19901.excite.bot.user.DiscordUser in project ExciteBot by TheGameCommunity.

the class Banee method getBanee.

@SuppressWarnings("rawtypes")
public static Banee getBanee(MessageContext context, long id) {
    DiscordUser discord = DiscordUser.getDiscordUserIncludingUnknown(context, id);
    Player player = Player.getPlayerByID(context, (int) id);
    if (!player.isKnown()) {
        return discord;
    }
    return player;
}
Also used : DiscordUser(com.gamebuster19901.excite.bot.user.DiscordUser) Player(com.gamebuster19901.excite.Player)

Aggregations

DiscordUser (com.gamebuster19901.excite.bot.user.DiscordUser)8 SQLException (java.sql.SQLException)7 Player (com.gamebuster19901.excite.Player)5 Result (com.gamebuster19901.excite.bot.database.Result)5 IOError (java.io.IOError)5 PreparedStatement (com.gamebuster19901.excite.bot.database.sql.PreparedStatement)4 UnknownDiscordUser (com.gamebuster19901.excite.bot.user.UnknownDiscordUser)3 Ban (com.gamebuster19901.excite.bot.audit.ban.Ban)2 Comparison (com.gamebuster19901.excite.bot.database.Comparison)2 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)2 Duration (java.time.Duration)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ErrorResponseException (net.dv8tion.jda.api.exceptions.ErrorResponseException)2 Wiimmfi (com.gamebuster19901.excite.Wiimmfi)1 MessageContext (com.gamebuster19901.excite.bot.command.MessageContext)1 DatabaseConnection (com.gamebuster19901.excite.bot.database.sql.DatabaseConnection)1 ConsoleUser (com.gamebuster19901.excite.bot.user.ConsoleUser)1 Wii (com.gamebuster19901.excite.bot.user.Wii)1