Search in sources :

Example 11 with Player

use of com.gamebuster19901.excite.Player in project ExciteBot by TheGameCommunity.

the class BanCommand method banProfile.

@SuppressWarnings("rawtypes")
private static int banProfile(MessageContext context, Player profile, Duration duration, String reason) {
    if (context.isAdmin()) {
        Ban ban = profile.ban(context, duration, reason);
        String message = "Banned profile " + profile.getPrettyDiscord() + ": \n\n" + ban;
        if (context.isConsoleMessage()) {
            context.sendMessage(message);
        } else {
            PrivateChannel privateChannel;
            if (context.isPrivateMessage()) {
                privateChannel = (PrivateChannel) context.getChannel();
            } else {
                privateChannel = context.getDiscordAuthor().getJDAUser().openPrivateChannel().complete();
            }
            privateChannel.sendMessage(message);
        }
    } else {
        context.sendMessage("You do not have permission to execute this command");
    }
    return 1;
}
Also used : PrivateChannel(net.dv8tion.jda.api.entities.PrivateChannel) Ban(com.gamebuster19901.excite.bot.audit.ban.Ban)

Example 12 with Player

use of com.gamebuster19901.excite.Player in project ExciteBot by TheGameCommunity.

the class DiscoveryAudit method addProfileDiscovery.

@SuppressWarnings("rawtypes")
public static DiscoveryAudit addProfileDiscovery(MessageContext context, boolean automatic, Player player) {
    Audit parent = Audit.addAudit(context, AuditType.DISCOVERY_AUDIT, getMessage(context, automatic, player));
    PreparedStatement st;
    try {
        st = Insertion.insertInto(Table.AUDIT_PROFILE_DISCOVERIES).setColumns(AUDIT_ID, PLAYER_ID).to(parent.getID(), player.getID()).prepare(context, true);
        st.execute();
        DiscoveryAudit ret = getProfileDiscoveryByDiscoveredID(ConsoleContext.INSTANCE, player.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 13 with Player

use of com.gamebuster19901.excite.Player in project ExciteBot by TheGameCommunity.

the class NameChangeAudit method addNameChange.

@SuppressWarnings("rawtypes")
public static NameChangeAudit addNameChange(MessageContext context, Player player, String newName) {
    Audit parent = Audit.addAudit(ConsoleContext.INSTANCE, context, AuditType.NAME_CHANGE_AUDIT, getMessage(context, newName));
    String name = player.getName();
    PreparedStatement st;
    try {
        st = Insertion.insertInto(Table.AUDIT_NAME_CHANGES).setColumns(AUDIT_ID, OLD_PLAYER_NAME, NEW_PLAYER_NAME, PLAYER_ID, FRIEND_CODE).to(parent.getID(), name, newName, player.getID(), player.getFriendCode()).prepare(ConsoleContext.INSTANCE, true);
        st.execute();
        NameChangeAudit ret = getNameChangeByAuditID(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 14 with Player

use of com.gamebuster19901.excite.Player in project ExciteBot by TheGameCommunity.

the class InsertCommand method addProfile.

private static int addProfile(MessageContext context, int pid, String fc, String name) {
    if (context.isOperator()) {
        if (!Player.isPlayerKnown(context, pid)) {
            try {
                if (Player.isValidFriendCode(fc)) {
                    name = name.replace("\"", "");
                    Player.addPlayer(context, false, pid, fc, name);
                    Player player = Player.getPlayerByID(context, pid);
                    context.sendMessage("Inserted " + player.toFullString());
                    return 1;
                } else {
                    context.sendMessage(fc + " is not a valid friend code");
                    return 1;
                }
            } catch (SQLException e) {
                context.sendMessage("Unable to add profile " + pid + ":\n\n + " + StacktraceUtil.getStackTrace(e));
                return 1;
            }
        } else {
            context.sendMessage("A profile with PID " + pid + " is already known.");
            return 1;
        }
    }
    context.sendMessage("You do not have permission to execute that command.");
    return 1;
}
Also used : Player(com.gamebuster19901.excite.Player) SQLException(java.sql.SQLException)

Example 15 with Player

use of com.gamebuster19901.excite.Player in project ExciteBot by TheGameCommunity.

the class RegisterCommand method requestRegistration.

@SuppressWarnings("rawtypes")
private static void requestRegistration(MessageContext context, String player) {
    HashSet<Player> players = new HashSet<Player>();
    DiscordUser discordUser = context.getDiscordAuthor();
    if (context.isConsoleMessage()) {
        context.sendMessage("This command must be executed from discord.");
        return;
    }
    if (discordUser.requestingRegistration()) {
        context.sendMessage("You are already trying to register a profile! Please wait until registration is complete or the registration code expires.");
        return;
    }
    try {
        int pid = Integer.parseInt(player);
        players.add(Player.getPlayerByID(ConsoleContext.INSTANCE, pid));
    } catch (NumberFormatException e) {
        for (Player p : Player.getPlayersByName(ConsoleContext.INSTANCE, player)) {
            players.add(p);
        }
    }
    switch(players.size()) {
        case 0:
            context.sendMessage("Could not find a player with name or PID of " + player);
            break;
        case 1:
            Player desiredProfile = players.toArray(new Player[] {})[0];
            if (desiredProfile.isBanned()) {
                context.sendMessage("You cannot register a banned profile.");
                return;
            }
            String securityCode = discordUser.requestRegistration(desiredProfile);
            sendInfo(context, discordUser, desiredProfile, securityCode);
            break;
        default:
            String ambiguities = "";
            for (Player p : players) {
                ambiguities += p.toFullString() + "\n";
            }
            context.sendMessage(player + " is ambiguous as there is more than one profile known with that name. Please supply your account's PID instead of it's name." + "\n\nAmbiguities:\n\n" + ambiguities);
            break;
    }
}
Also used : DiscordUser(com.gamebuster19901.excite.bot.user.DiscordUser) Player(com.gamebuster19901.excite.Player) HashSet(java.util.HashSet)

Aggregations

Player (com.gamebuster19901.excite.Player)7 SQLException (java.sql.SQLException)6 PreparedStatement (com.gamebuster19901.excite.bot.database.sql.PreparedStatement)5 IOError (java.io.IOError)5 DiscordUser (com.gamebuster19901.excite.bot.user.DiscordUser)4 HashSet (java.util.HashSet)4 Result (com.gamebuster19901.excite.bot.database.Result)2 Duration (java.time.Duration)2 UnknownPlayer (com.gamebuster19901.excite.UnknownPlayer)1 Wiimmfi (com.gamebuster19901.excite.Wiimmfi)1 Ban (com.gamebuster19901.excite.bot.audit.ban.Ban)1 MessageContext (com.gamebuster19901.excite.bot.command.MessageContext)1 Comparison (com.gamebuster19901.excite.bot.database.Comparison)1 Wii (com.gamebuster19901.excite.bot.user.Wii)1 WiimmfiErrorResponse (com.gamebuster19901.excite.exception.WiimmfiErrorResponse)1 WiimmfiResponseException (com.gamebuster19901.excite.exception.WiimmfiResponseException)1 Named (com.gamebuster19901.excite.util.Named)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 SimpleDateFormat (java.text.SimpleDateFormat)1