Search in sources :

Example 6 with IUser

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

the class DashboardHandler method handleGuildSelect.

public static String handleGuildSelect(Request request, Response response) {
    try {
        String guildId = request.queryParams("guild");
        IGuild g = Main.client.getGuildByID(Long.valueOf(guildId));
        WebGuild wg = new WebGuild().fromGuild(g);
        Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
        IUser u = g.getUserByID(Long.valueOf((String) m.get("id")));
        wg.setDiscalRole(PermissionChecker.hasSufficientRole(g, u));
        wg.setManageServer(PermissionChecker.hasManageServerRole(g, u));
        m.remove("selected");
        m.put("selected", wg);
        m.remove("settings");
        m.remove("admin");
        DiscordAccountHandler.getHandler().appendAccount(m, request.session().id());
        response.redirect("/dashboard/guild", 301);
    } catch (JSONException e) {
        Logger.getLogger().exception(null, "[WEB] JSON || Guild Select failed!", e, DashboardHandler.class, true);
        response.redirect("/dashboard", 301);
    } catch (Exception e) {
        Logger.getLogger().exception(null, "[WEB] Guild Select failed!", e, DashboardHandler.class, true);
        halt(500, "Internal Server Exception");
    }
    return response.body();
}
Also used : IUser(sx.blah.discord.handle.obj.IUser) JSONException(org.json.JSONException) WebGuild(com.cloudcraftgaming.discal.api.object.web.WebGuild) IGuild(sx.blah.discord.handle.obj.IGuild) HashMap(java.util.HashMap) Map(java.util.Map) JSONException(org.json.JSONException)

Example 7 with IUser

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

the class RsvpCommand method getRsvpEmbed.

private EmbedObject getRsvpEmbed(RsvpData data, GuildSettings settings) {
    EmbedBuilder em = new EmbedBuilder();
    em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
    em.withAuthorName("DisCal");
    em.withTitle(MessageManager.getMessage("Embed.RSVP.List.Title", settings));
    em.appendField("Event ID", data.getEventId(), false);
    IGuild g = Main.client.getGuildByID(settings.getGuildID());
    StringBuilder onTime = new StringBuilder();
    for (IUser u : UserUtils.getUsers(data.getGoingOnTime(), g)) {
        onTime.append(u.getName()).append(", ");
    }
    StringBuilder late = new StringBuilder();
    for (IUser u : UserUtils.getUsers(data.getGoingLate(), g)) {
        late.append(u.getName()).append(", ");
    }
    StringBuilder unsure = new StringBuilder();
    for (IUser u : UserUtils.getUsers(data.getUndecided(), g)) {
        unsure.append(u.getName()).append(", ");
    }
    StringBuilder notGoing = new StringBuilder();
    for (IUser u : UserUtils.getUsers(data.getNotGoing(), g)) {
        notGoing.append(u.getName()).append(", ");
    }
    if (onTime.toString().isEmpty()) {
        em.appendField("On time", "N/a", true);
    } else {
        em.appendField("On Time", onTime.toString(), true);
    }
    if (late.toString().isEmpty()) {
        em.appendField("Late", "N/a", true);
    } else {
        em.appendField("Late", late.toString(), true);
    }
    if (unsure.toString().isEmpty()) {
        em.appendField("Unsure", "N/a", true);
    } else {
        em.appendField("Unsure", unsure.toString(), true);
    }
    if (notGoing.toString().isEmpty()) {
        em.appendField("Not Going", "N/a", true);
    } else {
        em.appendField("Not Going", notGoing.toString(), true);
    }
    em.withFooterText(MessageManager.getMessage("Embed.RSVP.List.Footer", settings));
    em.withColor(56, 138, 237);
    return em.build();
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild)

Example 8 with IUser

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

the class UserUtils method getUser.

/**
 * Grabs a user from a string
 *
 * @param toLookFor The String to look with
 * @param guild     The guild
 * @return The user if found, null otherwise
 */
