use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.
the class AnnouncementMessageFormatter method getCondensedAnnouncementEmbed.
/**
* Gets the EmbedObject for a Condensed Announcement.
* @param a The Announcement to embed.
* @return The EmbedObject for a Condensed Announcement.
*/
public static EmbedObject getCondensedAnnouncementEmbed(Announcement a, GuildSettings settings) {
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
em.withAuthorName("DisCal");
em.withTitle(MessageManager.getMessage("Embed.Announcement.Condensed.Title", settings));
em.appendField(MessageManager.getMessage("Embed.Announcement.Condensed.ID", settings), a.getAnnouncementId().toString(), false);
em.appendField(MessageManager.getMessage("Embed.Announcement.Condensed.Time", settings), condensedTime(a), false);
if (a.getAnnouncementType().equals(AnnouncementType.SPECIFIC)) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Condensed.EventID", settings), a.getEventId(), false);
try {
Calendar service;
if (settings.useExternalCalendar()) {
service = CalendarAuth.getCalendarService(settings);
} else {
service = CalendarAuth.getCalendarService();
}
// TODO: Handle multiple calendars...
CalendarData data = DatabaseManager.getManager().getMainCalendar(a.getGuildId());
Event event = service.events().get(data.getCalendarAddress(), a.getEventId()).execute();
EventData ed = DatabaseManager.getManager().getEventData(settings.getGuildID(), event.getId());
if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink())) {
em.withThumbnail(ed.getImageLink());
}
if (event.getSummary() != null) {
String summary = event.getSummary();
if (summary.length() > 250) {
summary = summary.substring(0, 250);
summary = summary + " (continues on Google Calendar View)";
}
em.appendField(MessageManager.getMessage("Embed.Announcement.Condensed.Summary", settings), summary, true);
}
} catch (Exception e) {
// Failed to get from google cal.
Logger.getLogger().exception(null, "Failed to get event for announcement.", e, AnnouncementMessageFormatter.class, true);
}
} else if (a.getAnnouncementType().equals(AnnouncementType.COLOR)) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Condensed.Color", settings), a.getEventColor().name(), true);
} else if (a.getAnnouncementType().equals(AnnouncementType.RECUR)) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Condensed.RecurID", settings), a.getEventId(), true);
}
em.withFooterText(MessageManager.getMessage("Embed.Announcement.Condensed.Type", "%type%", a.getAnnouncementType().name(), settings));
if (a.getAnnouncementType().equals(AnnouncementType.COLOR)) {
EventColor c = a.getEventColor();
em.withColor(c.getR(), c.getG(), c.getB());
} else {
em.withColor(56, 138, 237);
}
em.appendField(MessageManager.getMessage("Embed.Announcement.Info.Enabled", settings), a.isEnabled() + "", true);
return em.build();
}
use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.
the class AnnouncementMessageFormatter method sendAnnouncementDM.
static void sendAnnouncementDM(Announcement announcement, Event event, IUser user, CalendarData data, GuildSettings settings) {
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
em.withAuthorName("DisCal");
em.withTitle(MessageManager.getMessage("Embed.Announcement.Announce.Title", settings));
EventData ed = DatabaseManager.getManager().getEventData(announcement.getGuildId(), event.getId());
if (ed.getImageLink() != null && ImageUtils.validate(ed.getImageLink())) {
em.withImage(ed.getImageLink());
}
if (event.getSummary() != null) {
String summary = event.getSummary();
if (summary.length() > 250) {
summary = summary.substring(0, 250);
summary = summary + " (continues on Google Calendar View)";
}
em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Summary", settings), summary, true);
}
if (event.getDescription() != null) {
String description = event.getDescription();
if (description.length() > 250) {
description = description.substring(0, 250);
description = description + " (continues on Google Calendar View)";
}
em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Description", settings), description, true);
}
if (!settings.usingSimpleAnnouncements()) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Date", settings), EventMessageFormatter.getHumanReadableDate(event.getStart(), settings, false), true);
em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Time", settings), EventMessageFormatter.getHumanReadableTime(event.getStart(), settings, false), true);
try {
Calendar service = CalendarAuth.getCalendarService();
String tz = service.calendars().get(data.getCalendarAddress()).execute().getTimeZone();
em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.TimeZone", settings), tz, true);
} catch (Exception e1) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.TimeZone", settings), "Unknown *Error Occurred", true);
}
} else {
String start = EventMessageFormatter.getHumanReadableDate(event.getStart(), settings, false) + " at " + EventMessageFormatter.getHumanReadableTime(event.getStart(), settings, false);
try {
Calendar service = CalendarAuth.getCalendarService();
String tz = service.calendars().get(data.getCalendarAddress()).execute().getTimeZone();
start = start + " " + tz;
} catch (Exception e1) {
start = start + " (TZ UNKNOWN/ERROR)";
}
em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Start", settings), start, false);
}
if (event.getLocation() != null && !event.getLocation().equalsIgnoreCase("")) {
if (event.getLocation().length() > 300) {
String location = event.getLocation().substring(0, 300).trim() + "... (cont. on Google Cal)";
em.appendField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), location, true);
} else {
em.appendField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), event.getLocation(), true);
}
}
if (!settings.usingSimpleAnnouncements()) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.EventID", settings), event.getId(), false);
}
em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Info", settings), announcement.getInfo(), false);
em.withUrl(event.getHtmlLink());
if (!settings.usingSimpleAnnouncements()) {
em.withFooterText(MessageManager.getMessage("Embed.Announcement.Announce.ID", "%id%", announcement.getAnnouncementId().toString(), settings));
}
try {
EventColor ec = EventColor.fromNameOrHexOrID(event.getColorId());
em.withColor(ec.getR(), ec.getG(), ec.getB());
} catch (Exception e) {
// I dunno, color probably null.
em.withColor(56, 138, 237);
}
IGuild guild = Main.client.getGuildByID(announcement.getGuildId());
String msg = MessageManager.getMessage("Embed.Announcement.Announce.Dm.Message", "%guild%", guild.getName(), settings);
Message.sendDirectMessage(msg, em.build(), user);
}
use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.
the class DisCalCommand method moduleSettings.
private void moduleSettings(MessageReceivedEvent event, GuildSettings settings) {
long guildId = event.getGuild().getLongID();
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
em.withAuthorName("DisCal");
em.withTitle(MessageManager.getMessage("Embed.DisCal.Settings.Title", settings));
em.appendField(MessageManager.getMessage("Embed.DisCal.Settings.ExternalCal", settings), String.valueOf(settings.useExternalCalendar()), true);
if (RoleUtils.roleExists(settings.getControlRole(), event)) {
em.appendField(MessageManager.getMessage("Embed.Discal.Settings.Role", settings), RoleUtils.getRoleNameFromID(settings.getControlRole(), event), true);
} else {
em.appendField(MessageManager.getMessage("Embed.Discal.Settings.Role", settings), "everyone", true);
}
if (ChannelUtils.channelExists(settings.getDiscalChannel(), event)) {
em.appendField(MessageManager.getMessage("Embed.DisCal.Settings.Channel", settings), ChannelUtils.getChannelNameFromNameOrId(settings.getDiscalChannel(), guildId), false);
} else {
em.appendField(MessageManager.getMessage("Embed.DisCal.Settings.Channel", settings), "All Channels", true);
}
em.appendField(MessageManager.getMessage("Embed.DisCal.Settings.SimpleAnn", settings), String.valueOf(settings.usingSimpleAnnouncements()), true);
em.appendField(MessageManager.getMessage("Embed.DisCal.Settings.Patron", settings), String.valueOf(settings.isPatronGuild()), true);
em.appendField(MessageManager.getMessage("Embed.DisCal.Settings.Dev", settings), String.valueOf(settings.isDevGuild()), true);
em.appendField(MessageManager.getMessage("Embed.DisCal.Settings.MaxCal", settings), String.valueOf(settings.getMaxCalendars()), true);
em.appendField(MessageManager.getMessage("Embed.DisCal.Settings.Language", settings), settings.getLang(), true);
em.appendField(MessageManager.getMessage("Embed.DisCal.Settings.Prefix", settings), settings.getPrefix(), true);
// TODO: Add translations...
em.appendField("Using Branding", settings.isBranded() + "", true);
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);
}
use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.
the class HelpCommand method getCommandInfoEmbed.
// Embed formatters
private EmbedObject getCommandInfoEmbed(ICommand cmd) {
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
em.withAuthorName("DisCal");
em.appendField("Command", cmd.getCommand(), true);
em.appendField("Description", cmd.getCommandInfo().getDescription(), true);
em.appendField("Example", cmd.getCommandInfo().getExample(), true);
// Loop through sub commands
if (cmd.getCommandInfo().getSubCommands().size() > 0) {
String subs = cmd.getCommandInfo().getSubCommands().keySet().toString();
subs = subs.replace("[", "").replace("]", "");
em.appendField("Sub-Commands", subs, false);
}
em.withFooterText("<> = required | () = optional");
em.withUrl("https://www.cloudcraftgaming.com/discal/commands");
em.withColor(56, 138, 237);
return em.build();
}
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();
}
Aggregations