use of sx.blah.discord.util.EmbedBuilder 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();
}
use of sx.blah.discord.util.EmbedBuilder 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();
}
}
use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.
the class CalendarMessageFormatter method getCalendarLinkEmbed.
public static EmbedObject getCalendarLinkEmbed(Calendar cal, GuildSettings settings) {
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
em.withAuthorName("DisCal");
em.withTitle(MessageManager.getMessage("Embed.Calendar.Link.Title", settings));
em.appendField(MessageManager.getMessage("Embed.Calendar.Link.Summary", settings), cal.getSummary(), true);
try {
em.appendField(MessageManager.getMessage("Embed.Calendar.Link.Description", settings), cal.getDescription(), true);
} catch (NullPointerException | IllegalArgumentException e) {
// Some error, desc probably never set, just ignore no need to log.
}
em.appendField(MessageManager.getMessage("Embed.Calendar.Link.TimeZone", settings), cal.getTimeZone(), false);
em.withUrl(CalendarMessageFormatter.getCalendarLink(cal.getId()));
em.withFooterText(MessageManager.getMessage("Embed.Calendar.Link.CalendarId", "%id%", cal.getId(), settings));
em.withColor(56, 138, 237);
return em.build();
}
use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.
the class EventMessageFormatter method getEventEmbed.
/**
* Gets an EmbedObject for the specified event.
*
* @param event The event involved.
* @param settings The guild's settings
* @return The EmbedObject of the event.
*/
public static EmbedObject getEventEmbed(Event event, GuildSettings settings) {
EventData ed = DatabaseManager.getManager().getEventData(settings.getGuildID(), event.getId());
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
em.withAuthorName("DisCal");
em.withTitle(MessageManager.getMessage("Embed.Event.Info.Title", settings));
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.Event.Info.Summary", settings), summary, true);
}
if (event.getDescription() != null) {
String description = event.getDescription();
if (description.length() > 500) {
description = description.substring(0, 500);
description = description + " (continues on Google Calendar View)";
}
em.appendField(MessageManager.getMessage("Embed.Event.Info.Description", settings), description, true);
}
em.appendField(MessageManager.getMessage("Embed.Event.Info.StartDate", settings), getHumanReadableDate(event.getStart(), settings, false), true);
em.appendField(MessageManager.getMessage("Embed.Event.Info.StartTime", settings), getHumanReadableTime(event.getStart(), settings, false), true);
em.appendField(MessageManager.getMessage("Embed.Event.Info.EndDate", settings), getHumanReadableDate(event.getEnd(), settings, false), true);
em.appendField(MessageManager.getMessage("Embed.Event.Info.EndTime", settings), getHumanReadableTime(event.getEnd(), settings, false), true);
try {
// TODO: add support for multiple calendars...
CalendarData data = DatabaseManager.getManager().getMainCalendar(settings.getGuildID());
Calendar service;
service = settings.useExternalCalendar() ? CalendarAuth.getCalendarService(settings) : CalendarAuth.getCalendarService();
String tz = service.calendars().get(data.getCalendarAddress()).execute().getTimeZone();
em.appendField(MessageManager.getMessage("Embed.Event.Info.TimeZone", settings), tz, true);
} catch (Exception e1) {
em.appendField(MessageManager.getMessage("Embed.Event.Info.TimeZone", settings), "Error/Unknown", true);
}
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);
}
}
// TODO: Add info on recurrence here.
em.withUrl(event.getHtmlLink());
em.withFooterText(MessageManager.getMessage("Embed.Event.Info.ID", "%id%", event.getId(), settings));
try {
EventColor ec = EventColor.fromId(Integer.valueOf(event.getColorId()));
em.withColor(ec.getR(), ec.getG(), ec.getB());
} catch (Exception e) {
// Color is null, ignore and add our default.
em.withColor(56, 138, 237);
}
return em.build();
}
use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.
the class EventMessageFormatter method getPreEventEmbed.
/**
* Gets an EmbedObject for the specified PreEvent.
*
* @param event The PreEvent to get an embed for.
* @return The EmbedObject of the PreEvent.
*/
public static EmbedObject getPreEventEmbed(PreEvent event, GuildSettings settings) {
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
em.withAuthorName("DisCal");
em.withTitle(MessageManager.getMessage("Embed.Event.Pre.Title", settings));
if (event.getEventData() != null && event.getEventData().getImageLink() != null && ImageUtils.validate(event.getEventData().getImageLink())) {
em.withImage(event.getEventData().getImageLink());
}
if (event.isEditing()) {
em.appendField(MessageManager.getMessage("Embed.Event.Pre.Id", settings), event.getEventId(), false);
}
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.Event.Pre.Summary", settings), summary, true);
} else {
em.appendField(MessageManager.getMessage("Embed.Event.Pre.Summary", settings), "NOT SET", true);
}
if (event.getDescription() != null) {
String description = event.getDescription();
if (description.length() > 500) {
description = description.substring(0, 500);
description = description + " (continues on Google Calendar View)";
}
em.appendField(MessageManager.getMessage("Embed.Event.Pre.Description", settings), description, true);
} else {
em.appendField(MessageManager.getMessage("Embed.Event.Pre.Description", settings), "NOT SET", true);
}
if (event.shouldRecur()) {
em.appendField(MessageManager.getMessage("Embed.Event.Pre.Recurrence", settings), event.getRecurrence().toHumanReadable(), true);
} else {
em.appendField(MessageManager.getMessage("Embed.Event.Pre.Recurrence", settings), "N/a", true);
}
em.appendField(MessageManager.getMessage("Embed.Event.Pre.StartDate", settings), getHumanReadableDate(event.getViewableStartDate(), settings, true), true);
em.appendField(MessageManager.getMessage("Embed.Event.Pre.StartTime", settings), EventMessageFormatter.getHumanReadableTime(event.getViewableStartDate(), settings, true), true);
em.appendField(MessageManager.getMessage("Embed.Event.Pre.EndDate", settings), getHumanReadableDate(event.getViewableEndDate(), settings, true), true);
em.appendField(MessageManager.getMessage("Embed.Event.Pre.EndTime", settings), EventMessageFormatter.getHumanReadableTime(event.getViewableEndDate(), settings, true), true);
em.appendField(MessageManager.getMessage("Embed.Event.Pre.TimeZone", settings), event.getTimeZone(), true);
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);
}
} else {
em.appendField(MessageManager.getMessage("Embed.Event.Confirm.Location", settings), "N/a", true);
}
em.withFooterText(MessageManager.getMessage("Embed.Event.Pre.Key", settings));
EventColor ec = event.getColor();
em.withColor(ec.getR(), ec.getG(), ec.getB());
return em.build();
}
Aggregations