Search in sources :

Example 16 with DiscordUser

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

the class Commands method handleCommand.

public void handleCommand(PrivateMessageReceivedEvent e) {
    MessageContext<PrivateMessageReceivedEvent> context = new MessageContext<PrivateMessageReceivedEvent>(e);
    String message = e.getMessage().getContentRaw();
    try {
        DiscordUser sender = DiscordUser.getDiscordUser(ConsoleContext.INSTANCE, e.getAuthor().getIdLong());
        if (!sender.isBanned()) {
            if (!sender.isBanned()) {
                CommandAudit.addCommandAudit(context, message);
                this.dispatcher.execute(message, context);
            }
        }
    } catch (CommandSyntaxException ex) {
        context.sendMessage(ex.getMessage());
    } catch (Throwable t) {
        context.sendMessage(StacktraceUtil.getStackTrace(t));
        if (!context.isConsoleMessage()) {
            t.printStackTrace();
        }
        if (t instanceof Error) {
            throw t;
        }
    }
}
Also used : DiscordUser(com.gamebuster19901.excite.bot.user.DiscordUser) PrivateMessageReceivedEvent(net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 17 with DiscordUser

use of com.gamebuster19901.excite.bot.user.DiscordUser 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

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