Search in sources :

Example 1 with MessageChannel

use of discord4j.core.object.entity.channel.MessageChannel in project symja_android_library by axkr.

the class SymjaBot method createMessage.

private static void createMessage(final Message message) {
    String content = message.getContent().trim();
    if (content.length() > 3) {
        String start = content.substring(0, 3);
        content = content.substring(3);
        String postfix = Scanner.balanceCode(content);
        if (postfix != null && postfix.length() > 0) {
            // there are open brackets which needs to be balanced
            content = content + postfix;
        }
        // } else
        if (start.equals("!~~")) {
            String result = interpreter("N(" + content + ")");
            final MessageChannel channel = message.getChannel().block();
            channel.createMessage(result).block();
        } else {
            String result = interpreter(content);
            final MessageChannel channel = message.getChannel().block();
            channel.createMessage(result).block();
        }
    }
}
Also used : MessageChannel(discord4j.core.object.entity.channel.MessageChannel)

Example 2 with MessageChannel

use of discord4j.core.object.entity.channel.MessageChannel in project KaellyBot by Kaysoro.

the class RSSCommand method request.

@Override
public void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
    // On check si la personne a bien les droits pour exécuter cette commande
    if (isUserHasEnoughRights(message)) {
        String value = m.group(1);
        String guildId = message.getGuild().blockOptional().map(Guild::getId).map(Snowflake::asString).orElse("");
        String channelId = message.getChannel().blockOptional().map(MessageChannel::getId).map(Snowflake::asString).orElse("");
        if (value.matches("\\s+true") || value.matches("\\s+0") || value.matches("\\s+on")) {
            if (!RSSFinder.getRSSFinders().containsKey(channelId)) {
                new RSSFinder(guildId, channelId).addToDatabase();
                message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "rss.request.1").replace("{game.url}", Translator.getLabel(lg, "game.url")))).subscribe();
            } else
                rssFound.throwException(message, this, lg);
        } else if (value.matches("\\s+false") || value.matches("\\s+1") || value.matches("\\s+off"))
            if (RSSFinder.getRSSFinders().containsKey(channelId)) {
                RSSFinder.getRSSFinders().get(channelId).removeToDatabase();
                message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "rss.request.2").replace("{game.url}", Translator.getLabel(lg, "game.url")))).subscribe();
            } else
                rssNotFound.throwException(message, this, lg);
        else
            badUse.throwException(message, this, lg);
    } else
        BasicDiscordException.NO_ENOUGH_RIGHTS.throwException(message, this, lg);
}
Also used : Guild(discord4j.core.object.entity.Guild) Language(enums.Language) MessageCreateEvent(discord4j.core.event.domain.message.MessageCreateEvent) AbstractCommand(commands.model.AbstractCommand) MessageChannel(discord4j.core.object.entity.channel.MessageChannel) Matcher(java.util.regex.Matcher) Message(discord4j.core.object.entity.Message) Translator(util.Translator) Constants(data.Constants) Snowflake(discord4j.common.util.Snowflake) exceptions(exceptions) RSSFinder(finders.RSSFinder) MessageChannel(discord4j.core.object.entity.channel.MessageChannel) RSSFinder(finders.RSSFinder) Guild(discord4j.core.object.entity.Guild)

Example 3 with MessageChannel

use of discord4j.core.object.entity.channel.MessageChannel in project KaellyBot by Kaysoro.

the class TwitterCommand method request.

