discord4j.core.object.entity.MessageChannel Java Examples

The following examples show how to use discord4j.core.object.entity.MessageChannel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
private void onMessageReceived(MessageCreateEvent event) {
  Message message = event.getMessage();

  message.getContent().ifPresent(it -> {
    MessageChannel channel = message.getChannel().block();

    if (channel instanceof TextChannel) {
      String[] command = it.split(" ", 2);

      if ("~play".equals(command[0]) && command.length == 2) {
        loadAndPlay((TextChannel) channel, command[1]);
      } else if ("~skip".equals(command[0])) {
        skipTrack((TextChannel) channel);
      }
    }
  });
}
 
Example #2
Source File: Translator.java    From KaellyBot with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Génère une liste de source formatée à partir d'un salon textuel
 * @param channel Salon d'origine
 * @return Liste de message éligibles à une reconnaissance de langue
 */
private static List<String> getReformatedMessages(MessageChannel channel){
    List<String> result = new ArrayList<>();

    if (channel != null) {
        try {
            List<Message> messages = channel.getMessagesBefore(Snowflake.of(Instant.now()))
                    .take(MAX_MESSAGES_READ).collectList().blockOptional().orElse(Collections.emptyList());
            for (Message message : messages) {
                String content = message.getContent()
                        .map(s -> s.replaceAll(":\\w+:", "").trim()).orElse("");
                if (content.length() > MAX_CHARACTER_ACCEPTANCE)
                    result.add(content);
            }
        } catch (Exception e){
            LOG.warn("Impossible to gather data from " + channel.getId().asString());
        }
    }
    return result;
}
 
Example #3
Source File: TwitterListener.java    From KaellyBot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onStatus(Status status) {
    Language language = twitterIDs.get(status.getUser().getId());
    if (twitterIDs.containsKey(status.getUser().getId()) && (status.getInReplyToScreenName() == null
            || twitterIDs.containsKey(status.getInReplyToUserId())))
        for (TwitterFinder twitterFinder : TwitterFinder.getTwitterChannels().values())
            try {
                ClientConfig.DISCORD()
                        .flatMap(client -> client.getChannelById(Snowflake.of(twitterFinder.getChannelId()))).distinct()
                        .filter(chan -> chan instanceof MessageChannel)
                        .map(chan -> (MessageChannel) chan)
                        .filter(chan -> Translator.getLanguageFrom(chan).equals(language))
                        .flatMap(chan -> chan.createEmbed(spec -> createEmbedFor(spec, status)))
                .subscribe();

            } catch(Exception e){
                LOG.error("onStatus", e);
            }
}
 
Example #4
Source File: RSSCommand.java    From KaellyBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void request(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);
}
 
Example #5
Source File: AlmanaxAutoCommand.java    From KaellyBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void request(Message message, Matcher m, Language lg) {
    if (isUserHasEnoughRights(message)) {
        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 (m.group(1).matches("\\s+true") || m.group(1).matches("\\s+0") || m.group(1).matches("\\s+on"))
            if (!AlmanaxCalendar.getAlmanaxCalendars().containsKey(channelId)) {
                new AlmanaxCalendar(guildId, channelId).addToDatabase();
                message.getChannel().flatMap(chan -> chan
                        .createMessage(Translator.getLabel(lg, "almanax-auto.request.1")))
                        .subscribe();
            } else
                message.getChannel().flatMap(chan -> chan
                        .createMessage(Translator.getLabel(lg, "almanax-auto.request.2")))
                        .subscribe();
        else if (m.group(1).matches("\\s+false") || m.group(1).matches("\\s+1") || m.group(1).matches("\\s+off"))
            if (AlmanaxCalendar.getAlmanaxCalendars().containsKey(channelId)) {
                AlmanaxCalendar.getAlmanaxCalendars().get(channelId).removeToDatabase();
                message.getChannel().flatMap(chan -> chan
                        .createMessage(Translator.getLabel(lg, "almanax-auto.request.3")))
                        .subscribe();
            } else
                message.getChannel().flatMap(chan -> chan
                        .createMessage(Translator.getLabel(lg, "almanax-auto.request.4")))
                        .subscribe();
    } else
        BasicDiscordException.NO_ENOUGH_RIGHTS.throwException(message, this, lg);
}
 
Example #6
Source File: TwitterCommand.java    From KaellyBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void request(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);
}
 
Example #7
Source File: Translator.java    From KaellyBot with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: ServerUtils.java    From KaellyBot with GNU General Public License v3.0 4 votes vote down vote up
public static ServerDofus getDofusServerFrom(Guild guild, MessageChannel channel){
    return Optional.ofNullable(ChannelServer.getChannelServers().get(channel.getId().asLong()))
            .map(ChannelServer::getServer)
            .orElse(guild.getServerDofus());
}