use of sx.blah.discord.handle.obj.IUser 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.IUser 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.IUser in project DisCal-Discord-Bot by NovaFox161.
the class UserUtils method getUser.
/**
* Grabs a user from a string
*
* @param toLookFor The String to look with
* @param guild The guild
* @return The user if found, null otherwise
*/
public static long getUser(String toLookFor, IGuild guild) {
toLookFor = GeneralUtils.trim(toLookFor);
final String lower = toLookFor.toLowerCase();
if (lower.matches("@!?[0-9]+") || lower.matches("[0-9]+")) {
final String parse = toLookFor.replaceAll("[<@!>]", "");
IUser exists = guild.getUserByID(Long.parseLong(toLookFor.replaceAll("[<@!>]", "")));
if (exists != null) {
return exists.getLongID();
}
}
List<IUser> users = new ArrayList<>();
List<IUser> us = guild.getUsers();
users.addAll(us.stream().filter(u -> u.getName().equalsIgnoreCase(lower)).collect(Collectors.toList()));
users.addAll(us.stream().filter(u -> u.getName().toLowerCase().contains(lower)).collect(Collectors.toList()));
users.addAll(us.stream().filter(u -> (u.getName() + "#" + u.getDiscriminator()).equalsIgnoreCase(lower)).collect(Collectors.toList()));
users.addAll(us.stream().filter(u -> u.getDiscriminator().equalsIgnoreCase(lower)).collect(Collectors.toList()));
users.addAll(us.stream().filter(u -> u.getDisplayName(guild).equalsIgnoreCase(lower)).collect(Collectors.toList()));
users.addAll(us.stream().filter(u -> u.getDisplayName(guild).toLowerCase().contains(lower)).collect(Collectors.toList()));
if (!users.isEmpty()) {
return users.get(0).getLongID();
}
return 0;
}
use of sx.blah.discord.handle.obj.IUser 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;
}
use of sx.blah.discord.handle.obj.IUser 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();
}
}
Aggregations