Search in sources :

Example 16 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project KaellyBot by Kaysoro.

the class Set method getMoreEmbedObject.

@Override
public EmbedObject getMoreEmbedObject(Language lg) {
    EmbedBuilder builder = new EmbedBuilder();
    builder.withTitle(name);
    builder.withUrl(url);
    builder.withColor(new Random().nextInt(16777216));
    builder.withImage(skinURL);
    if (level != null && !level.isEmpty())
        builder.appendField(Translator.getLabel(lg, "set.level"), level, true);
    if (composition != null && !composition.isEmpty())
        builder.appendField(Translator.getLabel(lg, "set.composition"), composition, true);
    if (bonusTotal != null && !bonusTotal.isEmpty())
        for (int i = 0; i < bonusTotal.size(); i++) builder.appendField(Translator.getLabel(lg, "set.bonus.total") + (bonusTotal.size() > 1 ? " (" + (i + 1) + "/" + bonusTotal.size() + ")" : "") + " : ", bonusTotal.get(i), true);
    if (!recipeTotal.isEmpty())
        for (int i = 0; i < recipeTotal.size(); i++) builder.appendField(Translator.getLabel(lg, "set.recipe") + (recipeTotal.size() > 1 ? " (" + (i + 1) + "/" + recipeTotal.size() + ")" : "") + " : ", recipeTotal.get(i), true);
    for (int i = 0; i < bonusPano.length; i++) builder.appendField(Translator.getLabel(lg, "set.bonus.1") + " " + (i + 2) + " " + Translator.getLabel(lg, "set.bonus.2"), bonusPano[i], true);
    return builder.build();
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Random(java.util.Random)

Example 17 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.

the class CalendarMessageFormatter method getPreCalendarEmbed.

/**
 * Creates an EmbedObject for the PreCalendar.
 *
 * @param calendar The PreCalendar to create an EmbedObject for.
 * @return The EmbedObject for the PreCalendar.
 */
public static EmbedObject getPreCalendarEmbed(PreCalendar calendar, GuildSettings settings) {
    EmbedBuilder em = new EmbedBuilder();
    em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
    em.withAuthorName("DisCal");
    em.withTitle(MessageManager.getMessage("Embed.Calendar.Pre.Title", settings));
    if (calendar.getSummary() != null) {
        em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.Summary", settings), calendar.getSummary(), true);
    } else {
        em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.Summary", settings), "***UNSET***", true);
    }
    if (calendar.getDescription() != null) {
        em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.Description", settings), calendar.getDescription(), false);
    } else {
        em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.Description", settings), "***UNSET***", false);
    }
    if (calendar.getTimezone() != null) {
        em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.TimeZone", settings), calendar.getTimezone(), true);
    } else {
        em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.TimeZone", settings), "***UNSET***", true);
    }
    if (calendar.isEditing()) {
        em.appendField(MessageManager.getMessage("Embed.Calendar.Pre.CalendarId", settings), calendar.getCalendarId(), false);
    }
    // No else needed, just don't post it.
    em.withFooterText(MessageManager.getMessage("Embed.Calendar.Pre.Key", settings));
    em.withColor(56, 138, 237);
    return em.build();
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder)

Example 18 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.

the class Authorization method requestCode.

public void requestCode(MessageReceivedEvent event, GuildSettings settings) {
    try {
        String body = "client_id=" + clientData.getClientId() + "&scope=" + CalendarScopes.CALENDAR;
        com.mashape.unirest.http.HttpResponse<JsonNode> response = Unirest.post("https://accounts.google.com/o/oauth2/device/code").header("Content-Type", "application/x-www-form-urlencoded").body(body).asJson();
        if (response.getStatus() == HttpStatusCodes.STATUS_CODE_OK) {
            Type type = new TypeToken<CodeResponse>() {
            }.getType();
            CodeResponse cr = new Gson().fromJson(response.getBody().toString(), type);
            // Send DM to user with code.
            EmbedBuilder em = new EmbedBuilder();
            em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
            em.withAuthorName("DisCal");
            em.withTitle(MessageManager.getMessage("Embed.AddCalendar.Code.Title", settings));
            em.appendField(MessageManager.getMessage("Embed.AddCalendar.Code.Code", settings), cr.user_code, true);
            em.withFooterText(MessageManager.getMessage("Embed.AddCalendar.Code.Footer", settings));
            em.withUrl(cr.verification_url);
            em.withColor(36, 153, 153);
            IUser user = event.getAuthor();
            Message.sendDirectMessage(MessageManager.getMessage("AddCalendar.Auth.Code.Request.Success", settings), em.build(), user);
            // Start timer to poll Google Cal for auth
            Poll poll = new Poll(user, event.getGuild());
            poll.setDevice_code(cr.device_code);
            poll.setRemainingSeconds(cr.expires_in);
            poll.setExpires_in(cr.expires_in);
            poll.setInterval(cr.interval);
            pollForAuth(poll);
        } else {
            Message.sendDirectMessage(MessageManager.getMessage("AddCalendar.Auth.Code.Request.Failure.NotOkay", settings), event.getAuthor());
            Logger.getLogger().debug(event.getAuthor(), "Error requesting access token.", "Status code: " + response.getStatus() + " | " + response.getStatusText() + " | " + response.getBody().toString(), this.getClass(), true);
        }
    } catch (Exception e) {
        // Failed, report issue to dev.
        Logger.getLogger().exception(event.getAuthor(), "Failed to request Google Access Code", e, this.getClass(), true);
        IUser u = event.getAuthor();
        Message.sendDirectMessage(MessageManager.getMessage("AddCalendar.Auth.Code.Request.Failure.Unknown", settings), u);
    }
}
Also used : CodeResponse(com.cloudcraftgaming.discal.api.object.json.google.CodeResponse) Gson(com.google.gson.Gson) JsonNode(com.mashape.unirest.http.JsonNode) IOException(java.io.IOException) Type(java.lang.reflect.Type) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IUser(sx.blah.discord.handle.obj.IUser) Poll(com.cloudcraftgaming.discal.api.object.network.google.Poll)

Example 19 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.

the class DevCommand method moduleEval.

@SuppressWarnings("all")
private void moduleEval(MessageReceivedEvent event) {
    IGuild guild = event.getGuild();
    IUser user = event.getAuthor();
    IMessage message = event.getMessage();
    IDiscordClient client = event.getClient();
    IChannel channel = event.getChannel();
    String input = message.getContent().substring(message.getContent().indexOf("eval") + 5).replaceAll("`", "");
    Object o = null;
    factory.put("guild", guild);
    factory.put("channel", channel);
    factory.put("user", user);
    factory.put("message", message);
    factory.put("command", this);
    factory.put("client", client);
    factory.put("builder", new EmbedBuilder());
    factory.put("cUser", client.getOurUser());
    try {
        o = factory.eval(input);
    } catch (Exception ex) {
        EmbedBuilder em = new EmbedBuilder();
        em.withAuthorIcon(guild.getIconURL());
        em.withAuthorName("Error");
        em.withDesc(ex.getMessage());
        em.withFooterText("Eval failed");
        em.withColor(56, 138, 237);
        Message.sendMessage(em.build(), channel);
        return;
    }
    EmbedBuilder em = new EmbedBuilder();
    em.withAuthorIcon(guild.getIconURL());
    em.withAuthorName("Success!");
    em.withColor(56, 138, 237);
    em.withTitle("Evaluation output.");
    em.withDesc(o == null ? "No output, object is null" : o.toString());
    em.appendField("Input", "```java\n" + input + "\n```", false);
    em.withFooterText("Eval successful!");
    Message.sendMessage(em.build(), channel);
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) IMessage(sx.blah.discord.handle.obj.IMessage) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild) IDiscordClient(sx.blah.discord.api.IDiscordClient) DiscordException(sx.blah.discord.util.DiscordException)

