use of sx.blah.discord.handle.obj.IGuild 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);
}
use of sx.blah.discord.handle.obj.IGuild in project DisCal-Discord-Bot by NovaFox161.
the class AnnouncementMessageFormatter method sendAnnouncementMessage.
/**
* Sends an embed with the announcement info in a proper format.
*
* @param announcement The announcement to send info about.
* @param event the calendar event the announcement is for.
* @param data The BotData belonging to the guild.
*/
static void sendAnnouncementMessage(Announcement announcement, Event event, CalendarData data, GuildSettings settings) {
EmbedBuilder em = new EmbedBuilder();
em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
IGuild guild = Main.client.getGuildByID(announcement.getGuildId());
assert guild != null;
// Set all of the stuff for embeds regardless of announcement settings
if (settings.isBranded()) {
em.withAuthorName(guild.getName());
} else {
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());
}
em.withUrl(event.getHtmlLink());
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);
}
if (!settings.usingSimpleAnnouncements()) {
em.withFooterText(MessageManager.getMessage("Embed.Announcement.Announce.ID", "%id%", announcement.getAnnouncementId().toString(), settings));
}
if (announcement.isInfoOnly()) {
// Only send info...
em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Info", settings), announcement.getInfo(), false);
} else {
// Requires all announcement data
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);
}
if (!announcement.getInfo().equalsIgnoreCase("None")) {
em.appendField(MessageManager.getMessage("Embed.Announcement.Announce.Info", settings), announcement.getInfo(), false);
}
}
IChannel channel = null;
try {
channel = guild.getChannelByID(Long.valueOf(announcement.getAnnouncementChannelId()));
} catch (Exception e) {
Logger.getLogger().exception(null, "Failed to find announcement channel! Will auto delete announcement to prevent issue! | Announcement: " + announcement.getAnnouncementId() + " | Guild: " + announcement.getGuildId(), e, AnnouncementMessageFormatter.class, true);
}
if (channel == null) {
// Channel does not exist or could not be found, automatically delete announcement to prevent issues.
DatabaseManager.getManager().deleteAnnouncement(announcement.getAnnouncementId().toString());
return;
}
Message.sendMessageAsync(em.build(), getSubscriberMentions(announcement, guild), channel);
}
use of sx.blah.discord.handle.obj.IGuild 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();
}
use of sx.blah.discord.handle.obj.IGuild 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.handle.obj.IGuild 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;
}
Aggregations