use of sx.blah.discord.handle.obj.IGuild in project DisCal-Discord-Bot by NovaFox161.
the class AnnouncementMessageFormatter method getSubscriberNames.
public static String getSubscriberNames(Announcement a) {
// Loop and get subs without mentions...
IGuild guild = Main.client.getGuildByID(a.getGuildId());
StringBuilder userMentions = new StringBuilder();
for (String userId : a.getSubscriberUserIds()) {
try {
IUser user = guild.getUserByID(Long.valueOf(userId));
if (user != null) {
userMentions.append(user.getName()).append(" ");
}
} catch (Exception e) {
// User does not exist, safely ignore.
}
}
StringBuilder roleMentions = new StringBuilder();
Boolean mentionEveryone = false;
Boolean mentionHere = false;
for (String roleId : a.getSubscriberRoleIds()) {
if (roleId.equalsIgnoreCase("everyone")) {
mentionEveryone = true;
} else if (roleId.equalsIgnoreCase("here")) {
mentionHere = true;
} else {
try {
IRole role = guild.getRoleByID(Long.valueOf(roleId));
if (role != null) {
roleMentions.append(role.getName()).append(" ");
}
} catch (Exception e) {
// Role does not exist, safely ignore.
}
}
}
String message = "Subscribers: " + userMentions + " " + roleMentions;
if (mentionEveryone) {
message = message + " " + guild.getEveryoneRole().getName();
}
if (mentionHere) {
message = message + " here";
}
return message;
}
use of sx.blah.discord.handle.obj.IGuild 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.handle.obj.IGuild in project DisCal-Discord-Bot by NovaFox161.
the class GuildUtils method getGuilds.
public static List<WebGuild> getGuilds(String userId) {
List<WebGuild> guilds = new ArrayList<>();
IUser user = Main.client.getUserByID(Long.valueOf(userId));
for (IGuild g : Main.client.getGuilds()) {
if (g.getUserByID(Long.valueOf(userId)) != null) {
WebGuild wg = new WebGuild().fromGuild(g);
wg.setManageServer(PermissionChecker.hasManageServerRole(g, user));
wg.setDiscalRole(PermissionChecker.hasSufficientRole(g, user));
guilds.add(wg);
}
}
return guilds;
}
use of sx.blah.discord.handle.obj.IGuild in project DisCal-Discord-Bot by NovaFox161.
the class Logger method debug.
public void debug(@Nullable IUser author, String message, @Nullable String info, Class clazz, boolean post) {
String timeStamp = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss").format(Calendar.getInstance().getTime());
if (Main.client != null) {
if (post) {
IUser bot = Main.getSelfUser();
EmbedBuilder em = new EmbedBuilder();
assert 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());
em.appendField("Time", timeStamp, true);
if (info != null) {
em.appendField("Additional Info", info, true);
}
// Get DisCal guild and channel..
IGuild guild = Main.client.getGuildByID(266063520112574464L);
IChannel channel = guild.getChannelByID(302249332244217856L);
Message.sendMessage(em.build(), "```" + message + "```", channel);
}
}
// ALWAYS LOG TO FILE!
try {
FileWriter file = new FileWriter(debugFile, true);
file.write("DEBUG --- " + timeStamp + " ---" + MessageUtils.lineBreak);
if (author != null) {
file.write("user: " + author.getName() + "#" + author.getDiscriminator() + MessageUtils.lineBreak);
}
if (message != null) {
file.write("message: " + message + MessageUtils.lineBreak);
}
if (info != null) {
file.write("info: " + info + MessageUtils.lineBreak);
}
file.close();
} catch (IOException io) {
io.printStackTrace();
}
}
use of sx.blah.discord.handle.obj.IGuild in project lavaplayer by sedmelluq.
the class Main method onMessageReceived.
@EventSubscriber
public void onMessageReceived(MessageReceivedEvent event) {
IMessage message = event.getMessage();
String[] command = message.getContent().split(" ", 2);
IGuild guild = message.getGuild();
if (guild != null) {
if ("~play".equals(command[0]) && command.length == 2) {
loadAndPlay(message.getChannel(), command[1]);
} else if ("~skip".equals(command[0])) {
skipTrack(message.getChannel());
}
}
}
Aggregations