@Override
public void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
    // On check si la personne a bien les droits pour exécuter cette commande
    if (isUserHasEnoughRights(message)) {
        String value = m.group(1);
        Long guildId = message.getGuild().blockOptional().map(Guild::getId).map(Snowflake::asLong).orElse(0L);
        Long channelId = message.getChannel().blockOptional().map(MessageChannel::getId).map(Snowflake::asLong).orElse(0L);
        if (value.matches("\\s+true") || value.matches("\\s+0") || value.matches("\\s+on")) {
            if (!TwitterFinder.getTwitterChannels().containsKey(channelId)) {
                new TwitterFinder(guildId, channelId).addToDatabase();
                message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "twitter.request.1").replace("{twitter.name}", Translator.getLabel(lg, "twitter.name")))).subscribe();
            } else
                twitterFound.throwException(message, this, lg);
        } else if (value.matches("\\s+false") || value.matches("\\s+1") || value.matches("\\s+off")) {
            if (TwitterFinder.getTwitterChannels().containsKey(channelId)) {
                TwitterFinder.getTwitterChannels().get(channelId).removeToDatabase();
                message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "twitter.request.2").replace("{twitter.name}", Translator.getLabel(lg, "twitter.name")))).subscribe();
            } else
                twitterNotFound.throwException(message, this, lg);
        } else
            badUse.throwException(message, this, lg);
    } else
        BasicDiscordException.NO_ENOUGH_RIGHTS.throwException(message, this, lg);
}
Also used : Guild(discord4j.core.object.entity.Guild) Language(enums.Language) MessageCreateEvent(discord4j.core.event.domain.message.MessageCreateEvent) AbstractCommand(commands.model.AbstractCommand) MessageChannel(discord4j.core.object.entity.channel.MessageChannel) Matcher(java.util.regex.Matcher) Message(discord4j.core.object.entity.Message) TwitterFinder(finders.TwitterFinder) Translator(util.Translator) Snowflake(discord4j.common.util.Snowflake) exceptions(exceptions) MessageChannel(discord4j.core.object.entity.channel.MessageChannel) Guild(discord4j.core.object.entity.Guild) TwitterFinder(finders.TwitterFinder)

Example 4 with MessageChannel

use of discord4j.core.object.entity.channel.MessageChannel 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();
    }
}
Also used : Language(enums.Language) MessageCreateEvent(discord4j.core.event.domain.message.MessageCreateEvent) AbstractCommand(commands.model.AbstractCommand) MessageChannel(discord4j.core.object.entity.channel.MessageChannel) data(data) ServerUtils(util.ServerUtils) Collectors(java.util.stream.Collectors) List(java.util.List) GuildMessageChannel(discord4j.core.object.entity.channel.GuildMessageChannel) Matcher(java.util.regex.Matcher) Message(discord4j.core.object.entity.Message) Game(enums.Game) BasicDiscordException(exceptions.BasicDiscordException) Translator(util.Translator) MessageChannel(discord4j.core.object.entity.channel.MessageChannel) GuildMessageChannel(discord4j.core.object.entity.channel.GuildMessageChannel) ServerUtils(util.ServerUtils) GuildMessageChannel(discord4j.core.object.entity.channel.GuildMessageChannel)

Example 5 with MessageChannel

use of discord4j.core.object.entity.channel.MessageChannel 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();
        }
}
Also used : ChannelLanguage(data.ChannelLanguage) MessageChannel(discord4j.core.object.entity.channel.MessageChannel) GuildMessageChannel(discord4j.core.object.entity.channel.GuildMessageChannel) Language(enums.Language) ChannelLanguage(data.ChannelLanguage) ArrayList(java.util.ArrayList) List(java.util.List) Guild(data.Guild)

Aggregations

MessageChannel (discord4j.core.object.entity.channel.MessageChannel)6 Language (enums.Language)5 MessageCreateEvent (discord4j.core.event.domain.message.MessageCreateEvent)4 Matcher (java.util.regex.Matcher)4 Translator (util.Translator)4 AbstractCommand (commands.model.AbstractCommand)3 Snowflake (discord4j.common.util.Snowflake)3 Message (discord4j.core.object.entity.Message)3 GuildMessageChannel (discord4j.core.object.entity.channel.GuildMessageChannel)3 Constants (data.Constants)2 Guild (data.Guild)2 Guild (discord4j.core.object.entity.Guild)2 exceptions (exceptions)2 BasicDiscordException (exceptions.BasicDiscordException)2 List (java.util.List)2 data (data)1 ChannelLanguage (data.ChannelLanguage)1 discord4j.core.object.entity (discord4j.core.object.entity)1 PrivateChannel (discord4j.core.object.entity.channel.PrivateChannel)1 TextChannel (discord4j.core.object.entity.channel.TextChannel)1