public static long getUser(String toLookFor, IGuild guild) {
    toLookFor = GeneralUtils.trim(toLookFor);
    final String lower = toLookFor.toLowerCase();
    if (lower.matches("@!?[0-9]+") || lower.matches("[0-9]+")) {
        final String parse = toLookFor.replaceAll("[<@!>]", "");
        IUser exists = guild.getUserByID(Long.parseLong(toLookFor.replaceAll("[<@!>]", "")));
        if (exists != null) {
            return exists.getLongID();
        }
    }
    List<IUser> users = new ArrayList<>();
    List<IUser> us = guild.getUsers();
    users.addAll(us.stream().filter(u -> u.getName().equalsIgnoreCase(lower)).collect(Collectors.toList()));
    users.addAll(us.stream().filter(u -> u.getName().toLowerCase().contains(lower)).collect(Collectors.toList()));
    users.addAll(us.stream().filter(u -> (u.getName() + "#" + u.getDiscriminator()).equalsIgnoreCase(lower)).collect(Collectors.toList()));
    users.addAll(us.stream().filter(u -> u.getDiscriminator().equalsIgnoreCase(lower)).collect(Collectors.toList()));
    users.addAll(us.stream().filter(u -> u.getDisplayName(guild).equalsIgnoreCase(lower)).collect(Collectors.toList()));
    users.addAll(us.stream().filter(u -> u.getDisplayName(guild).toLowerCase().contains(lower)).collect(Collectors.toList()));
    if (!users.isEmpty()) {
        return users.get(0).getLongID();
    }
    return 0;
}
Also used : ArrayList(java.util.ArrayList) IUser(sx.blah.discord.handle.obj.IUser)

Example 9 with IUser

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

the class UserUtils method getIUser.

public static IUser getIUser(String toLookFor, IMessage m, IGuild guild) {
    toLookFor = toLookFor.trim();
    final String lower = toLookFor.toLowerCase();
    IUser res = null;
    if (m != null && !m.getMentions().isEmpty())
        res = m.getMentions().get(0);
    if (toLookFor.matches("<@!?[0-9]+>")) {
        IUser u = guild.getUserByID(Long.parseUnsignedLong(toLookFor.replaceAll("[^0-9]", "")));
        if (u != null) {
            return u;
        }
    }
    List<IUser> users = guild.getUsers().stream().filter(u -> u.getName().toLowerCase().contains(lower) || u.getName().equalsIgnoreCase(lower) || u.getStringID().equals(lower) || u.getDisplayName(guild).toLowerCase().contains(lower) || u.getDisplayName(guild).equalsIgnoreCase(lower)).collect(Collectors.toList());
    if (!users.isEmpty())
        res = users.get(0);
    return res;
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage) IGuild(sx.blah.discord.handle.obj.IGuild) IUser(sx.blah.discord.handle.obj.IUser) List(java.util.List) GeneralUtils(com.cloudcraftgaming.discal.api.utils.GeneralUtils) Collectors(java.util.stream.Collectors) MessageReceivedEvent(sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent) ArrayList(java.util.ArrayList) IUser(sx.blah.discord.handle.obj.IUser)

Example 10 with IUser

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

the class Logger method exception.

public void exception(@Nullable IUser author, @Nullable String message, Exception e, Class clazz, boolean post) {
    String timeStamp = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime());
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    // stack trace as a string
    String error = sw.toString();
    pw.close();
    try {
        sw.close();
    } catch (IOException e1) {
    // Can ignore silently...
    }
    if (Main.getSelfUser() != null) {
        IUser bot = Main.getSelfUser();
        if (post) {
            String shortError = error;
            if (error.length() > 1250) {
                shortError = error.substring(0, 1250);
            }
            EmbedBuilder em = new EmbedBuilder();
            if (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());
            // Send to discord!
            em.appendField("Time", timeStamp, true);
            if (e.getMessage() != null) {
                if (e.getMessage().length() > 1024) {
                    em.appendField("Exception", e.getMessage().substring(0, 1024), true);
                } else {
                    em.appendField("Exception", e.getMessage(), true);
                }
            }
            if (message != null) {
                em.appendField("Message", message, true);
            }
            // Get DisCal guild and channel..
            IGuild guild = Main.client.getGuildByID(266063520112574464L);
            IChannel channel = guild.getChannelByID(302249332244217856L);
            Message.sendMessage(em.build(), "```" + shortError + "```", channel);
        }
    }
    // ALWAYS LOG TO FILE!
    try {
        FileWriter exceptions = new FileWriter(exceptionsFile, true);
        exceptions.write("ERROR --- " + timeStamp + " ---" + MessageUtils.lineBreak);
        if (author != null) {
            exceptions.write("user: " + author.getName() + "#" + author.getDiscriminator() + MessageUtils.lineBreak);
        }
        if (message != null) {
            exceptions.write("message: " + message + MessageUtils.lineBreak);
        }
        exceptions.write(error + MessageUtils.lineBreak);
        exceptions.close();
    } catch (IOException io) {
        io.printStackTrace();
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) IUser(sx.blah.discord.handle.obj.IUser) IOException(java.io.IOException) IGuild(sx.blah.discord.handle.obj.IGuild) SimpleDateFormat(java.text.SimpleDateFormat) PrintWriter(java.io.PrintWriter)

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