use of sx.blah.discord.handle.obj.IUser 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.IUser 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.IUser 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.IUser in project DisCal-Discord-Bot by NovaFox161.
the class GuildEndpoint method getUserGuilds.
public static String getUserGuilds(Request request, Response response) {
try {
JSONObject jsonMain = new JSONObject(request.body());
long userId = jsonMain.getLong("USER_ID");
IUser user = Main.client.getUserByID(userId);
// Find all guilds user is in...
ArrayList<IGuild> guilds = new ArrayList<>();
for (IGuild g : Main.client.getGuilds()) {
if (g.getUserByID(userId) != null) {
guilds.add(g);
}
}
// Get needed data
ArrayList<JSONObject> guildData = new ArrayList<>();
for (IGuild g : guilds) {
JSONObject d = new JSONObject();
d.put("GUILD_ID", g.getLongID());
d.put("IS_OWNER", g.getOwnerLongID() == userId);
d.put("MANAGE_SERVER", PermissionChecker.hasManageServerRole(g, user));
d.put("DISCAL_CONTROL", PermissionChecker.hasSufficientRole(g, user));
guildData.add(d);
}
JSONObject body = new JSONObject();
body.put("USER_ID", userId);
body.put("GUILD_COUNT", guildData.size());
body.put("GUILDS", guildData);
response.type("application/json");
response.status(200);
response.body(body.toString());
} catch (JSONException e) {
e.printStackTrace();
halt(400, "Bad Request");
} catch (Exception e) {
Logger.getLogger().exception(null, "[WEB-API] Internal get guilds from users error", e, GuildEndpoint.class, true);
}
return response.body();
}
use of sx.blah.discord.handle.obj.IUser in project DiscordSailv2 by Vaerys-Dawn.
the class TopTen method execute.
@Override
public String execute(String args, CommandObject command) {
ArrayList<ProfileObject> ranks = new ArrayList<>();
ArrayList<String> response = new ArrayList<>();
for (ProfileObject u : command.guild.users.getProfiles()) {
long rank = PixelHandler.rank(command.guild.users, command.guild.get(), u.getUserID());
if (rank <= 10 && rank != -1) {
ranks.add(u);
}
}
Utility.sortUserObjects(ranks, false);
// format rank stats
for (ProfileObject r : ranks) {
IUser ranked = command.guild.getUserByID(r.getUserID());
String rankPos = "**" + PixelHandler.rank(command.guild.users, command.guild.get(), r.getUserID()) + "** - ";
StringBuilder toFormat = new StringBuilder(ranked.getDisplayName(command.guild.get()));
toFormat.append("\n " + indent + "`Level: " + r.getCurrentLevel() + ", Pixels: " + NumberFormat.getInstance().format(r.getXP()) + "`");
if (r.getUserID() == command.user.get().getLongID()) {
response.add(rankPos + spacer + "**" + toFormat + "**");
} else {
response.add(rankPos + toFormat);
}
}
XEmbedBuilder builder = new XEmbedBuilder(command);
builder.withTitle("Top Ten Users for the " + command.guild.get().getName() + " Server.");
builder.withDesc(Utility.listFormatter(response, false));
RequestHandler.sendEmbedMessage("", builder, command.channel.get());
return null;
}
Aggregations