Search in sources :

Example 1 with DiscordUser

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

the class Player method ban.

@SuppressWarnings({ "rawtypes" })
public Ban ban(MessageContext context, Duration duration, String reason) {
    Ban ban = Ban.addBan(context, this, reason, duration);
    DiscordUser discord = DiscordUser.getDiscordUserIncludingUnknown(context, getDiscord());
    if (!(discord instanceof UnknownDiscordUser)) {
        discord.sendMessage(context, toString() + " " + reason);
    }
    return ban;
}
Also used : DiscordUser(com.gamebuster19901.excite.bot.user.DiscordUser) UnknownDiscordUser(com.gamebuster19901.excite.bot.user.UnknownDiscordUser) UnknownDiscordUser(com.gamebuster19901.excite.bot.user.UnknownDiscordUser) Ban(com.gamebuster19901.excite.bot.audit.ban.Ban)

Example 2 with DiscordUser

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

the class WhoIsCommand method sendResponse.

@SuppressWarnings("serial")
public static int sendResponse(MessageContext context, String lookingFor) {
    if (context.isConsoleMessage() || context.isIngameEvent()) {
        context.sendMessage("You cannot execute this command as " + context.getEvent().getClass().getSimpleName());
        return 1;
    }
    Wiimmfi wiimmfi = Main.discordBot.getWiimmfi();
    EmbedBuilder embed = new EmbedBuilder();
    boolean hasMembers = context.isGuildMessage();
    if (wiimmfi.getError() == null) {
        if (!lookingFor.isEmpty()) {
            HashSet<DiscordUser> users = new HashSet<DiscordUser>() {

                {
                    this.addAll(Arrays.asList(DiscordUser.getDiscordUsersWithUsernameOrID(context, lookingFor)));
                }
            };
            HashSet<Player> players = new HashSet<Player>() {

                {
                    this.addAll(Arrays.asList(Player.getPlayersByAnyIdentifier(context, lookingFor)));
                }
            };
            HashSet<Named> matches = new HashSet<Named>();
            matches.addAll(users);
            matches.addAll(players);
            SimpleDateFormat date = new SimpleDateFormat("yyyy/MM/dd HH:mm z", Locale.ENGLISH);
            if (matches.size() == 1) {
                Named match = matches.iterator().next();
                embed.setTitle("Information about " + match.getIdentifierName());
                if (match instanceof DiscordUser) {
                    DiscordUser user = (DiscordUser) match;
                    Member member;
                    embed.setColor(Color.WHITE);
                    Wii[] wiis = user.getRegisteredWiis();
                    Set<Player> profiles = user.getProfiles(context);
                    Duration timeOnline = Duration.ZERO;
                    Instant lastOnline = TimeUtils.PLAYER_EPOCH;
                    String profileList = "";
                    String wiiList = "";
                    for (Player profile : profiles) {
                        profileList = profileList + profile.toEmbedstring() + "\n";
                        timeOnline = timeOnline.plus(profile.getOnlineDuration());
                        Instant profileLastOnline = profile.getLastOnline();
                        if (profileLastOnline.isAfter(lastOnline)) {
                            lastOnline = profileLastOnline;
                        }
                    }
                    for (Wii wii : wiis) {
                        wiiList = wiiList + wii.getName() + "\n";
                    }
                    if (hasMembers && (member = user.getMember(context.getServer())) != null) {
                        embed.setColor(member.getColor());
                        embed.setThumbnail(user.getJDAUser().getEffectiveAvatarUrl());
                        embed.addField("Username:", user.getJDAUser().getName(), false);
                        embed.addField("Discriminator", user.getJDAUser().getDiscriminator(), false);
                        // embed.addField("Badges:", "", false);
                        embed.addField("ID:", "" + user.getID(), false);
                        embed.addField("Nickname:", member.getNickname() != null ? member.getNickname() : "##Not Nicknamed##", false);
                        embed.addField("Joined Discord:", date.format(member.getTimeCreated().toInstant().toEpochMilli()), false);
                        embed.addField("Joined " + context.getServer().getName() + ":", date.format(member.getTimeJoined().toInstant().toEpochMilli()), false);
                        embed.addField("Member for:", readableDuration(TimeUtils.since(member.getTimeJoined().toInstant()), false), false);
                        embed.addField("Time Online:", readableDuration(timeOnline, true), false);
                        embed.addField(profiles.size() + " registered Profiles:", profileList, false);
                        embed.addField(wiis.length + " registered Wiis:", wiiList, false);
                    } else {
                        embed.setThumbnail(user.getJDAUser().getEffectiveAvatarUrl());
                        embed.addField("Username:", user.getJDAUser().getName(), false);
                        embed.addField("Discriminator", user.getJDAUser().getDiscriminator(), false);
                        embed.addField("ID:", "" + user.getID(), false);
                        embed.addField("Time Online:", readableDuration(timeOnline, true), false);
                        embed.addField(profiles.size() + " registered Profiles:", profileList, false);
                        embed.addField(wiis.length + " registered Wiis:", wiiList, false);
                        embed.appendDescription("For more information, execute this command in a server the user is in.");
                    }
                } else if (match instanceof Player) {
                    Player profile = (Player) match;
                    DiscordUser user = DiscordUser.getDiscordUserTreatingUnknownsAsNobody(context, profile.getDiscord());
                    embed.addField("Name:", profile.getName(), false);
                    embed.addField("ID:", profile.getID() + "", false);
                    embed.addField("FC:", profile.getFriendCode(), false);
                    embed.addField("Owner:", user.toDetailedString(), false);
                    embed.addField("Time Online:", readableDuration(profile.getOnlineDuration(), true), false);
                    embed.addField("First Seen:", date.format(profile.getFirstSeen().toEpochMilli()), false);
                    embed.addField("Last Seen:", date.format(profile.getLastOnline().toEpochMilli()), false);
                }
            } else if (matches.size() == 0) {
                embed.setColor(Color.RED);
                embed.setTitle("Target not found");
                embed.addField("Target:", lookingFor, true);
            } else {
                embed.setTitle("Ambigious target string, supply an ID");
                embed.setColor(Color.RED);
                embed.addField("Target", lookingFor, true);
                embed.addField("Ambiguities", "" + matches.size(), true);
                if (users.size() > 0) {
                    embed.appendDescription("Discord users:\n");
                    String userList = "";
                    for (DiscordUser user : users) {
                        Member member;
                        if (hasMembers && (member = user.getMember(context.getServer())) != null && member.getNickname() != null) {
                            userList = userList + user.toDetailedString() + " AKA " + member.getEffectiveName() + "#" + member.getIdLong() + "\n";
                        } else {
                            userList = userList + user.toDetailedString() + "\n";
                        }
                    }
                    embed.addField("Ambiguous Users:", userList, false);
                }
                if (players.size() > 0) {
                    String playerList = "";
                    for (Player player : players) {
                        playerList = playerList + player.toFullString() + "\n";
                    }
                    embed.addField("Ambiguous Profiles:", playerList, false);
                }
            }
            embed.setTimestamp(Instant.now());
            context.sendMessage(embed.build());
        }
    }
    return 1;
}
Also used : DiscordUser(com.gamebuster19901.excite.bot.user.DiscordUser) Named(com.gamebuster19901.excite.util.Named) Player(com.gamebuster19901.excite.Player) Instant(java.time.Instant) Duration(java.time.Duration) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Wii(com.gamebuster19901.excite.bot.user.Wii) SimpleDateFormat(java.text.SimpleDateFormat) Member(net.dv8tion.jda.api.entities.Member) Wiimmfi(com.gamebuster19901.excite.Wiimmfi) HashSet(java.util.HashSet)

Example 3 with DiscordUser

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

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

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

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