Example 20 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.

the class DisCalCommand method moduleDisCalInfo.

private void moduleDisCalInfo(MessageReceivedEvent event, GuildSettings settings) {
    IGuild guild = event.getGuild();
    EmbedBuilder em = new EmbedBuilder();
    em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
    em.withAuthorName("DisCal!");
    em.withTitle(MessageManager.getMessage("Embed.DisCal.Info.Title", settings));
    em.appendField(MessageManager.getMessage("Embed.DisCal.Info.Developer", settings), "NovaFox161", true);
    em.appendField(MessageManager.getMessage("Embed.Discal.Info.Version", settings), Main.version, true);
    em.appendField(MessageManager.getMessage("Embed.DisCal.Info.Library", settings), "Discord4J, version 2.9.2", false);
    em.appendField(MessageManager.getMessage("Embed.DisCal.Info.TotalGuilds", settings), Main.client.getGuilds().size() + "", true);
    em.appendField(MessageManager.getMessage("Embed.DisCal.Info.TotalCalendars", settings), DatabaseManager.getManager().getCalendarCount() + "", true);
    em.appendField(MessageManager.getMessage("Embed.DisCal.Info.TotalAnnouncements", settings), DatabaseManager.getManager().getAnnouncementCount() + "", true);
    if (BotSettings.RUN_API.get().equalsIgnoreCase("True")) {
        // TODO: Add to translations
        em.appendField("Users in Dashboard", DiscordAccountHandler.getHandler().accountCount() + "", true);
    }
    em.appendField(MessageManager.getMessage("Embed.DisCal.Info.Ping", "%shard%", (guild.getShard().getInfo()[0] + 1) + "/" + Main.client.getShardCount(), settings), guild.getShard().getResponseTime() + "ms", false);
    em.withFooterText(MessageManager.getMessage("Embed.DisCal.Info.Patron", settings) + ": https://www.patreon.com/Novafox");
    em.withUrl("https://www.cloudcraftgaming.com/discal/");
    em.withColor(56, 138, 237);
    Message.sendMessage(em.build(), event);
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IGuild(sx.blah.discord.handle.obj.IGuild)

Aggregations

EmbedBuilder (sx.blah.discord.util.EmbedBuilder)103 IOException (java.io.IOException)19 Random (java.util.Random)17 IUser (sx.blah.discord.handle.obj.IUser)14 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)13 LoadingMessage (me.shadorc.shadbot.utils.object.LoadingMessage)13 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)12 JSONObject (org.json.JSONObject)11 IMessage (sx.blah.discord.handle.obj.IMessage)10 List (java.util.List)9 AbstractCommand (me.shadorc.shadbot.core.command.AbstractCommand)9 EmbedUtils (me.shadorc.shadbot.utils.embed.EmbedUtils)9 JSONException (org.json.JSONException)9 EventColor (com.cloudcraftgaming.discal.api.enums.event.EventColor)8 Utils (me.shadorc.shadbot.utils.Utils)8 IChannel (sx.blah.discord.handle.obj.IChannel)8 EventData (com.cloudcraftgaming.discal.api.object.event.EventData)7 FormatUtils (me.shadorc.shadbot.utils.FormatUtils)7 File (java.io.File)6 CommandCategory (me.shadorc.shadbot.core.command.CommandCategory)6