use of sx.blah.discord.handle.obj.IUser in project DiscordSailv2 by Vaerys-Dawn.
the class GetCompEntries method execute.
@Override
public String execute(String args, CommandObject command) {
if (command.guild.competition.getEntries().size() == 0) {
return "> No entries were found.";
}
List<CompObject> compObjects = command.guild.competition.getEntries();
for (int i = 0; i < compObjects.size(); i++) {
XEmbedBuilder builder = new XEmbedBuilder(command);
builder.withTitle("Entry " + (i + 1));
IUser user = command.guild.getUserByID(compObjects.get(i).getUserID());
if (user != null) {
builder.withDesc(user.mention());
builder.withColor(GuildHandler.getUsersColour(user, command.guild.get()));
}
if (Utility.isImageLink(compObjects.get(i).getFileUrl())) {
builder.withThumbnail(compObjects.get(i).getFileUrl());
} else {
if (user != null) {
builder.withDesc(user.mention() + "\n" + compObjects.get(i).getFileUrl());
} else {
builder.withDesc(compObjects.get(i).getFileUrl());
}
}
builder.send(command.channel);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
Utility.sendStack(e);
}
}
return "";
}
use of sx.blah.discord.handle.obj.IUser in project DiscordSailv2 by Vaerys-Dawn.
the class WeightedFinalTally method execute.
@Override
public String execute(String args, CommandObject command) {
if (!command.guild.config.modulePixels)
return "> Weighted final tally should only be used if the pixel module is enabled, please use **" + new FinalTally().getUsage(command) + "** instead.";
Map<Long, Long> entryVotes = new HashMap<>();
long totalEntries = 0;
long totalVotes = 0;
StringBuilder builder = new StringBuilder();
for (long i = 0; i < command.guild.competition.getEntries().size(); i++) {
entryVotes.put(i + 1, 0L);
}
for (String s : command.guild.competition.getVotes()) {
String[] splitVotes = s.split(",");
if (splitVotes.length != 1 && splitVotes.length != 0) {
for (long i = 1; i < splitVotes.length; i++) {
try {
long vote = Long.parseLong(splitVotes[(int) i]);
if (entryVotes.containsKey(vote)) {
IUser user = command.guild.getUserByID(Utility.stringLong(splitVotes[0]));
if (user != null) {
int weight = PixelHandler.getRewardCount(command.guild, user.getLongID());
entryVotes.put(vote, entryVotes.get(vote).longValue() + weight + 1);
totalVotes += weight + 1;
}
}
} catch (NumberFormatException e) {
// Ignore
}
totalEntries++;
}
}
}
builder.append("**Total Weighted Votes\n**");
entryVotes.forEach((k, v) -> builder.append("> Entry " + k + ": " + v + " Votes.\n"));
builder.append("Total votes: " + totalVotes + ".\n");
builder.append("Total Entries: " + totalEntries + ".");
return builder.toString();
}
use of sx.blah.discord.handle.obj.IUser in project DiscordSailv2 by Vaerys-Dawn.
the class ListCCs method getUserCommands.
public String getUserCommands(CommandObject command, long userID) {
IUser user = Globals.getClient().getUserByID(userID);
int total = 0;
command.setAuthor(user);
int max = command.guild.customCommands.maxCCs(command.user, command.guild);
XEmbedBuilder builder = new XEmbedBuilder(command);
String title = "> Here are the custom commands for user: **@" + user.getName() + "#" + user.getDiscriminator() + "**.";
List<String> list = new ArrayList<>();
for (CCommandObject c : command.guild.customCommands.getCommandList()) {
if (c.getUserID() == userID) {
list.add(command.guild.config.getPrefixCC() + c.getName());
total++;
}
}
builder.withTitle(title);
String content = Utility.listFormatter(list, true);
if (content.length() > 2000) {
String path = Constants.DIRECTORY_TEMP + command.message.longID + ".txt";
FileHandler.writeToFile(path, content, false);
File file = new File(path);
RequestHandler.sendFile(title, file, command.channel.get());
return null;
}
builder.withDescription("```\n" + content + "```");
builder.withFooterText("Total Custom commands: " + total + "/" + max + ".");
RequestHandler.sendEmbedMessage("", builder, command.channel.get());
return null;
}
use of sx.blah.discord.handle.obj.IUser in project DiscordSailv2 by Vaerys-Dawn.
the class ResetRuleCode method execute.
@Override
public String execute(String args, CommandObject command) {
IMessage working = RequestHandler.sendMessage("`Working...`", command.channel).get();
for (ProfileObject p : command.guild.users.profiles) {
if (p.getSettings().size() != 0) {
p.getSettings().remove(UserSetting.READ_RULES);
}
}
for (IUser u : command.guild.getUsers()) {
GuildHandler.checkUsersRoles(u.getLongID(), command.guild);
}
RequestHandler.deleteMessage(working);
return "Done. The Rule code tag has been removed off all profiles.";
}
use of sx.blah.discord.handle.obj.IUser in project DiscordSailv2 by Vaerys-Dawn.
the class TagRemoveMentions method execute.
@Override
public String execute(String from, CommandObject command, String args) {
boolean isRoleMention = false;
String id;
if (Pattern.compile("<@&[0-9]*>").matcher(from).find()) {
id = StringUtils.substringBetween(from, "<@&", ">");
isRoleMention = true;
} else {
id = StringUtils.substringBetween(from, "<@!", ">");
if (id == null) {
id = StringUtils.substringBetween(from, "<@", ">");
}
}
if (!isRoleMention) {
try {
long userID = Long.parseUnsignedLong(id);
IUser user = command.guild.getUserByID(userID);
if (user != null) {
from = from.replace(user.mention(true), user.getDisplayName(command.guild.get()));
from = from.replace(user.mention(false), user.getDisplayName(command.guild.get()));
} else {
throw new NumberFormatException("You shouldn't see this.");
}
} catch (NumberFormatException e) {
from = from.replaceAll("<@!?" + id + ">", "null");
}
} else {
// remove role mentions
try {
long roleID = Long.parseUnsignedLong(id);
IRole role = command.guild.getRoleByID(roleID);
if (role != null) {
from = from.replace("<@&" + id + ">", role.getName());
} else {
throw new NumberFormatException("You shouldn't see this.");
}
} catch (NumberFormatException e) {
from = from.replace("<@&" + id + ">", "null");
}
}
return from;
}
Aggregations