use of discord4j.core.spec.EmbedCreateSpec in project BoltBot by DiscordBolt.
the class HelpCommand method createHelpEmbed.
private EmbedCreateSpec createHelpEmbed(EmbedCreateSpec embed, List<String> modules, String commandPrefix) {
int fieldCount = 0;
embed.setColor(new Color(36, 153, 153));
StringBuilder sb = new StringBuilder();
for (String module : modules) {
// Discord only allows 25 fields in an embed
if (fieldCount > 25)
continue;
sb.setLength(0);
// Get all commands of this module
manager.getCommands().stream().filter(c -> c.getModule().equals(module)).forEach(command -> {
if (command.isSecret()) {
return;
}
sb.append('`').append(commandPrefix).append(String.join(" ", command.getCommands())).append("` | ").append(command.getDescription()).append('\n');
});
// Discord only allows field descriptions to be 1024 characters
if (sb.length() > 1024) {
sb.setLength(1024);
}
if (module.length() == 0 || sb.length() == 0) {
continue;
}
fieldCount++;
embed.addField(module, sb.toString(), false);
}
return embed;
}
use of discord4j.core.spec.EmbedCreateSpec in project KaellyBot by Kaysoro.
the class AlignmentCommand method request.
@Override
public void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
String content = m.group(1).trim();
Optional<discord4j.core.object.entity.Guild> guild = message.getGuild().blockOptional();
Optional<Member> user = message.getAuthorAsMember().blockOptional();
// Initialisation du Filtre
City city = null;
Order order = null;
if (guild.isPresent() && user.isPresent()) {
ServerDofus server = ServerUtils.getDofusServerFrom(Guild.getGuild(guild.get()), message.getChannel().block());
// Consultation filtré par niveau
if ((m = Pattern.compile(">\\s+(\\d{1,3})(\\s+.+)?").matcher(content)).matches()) {
int level = Integer.parseInt(m.group(1));
if (m.group(2) != null) {
ServerUtils.ServerQuery serverQuery = ServerUtils.getServerDofusFromName(m.group(2), lg);
if (serverQuery.hasSucceed())
server = serverQuery.getServer();
else {
serverQuery.getExceptions().forEach(e -> e.throwException(message, this, lg, serverQuery.getServersFound()));
return;
}
} else if (server == null) {
notFoundServer.throwException(message, this, lg);
return;
}
List<EmbedCreateSpec> embeds = OrderUser.getOrdersFromLevel(guild.get().getMembers().collectList().blockOptional().orElse(Collections.emptyList()), server, level, guild.get(), lg);
for (EmbedCreateSpec embed : embeds) message.getChannel().flatMap(chan -> chan.createEmbed(embed)).subscribe();
} else {
// L'utilisateur concerné est-il l'auteur de la commande ?
if (Pattern.compile("^<@[!|&]?\\d+>").matcher(content).find()) {
content = content.replaceFirst("<@[!|&]?\\d+>", "").trim();
Optional<Snowflake> memberId = message.getUserMentionIds().stream().findFirst();
if (!memberId.isPresent()) {
BasicDiscordException.USER_NEEDED.throwException(message, this, lg);
return;
}
user = guild.get().getMemberById(memberId.get()).blockOptional();
}
// Consultation des données filtrés par utilisateur
ServerUtils.ServerQuery serverQuery = ServerUtils.getServerDofusFromName(content, lg);
if (!serverQuery.getServersFound().isEmpty() && Pattern.compile("(.+)").matcher(content).matches() || content.isEmpty()) {
if (serverQuery.hasSucceed())
server = serverQuery.getServer();
else if (server == null) {
if (!content.isEmpty())
serverQuery.getExceptions().forEach(e -> e.throwException(message, this, lg, serverQuery.getServersFound()));
else
notFoundServer.throwException(message, this, lg);
return;
}
if (user.isPresent()) {
List<EmbedCreateSpec> embeds = OrderUser.getOrdersFromUser(user.get(), server, lg);
for (EmbedCreateSpec embed : embeds) message.getChannel().flatMap(chan -> chan.createEmbed(embed)).subscribe();
}
} else // Enregistrement des données
if ((m = Pattern.compile("(\\p{L}+)\\s+(\\p{L}+)\\s+(\\d{1,3})(\\s+.+)?").matcher(content)).matches()) {
if (user.isPresent() && message.getAuthor().isPresent() && user.get().getId().equals(message.getAuthor().get().getId())) {
// Parsing des données et traitement des divers exceptions
List<City> cities = findCity(m.group(1), lg);
if (checkData(cities, tooMuchCities, notFoundCity, message, lg))
return;
city = cities.get(0);
List<Order> orders = findOrder(m.group(2), lg);
if (checkData(orders, tooMuchOrders, notFoundOrder, message, lg))
return;
order = orders.get(0);
int level = Integer.parseInt(m.group(3));
if (m.group(4) != null) {
ServerUtils.ServerQuery query = ServerUtils.getServerDofusFromName(m.group(4), lg);
if (query.hasSucceed())
server = query.getServer();
else {
query.getExceptions().forEach(e -> e.throwException(message, this, lg, query.getServersFound()));
return;
}
} else if (server == null) {
notFoundServer.throwException(message, this, lg);
return;
}
if (OrderUser.containsKeys(user.get().getId().asLong(), server, city, order)) {
OrderUser.get(user.get().getId().asLong(), server, city, order).get(0).setLevel(level);
if (level != 0)
message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "align.update"))).subscribe();
else
message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "align.reset"))).subscribe();
} else {
new OrderUser(user.get().getId().asLong(), server, city, order, level).addToDatabase();
if (level != 0)
message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "align.save"))).subscribe();
else
message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "align.no_reset"))).subscribe();
}
} else
badUse.throwException(message, this, lg);
} else // Consultation filtré par cité et/ou par ordre
if ((m = Pattern.compile("(\\p{L}+)(\\s+\\p{L}+)?(\\s+[\\p{L}|\\W]+)?").matcher(content)).matches()) {
if (m.group(3) != null) {
ServerUtils.ServerQuery query = ServerUtils.getServerDofusFromName(m.group(3), lg);
if (query.hasSucceed())
server = query.getServer();
else {
query.getExceptions().forEach(e -> e.throwException(message, this, lg, query.getServersFound()));
return;
}
}
// On a précisé à la fois une cité et un ordre
if (m.group(2) != null) {
boolean is2Server = false;
if (m.group(3) == null) {
ServerUtils.ServerQuery query = ServerUtils.getServerDofusFromName(m.group(2), lg);
if (query.hasSucceed()) {
server = query.getServer();
is2Server = true;
} else {
query.getExceptions().forEach(e -> e.throwException(message, this, lg, query.getServersFound()));
return;
}
}
if (is2Server) {
// Est-ce un ordre ? une cité ?
String value = m.group(1).trim();
List<City> cities = findCity(value, lg);
List<Order> orders = findOrder(value, lg);
if (cities.isEmpty() && orders.isEmpty()) {
notFoundFilter.throwException(message, this, lg);
return;
}
if (cities.size() > 1 || orders.size() > 1) {
tooMuchFilters.throwException(message, this, lg);
return;
}
if (cities.size() == 1)
city = cities.get(0);
if (orders.size() == 1)
order = orders.get(0);
} else {
List<City> cities = findCity(m.group(1).trim(), lg);
if (checkData(cities, tooMuchCities, notFoundCity, message, lg))
return;
city = cities.get(0);
List<Order> orders = findOrder(m.group(2).trim(), lg);
if (checkData(orders, tooMuchOrders, notFoundOrder, message, lg))
return;
order = orders.get(0);
}
} else {
// Is an order ? a city ?
List<City> cities = findCity(m.group(1).trim(), lg);
List<Order> orders = findOrder(m.group(1).trim(), lg);
if (cities.isEmpty() && orders.isEmpty()) {
notFoundFilter.throwException(message, this, lg);
return;
}
if (cities.size() > 1 || orders.size() > 1) {
tooMuchFilters.throwException(message, this, lg);
return;
}
if (cities.size() == 1)
city = cities.get(0);
if (orders.size() == 1)
order = orders.get(0);
}
if (server == null) {
notFoundServer.throwException(message, this, lg);
return;
}
List<EmbedCreateSpec> embeds = OrderUser.getOrdersFromCityOrOrder(guild.get().getMembers().collectList().blockOptional().orElse(Collections.emptyList()), server, city, order, guild.get(), lg);
for (EmbedCreateSpec embed : embeds) message.getChannel().flatMap(chan -> chan.createEmbed(embed)).subscribe();
} else
badUse.throwException(message, this, lg);
}
}
}
use of discord4j.core.spec.EmbedCreateSpec in project KaellyBot by Kaysoro.
the class AlmanaxCommand method request.
@Override
public void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
try {
Date date = new Date();
if (m.group(1) != null && m.group(1).matches("\\s+\\+\\d")) {
int number = Integer.parseInt(m.group(1).replaceAll("\\s+\\+", ""));
try {
EmbedCreateSpec embed = Almanax.decorateGroupedObject(lg, date, number);
message.getChannel().flatMap(chan -> chan.createEmbed(embed)).subscribe();
} catch (IOException e) {
ExceptionManager.manageIOException(e, message, this, lg, BasicDiscordException.ALMANAX);
}
} else {
if (m.group(1) != null && m.group(1).matches("\\s+\\d{2}/\\d{2}/\\d{4}"))
date = Almanax.discordToBot.parse(m.group(1));
Almanax almanax = Almanax.get(lg, date);
message.getChannel().flatMap(chan -> chan.createEmbed(almanax.decorateMoreEmbedObject(lg))).subscribe();
}
} catch (ParseException e) {
BasicDiscordException.INCORRECT_DATE_FORMAT.throwException(message, this, lg);
} catch (IOException e) {
ExceptionManager.manageIOException(e, message, this, lg, BasicDiscordException.ALMANAX);
} catch (Exception e) {
ExceptionManager.manageException(e, message, this, lg);
}
}
use of discord4j.core.spec.EmbedCreateSpec in project KaellyBot by Kaysoro.
the class JobCommand method request.
@Override
protected void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
String content = m.group(1).trim().replaceAll(",", "");
// Filter Initialisation
Optional<discord4j.core.object.entity.Guild> guild = message.getGuild().blockOptional();
Optional<Member> user = message.getAuthorAsMember().blockOptional();
if (guild.isPresent() && user.isPresent()) {
ServerDofus server = ServerUtils.getDofusServerFrom(Guild.getGuild(guild.get()), message.getChannel().block());
// Concerned user is the author?
if (Pattern.compile("^<@[!|&]?\\d+>").matcher(content).find()) {
content = content.replaceFirst("<@[!|&]?\\d+>", "").trim();
Optional<Snowflake> memberId = message.getUserMentionIds().stream().findFirst();
if (!memberId.isPresent()) {
BasicDiscordException.USER_NEEDED.throwException(message, this, lg);
return;
}
user = guild.get().getMemberById(memberId.get()).blockOptional();
}
// user data consultation
ServerUtils.ServerQuery serverQuery = ServerUtils.getServerDofusFromName(content, lg);
if (!serverQuery.getServersFound().isEmpty() && Pattern.compile("(.+)").matcher(content).matches() || content.isEmpty()) {
if (serverQuery.hasSucceed())
server = serverQuery.getServer();
else if (server == null) {
if (!content.isEmpty())
serverQuery.getExceptions().forEach(e -> e.throwException(message, this, lg, serverQuery.getServersFound()));
else
notFoundServer.throwException(message, this, lg);
return;
}
if (user.isPresent()) {
List<EmbedCreateSpec> embeds = JobUser.getJobsFromUser(user.get(), server, lg);
for (EmbedCreateSpec embed : embeds) message.getChannel().flatMap(chan -> chan.createEmbed(embed)).subscribe();
}
} else // Data recording
if ((m = Pattern.compile("-list|(-all|\\p{L}+(?:\\s+\\p{L}+)*)\\s+(\\d{1,3})(\\s+.+)?").matcher(content)).matches()) {
if (user.isPresent() && message.getAuthor().isPresent() && user.get().getId().equals(message.getAuthor().get().getId())) {
if (!m.group(0).equals("-list")) {
// Data Parsing and exceptions processing
Set<Job> jobs;
StringBuilder found = new StringBuilder();
StringBuilder notFound = new StringBuilder();
StringBuilder tooMuch = new StringBuilder();
if (!m.group(1).equals("-all")) {
jobs = new HashSet<>();
String[] proposals = m.group(1).split("\\s+");
for (String proposal : proposals) if (!proposal.trim().isEmpty()) {
List<Job> tmp = getJob(lg, proposal);
if (tmp.size() == 1) {
jobs.add(tmp.get(0));
found.append(tmp.get(0).getLabel(lg)).append(", ");
} else if (tmp.isEmpty())
notFound.append("*").append(proposal).append("*, ");
else
tooMuch.append("*").append(proposal).append("*, ");
}
} else
jobs = new HashSet<>(Arrays.asList(Job.values()));
// Check existing jobs
if (jobs.isEmpty()) {
message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "job.noone"))).subscribe();
return;
}
if (found.length() > 0)
found.setLength(found.length() - 2);
if (notFound.length() > 0)
notFound.setLength(notFound.length() - 2);
if (tooMuch.length() > 0)
tooMuch.setLength(tooMuch.length() - 2);
int level = Integer.parseInt(m.group(2));
if (m.group(3) != null) {
ServerUtils.ServerQuery query = ServerUtils.getServerDofusFromName(m.group(3), lg);
if (serverQuery.hasSucceed())
server = serverQuery.getServer();
else
serverQuery.getExceptions().forEach(e -> e.throwException(message, this, lg, query.getServersFound()));
} else if (server == null) {
notFoundServer.throwException(message, this, lg);
return;
}
for (Job job : jobs) if (JobUser.containsKeys(user.get().getId().asLong(), server, job))
JobUser.get(user.get().getId().asLong(), server, job).get(0).setLevel(level);
else
new JobUser(user.get().getId().asLong(), server, job, level).addToDatabase();
StringBuilder sb = new StringBuilder();
if (jobs.size() < Job.values().length)
sb.append(Translator.getLabel(lg, level > 0 ? "job.save" : "job.reset").replace("{jobs}", found.toString()));
else
sb.append(Translator.getLabel(lg, level > 0 ? "job.all_save" : "job.all_reset"));
if (notFound.length() > 0)
sb.append("\n").append(Translator.getLabel(lg, "job.not_found").replace("{jobs}", notFound.toString()));
if (tooMuch.length() > 0)
sb.append("\n").append(Translator.getLabel(lg, "job.too_much").replace("{jobs}", tooMuch.toString()));
final String CONTENT = sb.toString();
message.getChannel().flatMap(chan -> chan.createMessage(CONTENT)).subscribe();
} else {
String sb = Translator.getLabel(lg, "job.list") + "\n" + getJobsList(lg);
message.getChannel().flatMap(chan -> chan.createMessage(sb)).subscribe();
}
} else
badUse.throwException(message, this, lg);
} else if ((m = Pattern.compile("(?:>\\s*(\\d{1,3})\\s+)?(\\p{L}+(?:\\s+\\p{L}+)*)").matcher(content)).matches()) {
List<String> proposals = new LinkedList<>(Arrays.asList(m.group(2).split("\\s+")));
if (proposals.size() > 1) {
String potentialServer = proposals.get(proposals.size() - 1);
ServerUtils.ServerQuery query = ServerUtils.getServerDofusFromName(potentialServer, lg);
if (query.hasSucceed()) {
server = query.getServer();
proposals.remove(potentialServer);
} else {
query.getExceptions().forEach(e -> e.throwException(message, this, lg, query.getServersFound()));
return;
}
} else if (server == null) {
notFoundServer.throwException(message, this, lg);
return;
}
Set<Job> jobs = new HashSet<>();
for (String proposal : proposals) if (jobs.size() < MAX_JOB_DISPLAY) {
if (!proposal.trim().isEmpty()) {
List<Job> tmp = getJob(lg, proposal);
if (tmp.size() == 1)
jobs.add(tmp.get(0));
}
}
// Check if a job is found
if (jobs.isEmpty()) {
message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "job.noone"))).subscribe();
return;
}
int level = -1;
if (m.group(1) != null)
level = Integer.parseInt(m.group(1));
List<EmbedCreateSpec> embeds = JobUser.getJobsFromFilters(guild.get().getMembers().collectList().blockOptional().orElse(Collections.emptyList()), server, jobs, level, guild.get(), lg);
for (EmbedCreateSpec embed : embeds) message.getChannel().flatMap(chan -> chan.createEmbed(embed)).subscribe();
} else
badUse.throwException(message, this, lg);
}
}
use of discord4j.core.spec.EmbedCreateSpec in project S-argo by Expugn.
the class Profile method bannerSearchMenu.
/**
* Searches for characters with the given name and displays a list
* of all those characters that the user has.
*
* @param characterName Character to be looked up.
*/
private void bannerSearchMenu(String characterName) {
String characterList = "";
int characterCount = 0;
String correctName = "";
boolean fetchCorrectName = true;
for (Character c : user.getCharacterBox()) {
if (c.getName().equalsIgnoreCase(characterName)) {
characterList += c.toStringNoName() + "\n";
characterCount++;
if (fetchCorrectName) {
fetchCorrectName = false;
correctName = c.getName();
}
}
}
Consumer<EmbedCreateSpec> ecsTemplate;
if (!characterList.isEmpty()) {
String correctName_final = correctName;
String characterList_final = characterList;
int characterCount_final = characterCount;
ecsTemplate = s -> {
s.setAuthor(userName + "'s Profile", "", member.getAvatarUrl());
s.setColor(new Color(255, 86, 91));
s.setThumbnail(new GitHubImage("images/System/Profile_Icon.png").getURL());
s.addField("Character Search: " + correctName_final, characterList_final, false);
s.setFooter(characterCount_final + " " + correctName_final + " found.", "");
};
} else {
ecsTemplate = s -> {
s.setAuthor(userName + "'s Profile", "", member.getAvatarUrl());
s.setColor(new Color(255, 86, 91));
s.setThumbnail(new GitHubImage("images/System/Profile_Icon.png").getURL());
s.addField("Character Search", "Could not find data for \"" + characterName + "\"", false);
};
}
Sargo.sendEmbed(CHANNEL, ecsTemplate);
}
Aggregations