use of discord4j.core.object.entity.channel.GuildMessageChannel in project KaellyBot by Kaysoro.
the class ServerCommand method request.
@Override
public void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
Guild guild = Guild.getGuild(message.getGuild().block());
MessageChannel channel = message.getChannel().block();
if (m.group(1) != null) {
String serverName = m.group(1).toLowerCase().trim();
if (serverName.equals("-list")) {
String sb = Translator.getLabel(lg, "server.list") + "\n" + getServersList(lg);
message.getChannel().flatMap(chan -> chan.createMessage(sb)).subscribe();
return;
}
if (isUserHasEnoughRights(message)) {
if (!serverName.startsWith("-channel")) {
ServerUtils.ServerQuery query = ServerUtils.getServerDofusFromName(serverName, lg);
if (query.hasSucceed()) {
guild.setServer(query.getServer());
message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "server.request.1").replace("{game}", Constants.game.getName()) + " " + guild.getName() + " " + Translator.getLabel(lg, "server.request.2") + " " + query.getServer().getLabel(lg) + ".")).subscribe();
} else
query.getExceptions().forEach(exception -> exception.throwException(message, this, lg, query.getServersFound()));
} else {
ServerUtils.ServerQuery query = ServerUtils.getServerDofusFromName(serverName.replace("-channel", "").trim(), lg);
ChannelServer channelServer = ChannelServer.getChannelServers().get(channel.getId().asLong());
if (query.hasSucceed()) {
if (channelServer != null) {
if (channelServer.getServer().getName().equals(query.getServer().getName())) {
channelServer.removeToDatabase();
channel.createMessage(((GuildMessageChannel) channel).getName() + " " + Translator.getLabel(lg, "server.request.4").replace("{server}", guild.getServerDofus().toString())).subscribe();
} else {
channelServer.setServer(query.getServer());
message.getChannel().flatMap(salon -> salon.createMessage(((GuildMessageChannel) channel).getName() + " " + Translator.getLabel(lg, "server.request.4").replace("{server}", query.getServer().toString()))).subscribe();
}
} else {
final ChannelServer CHAN = new ChannelServer(query.getServer(), channel.getId().asLong());
CHAN.addToDatabase();
message.getChannel().flatMap(salon -> salon.createMessage(((GuildMessageChannel) channel).getName() + " " + Translator.getLabel(lg, "server.request.4").replace("{server}", query.getServer().toString()))).subscribe();
}
} else
query.getExceptions().forEach(exception -> exception.throwException(message, this, lg, query.getServersFound()));
}
} else
BasicDiscordException.NO_ENOUGH_RIGHTS.throwException(message, this, lg);
} else {
String text = "**" + guild.getName() + "** " + (guild.getServerDofus() != null ? Translator.getLabel(lg, "server.request.4").replace("{server}", guild.getServerDofus().getLabel(lg)) : Translator.getLabel(lg, "server.request.5")).replace("{game}", Constants.game.getName());
ChannelServer channelServer = ChannelServer.getChannelServers().get(channel.getId().asLong());
if (channelServer != null)
text += "\n" + Translator.getLabel(lg, "server.request.6").replace("{channel}", ((GuildMessageChannel) channel).getName()).replace("{server}", channelServer.getServer().getLabel(lg));
channel.createMessage(text).subscribe();
}
}
use of discord4j.core.object.entity.channel.GuildMessageChannel in project KaellyBot by Kaysoro.
the class LanguageCommand method request.
@Override
public void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
Optional<discord4j.core.object.entity.Guild> guild = message.getGuild().blockOptional();
Optional<MessageChannel> channel = message.getChannel().blockOptional();
if (guild.isPresent() && channel.isPresent())
if (m.group(2) != null) {
// Ajouts
String channelName = ((GuildMessageChannel) channel.get()).getName();
if (isUserHasEnoughRights(message)) {
List<Language> langs = new ArrayList<>();
for (Language lang : Language.values()) if (m.group(2).trim().toUpperCase().equals(lang.getAbrev()))
langs.add(lang);
if (langs.size() == 1) {
if (m.group(1) == null) {
Guild.getGuild(guild.get()).setLanguage(langs.get(0));
final Language LG = langs.get(0);
message.getChannel().flatMap(chan -> chan.createMessage(guild.get().getName() + " " + Translator.getLabel(LG, "lang.request.1") + " " + langs.get(0))).subscribe();
} else {
ChannelLanguage chan = ChannelLanguage.getChannelLanguages().get(channel.get().getId().asLong());
if (chan != null) {
if (chan.getLang().equals(langs.get(0))) {
chan.removeToDatabase();
final Language LG = Translator.getLanguageFrom(channel.get());
message.getChannel().flatMap(salon -> salon.createMessage(channelName + " " + Translator.getLabel(LG, "lang.request.2") + " " + Guild.getGuild(guild.get()).getLanguage())).subscribe();
} else {
chan.setLanguage(langs.get(0));
final Language LG = langs.get(0);
message.getChannel().flatMap(salon -> salon.createMessage(channelName + " " + Translator.getLabel(LG, "lang.request.1") + " " + chan.getLang())).subscribe();
}
} else {
final Language LG = langs.get(0);
final ChannelLanguage CHAN = new ChannelLanguage(langs.get(0), channel.get().getId().asLong());
CHAN.addToDatabase();
message.getChannel().flatMap(salon -> salon.createMessage(channelName + " " + Translator.getLabel(LG, "lang.request.1") + " " + CHAN.getLang())).subscribe();
}
}
} else if (langs.isEmpty())
notFoundLang.throwException(message, this, lg);
else
tooMuchLangs.throwException(message, this, lg);
} else
BasicDiscordException.NO_ENOUGH_RIGHTS.throwException(message, this, lg);
} else {
// Consultation
String text = "**" + guild.get().getName() + "** " + Translator.getLabel(lg, "lang.request.3") + " " + Guild.getGuild(guild.get()).getLanguage() + ".";
ChannelLanguage chanLang = ChannelLanguage.getChannelLanguages().get(channel.get().getId().asLong());
if (chanLang != null)
text += "\nLe salon *" + ((GuildMessageChannel) channel.get()).getName() + "* " + Translator.getLabel(lg, "lang.request.3") + " " + chanLang.getLang() + ".";
final String TEXT = text;
message.getChannel().flatMap(salon -> salon.createMessage(TEXT)).subscribe();
}
}
use of discord4j.core.object.entity.channel.GuildMessageChannel in project KaellyBot by Kaysoro.
the class GuildCreateListener method onReady.
public Flux<MessageData> onReady(GuildCreateEvent event) {
try {
if (!Guild.getGuilds().containsKey(event.getGuild().getId().asString())) {
return event.getGuild().getChannels().filter(chan -> chan instanceof GuildMessageChannel).map(chan -> (GuildMessageChannel) chan).take(1).flatMap(chan -> {
Guild guild = new Guild(event.getGuild().getId().asString(), event.getGuild().getName(), Translator.detectLanguage(chan));
guild.addToDatabase();
Language lg = guild.getLanguage();
LOG.info("La guilde " + guild.getId() + " - " + guild.getName() + " a ajouté " + Constants.name);
return event.getGuild().getOwner().flatMap(owner -> {
String customMessage = Translator.getLabel(lg, "welcome.message").replaceAll("\\{name}", Constants.name).replaceAll("\\{game}", Constants.game.getName()).replaceAll("\\{prefix}", Constants.prefixCommand).replaceAll("\\{help}", HelpCommand.NAME).replaceAll("\\{server}", new ServerCommand().getName()).replaceAll("\\{lang}", new LanguageCommand().getName()).replaceAll("\\{twitter}", new TwitterCommand().getName()).replaceAll("\\{almanax-auto}", new AlmanaxAutoCommand().getName()).replaceAll("\\{rss}", new RSSCommand().getName()).replaceAll("\\{owner}", owner.getMention()).replaceAll("\\{guild}", event.getGuild().getName());
return chan.createMessage(customMessage).onErrorResume(ignored -> sendWelcomeMessageInPM(event, customMessage)).then(ClientConfig.DISCORD().getChannelById(Snowflake.of(Constants.chanReportID)).createMessage("[NEW] **" + event.getGuild().getName() + "** (" + guild.getLanguage().getAbrev() + "), +" + event.getGuild().getMemberCount() + " utilisateurs"));
});
});
}
} catch (Exception e) {
Reporter.report(e, event.getGuild());
LOG.error("onReady", e);
}
return Flux.empty();
}
use of discord4j.core.object.entity.channel.GuildMessageChannel in project KaellyBot by Kaysoro.
the class Translator method getLanguageFrom.
/**
* Fournit la langue utilisée dans un salon textuel
* @param channel Salon textuel
* @return Langue de la guilde ou du salon si précisé
*/
public static Language getLanguageFrom(MessageChannel channel) {
Language result = Constants.defaultLanguage;
if (channel instanceof GuildMessageChannel) {
Guild guild = Guild.getGuild(((GuildMessageChannel) channel).getGuild().block());
result = guild.getLanguage();
ChannelLanguage channelLanguage = ChannelLanguage.getChannelLanguages().get(channel.getId().asLong());
if (channelLanguage != null)
result = channelLanguage.getLang();
}
return result;
}
Aggregations