Search in sources :

Example 41 with IUser

use of sx.blah.discord.handle.obj.IUser in project DisCal-Discord-Bot by NovaFox161.

the class AnnouncementMessageFormatter method getSubscriberNames.

public static String getSubscriberNames(Announcement a) {
    // Loop and get subs without mentions...
    IGuild guild = Main.client.getGuildByID(a.getGuildId());
    StringBuilder userMentions = new StringBuilder();
    for (String userId : a.getSubscriberUserIds()) {
        try {
            IUser user = guild.getUserByID(Long.valueOf(userId));
            if (user != null) {
                userMentions.append(user.getName()).append(" ");
            }
        } catch (Exception e) {
        // User does not exist, safely ignore.
        }
    }
    StringBuilder roleMentions = new StringBuilder();
    Boolean mentionEveryone = false;
    Boolean mentionHere = false;
    for (String roleId : a.getSubscriberRoleIds()) {
        if (roleId.equalsIgnoreCase("everyone")) {
            mentionEveryone = true;
        } else if (roleId.equalsIgnoreCase("here")) {
            mentionHere = true;
        } else {
            try {
                IRole role = guild.getRoleByID(Long.valueOf(roleId));
                if (role != null) {
                    roleMentions.append(role.getName()).append(" ");
                }
            } catch (Exception e) {
            // Role does not exist, safely ignore.
            }
        }
    }
    String message = "Subscribers: " + userMentions + " " + roleMentions;
    if (mentionEveryone) {
        message = message + " " + guild.getEveryoneRole().getName();
    }
    if (mentionHere) {
        message = message + " here";
    }
    return message;
}
Also used : IRole(sx.blah.discord.handle.obj.IRole) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild)

Example 42 with IUser

use of sx.blah.discord.handle.obj.IUser in project DisCal-Discord-Bot by NovaFox161.

the class GuildUtils method getGuilds.

public static List<WebGuild> getGuilds(String userId) {
    List<WebGuild> guilds = new ArrayList<>();
    IUser user = Main.client.getUserByID(Long.valueOf(userId));
    for (IGuild g : Main.client.getGuilds()) {
        if (g.getUserByID(Long.valueOf(userId)) != null) {
            WebGuild wg = new WebGuild().fromGuild(g);
            wg.setManageServer(PermissionChecker.hasManageServerRole(g, user));
            wg.setDiscalRole(PermissionChecker.hasSufficientRole(g, user));
            guilds.add(wg);
        }
    }
    return guilds;
}
Also used : ArrayList(java.util.ArrayList) IUser(sx.blah.discord.handle.obj.IUser) WebGuild(com.cloudcraftgaming.discal.api.object.web.WebGuild) IGuild(sx.blah.discord.handle.obj.IGuild)

Example 43 with IUser

use of sx.blah.discord.handle.obj.IUser in project DisCal-Discord-Bot by NovaFox161.

the class Logger method debug.

