use of discord4j.discordjson.json.MessageData 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();
}
Aggregations