Search in sources :

Example 1 with MessageData

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();
}
Also used : commands.config(commands.config) Language(enums.Language) GuildCreateEvent(discord4j.core.event.domain.guild.GuildCreateEvent) Logger(org.slf4j.Logger) TextChannel(discord4j.core.object.entity.channel.TextChannel) ClientException(discord4j.rest.http.client.ClientException) LoggerFactory(org.slf4j.LoggerFactory) Mono(reactor.core.publisher.Mono) HelpCommand(commands.classic.HelpCommand) DiscordClient(discord4j.core.DiscordClient) Permission(discord4j.rest.util.Permission) Snowflake(discord4j.common.util.Snowflake) Constants(data.Constants) Guild(data.Guild) Flux(reactor.core.publisher.Flux) Reporter(util.Reporter) GuildMessageChannel(discord4j.core.object.entity.channel.GuildMessageChannel) Message(discord4j.core.object.entity.Message) Member(discord4j.core.object.entity.Member) MessageData(discord4j.discordjson.json.MessageData) Translator(util.Translator) ClientConfig(util.ClientConfig) Language(enums.Language) Guild(data.Guild) ClientException(discord4j.rest.http.client.ClientException) GuildMessageChannel(discord4j.core.object.entity.channel.GuildMessageChannel)

Aggregations

HelpCommand (commands.classic.HelpCommand)1 commands.config (commands.config)1 Constants (data.Constants)1 Guild (data.Guild)1 Snowflake (discord4j.common.util.Snowflake)1 DiscordClient (discord4j.core.DiscordClient)1 GuildCreateEvent (discord4j.core.event.domain.guild.GuildCreateEvent)1 Member (discord4j.core.object.entity.Member)1 Message (discord4j.core.object.entity.Message)1 GuildMessageChannel (discord4j.core.object.entity.channel.GuildMessageChannel)1 TextChannel (discord4j.core.object.entity.channel.TextChannel)1 MessageData (discord4j.discordjson.json.MessageData)1 ClientException (discord4j.rest.http.client.ClientException)1 Permission (discord4j.rest.util.Permission)1 Language (enums.Language)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Flux (reactor.core.publisher.Flux)1 Mono (reactor.core.publisher.Mono)1 ClientConfig (util.ClientConfig)1