use of discord4j.core.object.entity.channel.PrivateChannel in project KaellyBot by Kaysoro.
the class HelpCommand method request.
@Override
public void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
String prefix = getPrefixMdEscaped(message);
StringBuilder st = new StringBuilder();
List<String> messages = new ArrayList<>();
boolean argumentFound = m.group(1) != null && m.group(1).replaceAll("^\\s+", "").length() > 0;
for (Command command : CommandManager.getCommands()) if (command.isPublic() && !command.isAdmin() && (!command.isHidden() || argumentFound) && (message.getChannel().block() instanceof PrivateChannel || !command.isForbidden(Guild.getGuild(message.getGuild().block())))) {
if (!argumentFound) {
String helpCmd = command.help(lg, prefix) + "\n";
if (st.length() + helpCmd.length() > Message.MAX_CONTENT_LENGTH) {
messages.add(st.toString());
st.setLength(0);
}
st.append(helpCmd);
} else if (command.getName().equals(m.group(1).trim())) {
st.append(command.helpDetailed(lg, prefix));
break;
}
}
if (st.length() > 0)
messages.add(st.toString());
if (argumentFound && messages.isEmpty())
notFoundCmd.throwException(message, this, lg);
else
for (String msg : messages) message.getChannel().flatMap(chan -> chan.createMessage(msg)).subscribe();
}
use of discord4j.core.object.entity.channel.PrivateChannel in project KaellyBot by Kaysoro.
the class AbstractCommand method request.
@Override
public final void request(MessageCreateEvent event, Message message) {
Language lg = Translator.getLanguageFrom(message.getChannel().block());
try {
Matcher m = getMatcher(message);
boolean isFound = m.find();
// Caché si la fonction est désactivée/réservée aux admin et que l'auteur n'est pas super-admin
if ((!isPublic() || isAdmin()) && message.getAuthor().map(user -> user.getId().asLong() != Constants.authorId).orElse(false))
return;
// S'il s'agit d'une demande d'aide...
if (message.getContent().matches(Pattern.quote(getPrefix(message)) + getName() + "\\s+help")) {
message.getChannel().flatMap(chan -> chan.createMessage(helpDetailed(lg, getPrefix(message)))).subscribe();
return;
}
// La commande est trouvée
if (isFound) {
// Mais n'est pas utilisable en MP
MessageChannel channel = message.getChannel().block();
if (!isUsableInMP() && channel instanceof PrivateChannel) {
BasicDiscordException.NOT_USABLE_IN_MP.throwException(message, this, lg);
return;
} else // Mais est désactivée par la guilde
if (!(channel instanceof PrivateChannel) && message.getAuthor().map(user -> user.getId().asLong() != Constants.authorId).orElse(false) && isForbidden(Guild.getGuild(message.getGuild().block()))) {
BasicDiscordException.COMMAND_FORBIDDEN.throwException(message, this, lg);
return;
}
} else // Mais est mal utilisée
if (message.getContent().startsWith(getPrefix(message) + getName())) {
badUse.throwException(message, this, lg);
return;
}
if (isFound)
request(event, message, m, lg);
} catch (Exception e) {
BasicDiscordException.UNKNOWN_ERROR.throwException(message, this, lg);
Reporter.report(e);
LOG.error("request", e);
}
}
use of discord4j.core.object.entity.channel.PrivateChannel in project KaellyBot by Kaysoro.
the class SendNudeCommand method request.
@Override
public void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
if (message.getChannel().blockOptional().map(chan -> chan instanceof PrivateChannel).orElse(false) || message.getChannel().blockOptional().map(chan -> ((TextChannel) chan).isNsfw()).orElse(false)) {
int position = RANDOM.nextInt(Nude.values().length);
Nude nude = Nude.values()[position];
message.getChannel().flatMap(chan -> chan.createEmbed(spec -> spec.setTitle(Translator.getLabel(lg, "sendnude.title")).setDescription(Translator.getLabel(lg, "sendnude.author").replace("{author}", nude.getAuthor()).replace("{url}", nude.getUrl())).setColor(discord4j.rest.util.Color.PINK).setFooter(Translator.getLabel(lg, "sendnude.footer").replace("{position}", String.valueOf(position + 1)).replace("{number}", String.valueOf(Nude.values().length)), null).setImage(nude.getImage()))).subscribe();
} else
// Exception NSFW
BasicDiscordException.NO_NSFW_CHANNEL.throwException(message, this, lg);
}
Aggregations