public void debug(@Nullable IUser author, String message, @Nullable String info, Class clazz, boolean post) {
    String timeStamp = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss").format(Calendar.getInstance().getTime());
    if (Main.client != null) {
        if (post) {
            IUser bot = Main.getSelfUser();
            EmbedBuilder em = new EmbedBuilder();
            assert bot != null;
            em.withAuthorIcon(bot.getAvatarURL());
            if (author != null) {
                em.withAuthorName(author.getName());
                em.withThumbnail(author.getAvatarURL());
            }
            em.withColor(239, 15, 0);
            em.withFooterText(clazz.getName());
            em.appendField("Time", timeStamp, true);
            if (info != null) {
                em.appendField("Additional Info", info, true);
            }
            // Get DisCal guild and channel..
            IGuild guild = Main.client.getGuildByID(266063520112574464L);
            IChannel channel = guild.getChannelByID(302249332244217856L);
            Message.sendMessage(em.build(), "```" + message + "```", channel);
        }
    }
    // ALWAYS LOG TO FILE!
    try {
        FileWriter file = new FileWriter(debugFile, true);
        file.write("DEBUG --- " + timeStamp + " ---" + MessageUtils.lineBreak);
        if (author != null) {
            file.write("user: " + author.getName() + "#" + author.getDiscriminator() + MessageUtils.lineBreak);
        }
        if (message != null) {
            file.write("message: " + message + MessageUtils.lineBreak);
        }
        if (info != null) {
            file.write("info: " + info + MessageUtils.lineBreak);
        }
        file.close();
    } catch (IOException io) {
        io.printStackTrace();
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) FileWriter(java.io.FileWriter) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 44 with IUser

use of sx.blah.discord.handle.obj.IUser in project DisCal-Discord-Bot by NovaFox161.

the class GuildEndpoint method getUserGuilds.

public static String getUserGuilds(Request request, Response response) {
    try {
        JSONObject jsonMain = new JSONObject(request.body());
        long userId = jsonMain.getLong("USER_ID");
        IUser user = Main.client.getUserByID(userId);
        // Find all guilds user is in...
        ArrayList<IGuild> guilds = new ArrayList<>();
        for (IGuild g : Main.client.getGuilds()) {
            if (g.getUserByID(userId) != null) {
                guilds.add(g);
            }
        }
        // Get needed data
        ArrayList<JSONObject> guildData = new ArrayList<>();
        for (IGuild g : guilds) {
            JSONObject d = new JSONObject();
            d.put("GUILD_ID", g.getLongID());
            d.put("IS_OWNER", g.getOwnerLongID() == userId);
            d.put("MANAGE_SERVER", PermissionChecker.hasManageServerRole(g, user));
            d.put("DISCAL_CONTROL", PermissionChecker.hasSufficientRole(g, user));
            guildData.add(d);
        }
        JSONObject body = new JSONObject();
        body.put("USER_ID", userId);
        body.put("GUILD_COUNT", guildData.size());
        body.put("GUILDS", guildData);
        response.type("application/json");
        response.status(200);
        response.body(body.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        halt(400, "Bad Request");
    } catch (Exception e) {
        Logger.getLogger().exception(null, "[WEB-API] Internal get guilds from users error", e, GuildEndpoint.class, true);
    }
    return response.body();
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) IUser(sx.blah.discord.handle.obj.IUser) JSONException(org.json.JSONException) IGuild(sx.blah.discord.handle.obj.IGuild) JSONException(org.json.JSONException)

Example 45 with IUser

use of sx.blah.discord.handle.obj.IUser in project DiscordSailv2 by Vaerys-Dawn.

the class TopTen method execute.

@Override
public String execute(String args, CommandObject command) {
    ArrayList<ProfileObject> ranks = new ArrayList<>();
    ArrayList<String> response = new ArrayList<>();
    for (ProfileObject u : command.guild.users.getProfiles()) {
        long rank = PixelHandler.rank(command.guild.users, command.guild.get(), u.getUserID());
        if (rank <= 10 && rank != -1) {
            ranks.add(u);
        }
    }
    Utility.sortUserObjects(ranks, false);
    // format rank stats
    for (ProfileObject r : ranks) {
        IUser ranked = command.guild.getUserByID(r.getUserID());
        String rankPos = "**" + PixelHandler.rank(command.guild.users, command.guild.get(), r.getUserID()) + "** - ";
        StringBuilder toFormat = new StringBuilder(ranked.getDisplayName(command.guild.get()));
        toFormat.append("\n " + indent + "`Level: " + r.getCurrentLevel() + ", Pixels: " + NumberFormat.getInstance().format(r.getXP()) + "`");
        if (r.getUserID() == command.user.get().getLongID()) {
            response.add(rankPos + spacer + "**" + toFormat + "**");
        } else {
            response.add(rankPos + toFormat);
        }
    }
    XEmbedBuilder builder = new XEmbedBuilder(command);
    builder.withTitle("Top Ten Users for the " + command.guild.get().getName() + " Server.");
    builder.withDesc(Utility.listFormatter(response, false));
    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) ArrayList(java.util.ArrayList) IUser(sx.blah.discord.handle.obj.IUser) ProfileObject(com.github.vaerys.objects.ProfileObject)

Aggregations

IUser (sx.blah.discord.handle.obj.IUser)67 ArrayList (java.util.ArrayList)15 IGuild (sx.blah.discord.handle.obj.IGuild)13 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)13 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)9 IMessage (sx.blah.discord.handle.obj.IMessage)9 IRole (sx.blah.discord.handle.obj.IRole)8 List (java.util.List)7 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)7 IllegalCmdArgumentException (me.shadorc.shadbot.exception.IllegalCmdArgumentException)6 IChannel (sx.blah.discord.handle.obj.IChannel)6 HashMap (java.util.HashMap)5 CCommandObject (com.github.vaerys.objects.CCommandObject)4 AbstractCommand (me.shadorc.shadbot.core.command.AbstractCommand)4 CommandCategory (me.shadorc.shadbot.core.command.CommandCategory)4 Context (me.shadorc.shadbot.core.command.Context)4 Command (me.shadorc.shadbot.core.command.annotation.Command)4 BotUtils (me.shadorc.shadbot.utils.BotUtils)4 FormatUtils (me.shadorc.shadbot.utils.FormatUtils)4 TextUtils (me.shadorc.shadbot.utils.TextUtils)4