net.dv8tion.jda.api.entities.MessageChannel Java Examples

The following examples show how to use net.dv8tion.jda.api.entities.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: HelpCommand.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private void send(GuildMessageReceivedEvent message, MessageChannel channel, EmbedBuilder embedBuilder, boolean direct) {
    channel.sendMessage(embedBuilder.build()).queue();
    if (direct && message.getAuthor() != null) {
        contextService.withContext(message.getGuild(), () -> {
            messageService.onMessage(message.getChannel(), "discord.command.help.sent", message.getAuthor().getAsMention());
        });
    }
}
 
Example #2
Source File: DiscordBotServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
NavigableEmbed( List<List<Supplier<MessageEmbed>>> embeds,  MessageChannel channel) {
	this.embeds = new ArrayList<>();
	this.embeds.addAll(embeds);
	this.channel = channel;
	xindex = 0;
	yindex = 0;
	sendMessage();
}
 
Example #3
Source File: MessageServiceImpl.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public <T> void sendTempMessageSilent(Function<T, RestAction<Message>> action, T embed, int sec) {
    sendMessageSilentQueue(action, embed, message -> {
        JDA jda = message.getJDA();
        long messageId = message.getIdLong();
        long channelId = message.getChannel().getIdLong();
        ChannelType type = message.getChannelType();
        scheduler.schedule(() -> {
            MessageChannel channel = DiscordUtils.getChannel(jda, type, channelId);
            if (channel != null) {
                channel.retrieveMessageById(messageId).queue(this::delete);
            }
        }, new DateTime().plusSeconds(sec).toDate());
    });
}
 
Example #4
Source File: MessageServiceImpl.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTitledMessage(MessageChannel sourceChannel, String titleCode, String code, Object... args) {
    if (StringUtils.isEmpty(titleCode)) {
        sendMessageSilent(sourceChannel::sendMessage, getMessage(code, args));
        return;
    }
    sendMessageSilent(sourceChannel::sendMessage, createMessage(titleCode, code, args).build());
}
 
Example #5
Source File: MessagePaginationActionImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
public MessagePaginationActionImpl(MessageChannel channel)
{
    super(channel.getJDA(), Route.Messages.GET_MESSAGE_HISTORY.compile(channel.getId()), 1, 100, 100);

    if (channel.getType() == ChannelType.TEXT)
    {
        TextChannel textChannel = (TextChannel) channel;
        if (!textChannel.getGuild().getSelfMember().hasPermission(textChannel, Permission.MESSAGE_HISTORY))
            throw new InsufficientPermissionException(textChannel, Permission.MESSAGE_HISTORY);
    }

    this.channel = channel;
}
 
Example #6
Source File: RemindCommand.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private void createReminder(MessageChannel channel, Member member, String message, Date date) {
    JobDetail job = ReminderJob.createDetails(channel, member, message);
    Trigger trigger = TriggerBuilder
            .newTrigger()
            .startAt(date)
            .withSchedule(SimpleScheduleBuilder.simpleSchedule())
            .build();
    try {
        schedulerFactoryBean.getScheduler().scheduleJob(job, trigger);
    } catch (SchedulerException e) {
        throw new RuntimeException(e);
    }
}
 
Example #7
Source File: ReactionPaginationActionImpl.java    From JDA with Apache License 2.0 4 votes vote down vote up
public ReactionPaginationActionImpl(MessageChannel channel, String messageId, String code)
{
    super(channel.getJDA(), Route.Messages.GET_REACTION_USERS.compile(channel.getId(), messageId, code), 1, 100, 100);
    this.reaction = null;
}
 
Example #8
Source File: MessageDeleteHandler.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Override
protected Long handleInternally(DataObject content)
{
    final long messageId = content.getLong("id");
    final long channelId = content.getLong("channel_id");

    MessageChannel channel = getJDA().getTextChannelById(channelId);
    if (channel == null)
    {
        channel = getJDA().getPrivateChannelById(channelId);
    }
    if (channel == null)
    {
        channel = getJDA().getFakePrivateChannelMap().get(channelId);
    }
    if (channel == null)
    {
        getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
        EventCache.LOG.debug("Got message delete for a channel/group that is not yet cached. ChannelId: {}", channelId);
        return null;
    }

    if (channel instanceof TextChannel)
    {
        TextChannelImpl tChan = (TextChannelImpl) channel;
        if (getJDA().getGuildSetupController().isLocked(tChan.getGuild().getIdLong()))
            return tChan.getGuild().getIdLong();
        if (tChan.hasLatestMessage() && messageId == channel.getLatestMessageIdLong())
            tChan.setLastMessageId(0); // Reset latest message id as it was deleted.
        getJDA().handleEvent(
                new GuildMessageDeleteEvent(
                        getJDA(), responseNumber,
                        messageId, tChan));
    }
    else
    {
        PrivateChannelImpl pChan = (PrivateChannelImpl) channel;
        if (channel.hasLatestMessage() && messageId == channel.getLatestMessageIdLong())
            pChan.setLastMessageId(0); // Reset latest message id as it was deleted.
        getJDA().handleEvent(
                new PrivateMessageDeleteEvent(
                        getJDA(), responseNumber,
                        messageId, pChan));
    }

    //Combo event
    getJDA().handleEvent(
            new MessageDeleteEvent(
                    getJDA(), responseNumber,
                    messageId, channel));
    return null;
}
 
Example #9
Source File: TypingStartHandler.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Override
    protected Long handleInternally(DataObject content)
    {
        if (!content.isNull("guild_id"))
        {
            long guildId = content.getLong("guild_id");
            if (getJDA().getGuildSetupController().isLocked(guildId))
                return guildId;
        }

        final long channelId = content.getLong("channel_id");
        MessageChannel channel = getJDA().getTextChannelsView().get(channelId);
        if (channel == null)
            channel = getJDA().getPrivateChannelsView().get(channelId);
        if (channel == null)
            channel = getJDA().getFakePrivateChannelMap().get(channelId);
        if (channel == null)
            return null;    //We don't have the channel cached yet. We chose not to cache this event
                            // because that happen very often and could easily fill up the EventCache if
                            // we, for some reason, never get the channel. Especially in an active channel.

//        if (channel instanceof TextChannel)
//        {
//            final long guildId = ((TextChannel) channel).getGuild().getIdLong();
//            if (getJDA().getGuildSetupController().isLocked(guildId))
//                return guildId;
//        }

        final long userId = content.getLong("user_id");
        User user;
        if (channel instanceof PrivateChannel)
            user = ((PrivateChannel) channel).getUser();
        else
            user = getJDA().getUsersView().get(userId);

        if (user == null)
            return null;    //Just like in the comment above, if for some reason we don't have the user
                            // then we will just throw the event away.

        OffsetDateTime timestamp = Instant.ofEpochSecond(content.getInt("timestamp")).atOffset(ZoneOffset.UTC);
        getJDA().handleEvent(
                new UserTypingEvent(
                        getJDA(), responseNumber,
                        user, channel, timestamp));
        return null;
    }
 
Example #10
Source File: MessageReactionRemoveEmoteEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public MessageReactionRemoveEmoteEvent(@Nonnull JDA api, long responseNumber, long messageId, @Nonnull MessageChannel channel, @Nonnull MessageReaction reaction)
{
    super(api, responseNumber, messageId, channel);
    this.reaction = reaction;
}
 
Example #11
Source File: MessagePaginationActionImpl.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public MessageChannel getChannel()
{
    return channel;
}
 
Example #12
Source File: MessageReactionRemoveAllEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public MessageReactionRemoveAllEvent(@Nonnull JDA api, long responseNumber, long messageId, @Nonnull MessageChannel channel)
{
    super(api, responseNumber, messageId, channel);
}
 
Example #13
Source File: MessageDeleteEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public MessageDeleteEvent(@Nonnull JDA api, long responseNumber, long messageId, @Nonnull MessageChannel channel)
{
    super(api, responseNumber, messageId, channel);
}
 
Example #14
Source File: MessageEmbedEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public MessageEmbedEvent(@Nonnull JDA api, long responseNumber, long messageId, @Nonnull MessageChannel channel, @Nonnull List<MessageEmbed> embeds)
{
    super(api, responseNumber, messageId, channel);
    this.embeds = Collections.unmodifiableList(embeds);
}
 
Example #15
Source File: DiscordBotServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
public Builder( MessageChannel channel) {
	embeds = new ArrayList<>();
	this.channel = channel;
}
 
Example #16
Source File: PlayerControl.java    From Yui with Apache License 2.0 4 votes vote down vote up
private void loadAndPlay(GuildMusicManager mng, final MessageChannel channel, String url, final boolean addPlaylist)
{
    final String trackUrl;

    //Strip <>'s that prevent discord from embedding link resources
    if (url.startsWith("<") && url.endsWith(">"))
        trackUrl = url.substring(1, url.length() - 1);
    else
        trackUrl = url;

    playerManager.loadItemOrdered(mng, trackUrl, new AudioLoadResultHandler()
    {
        @Override
        public void trackLoaded(AudioTrack track)
        {
            String msg = "Adding to queue: " + track.getInfo().title;
            if (mng.player.getPlayingTrack() == null)
                msg += "\nand the Player has started playing;";

            mng.scheduler.queue(track);
            channel.sendMessage(msg).queue();
        }

        @Override
        public void playlistLoaded(AudioPlaylist playlist)
        {
            AudioTrack firstTrack = playlist.getSelectedTrack();
            List<AudioTrack> tracks = playlist.getTracks();


            if (firstTrack == null) {
                firstTrack = playlist.getTracks().get(0);
            }

            if (addPlaylist)
            {
                channel.sendMessage("Adding **" + playlist.getTracks().size() +"** tracks to queue from playlist: " + playlist.getName()).queue();
                tracks.forEach(mng.scheduler::queue);
            }
            else
            {
                channel.sendMessage("Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")").queue();
                mng.scheduler.queue(firstTrack);
            }
        }

        @Override
        public void noMatches()
        {
            channel.sendMessage("Nothing found by " + trackUrl).queue();
        }

        @Override
        public void loadFailed(FriendlyException exception)
        {
            channel.sendMessage("Could not play: " + exception.getMessage()).queue();
        }
    });
}
 
Example #17
Source File: DiscordBotServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
private void analyseCard(MessageReceivedEvent event) {
	logger.debug("Received message :" + event.getMessage().getContentRaw() + " from " + event.getAuthor().getName()+ " in #" + event.getChannel().getName());
	final List<MagicCard> liste = new ArrayList<>();
	Pattern p = Pattern.compile(getString(REGEX));
	Matcher m = p.matcher(event.getMessage().getContentRaw());
	if(m.find())
	{
		String name=m.group(1).trim();
		MagicEdition ed = null;
		if(name.contains("|"))
		{
			ed = new MagicEdition();
			ed.setId(name.substring(name.indexOf('|')+1,name.length()).toUpperCase().trim());
			name=name.substring(0, name.indexOf('|')).trim();
		}
		
		MessageChannel channel = event.getChannel();
			channel.sendTyping().queue();

			try {
				liste.addAll(MTGControler.getInstance().getEnabled(MTGCardsProvider.class).searchCardByName(name, ed, false));
			}
			catch(Exception e)
			{
				logger.error(e);
			}
			
			if(liste.isEmpty())
			{
				channel.sendMessage("Sorry i can't found "+name ).queue();
				return;
			}
			
			NavigableEmbed.Builder builder = new NavigableEmbed.Builder(event.getChannel());
			for (int x = 0; x < liste.size(); x++) {
				MagicCard result = liste.get(x);
				BiFunction<MagicCard, Integer, MessageEmbed> getEmbed = (c, resultIndex) -> {
					MessageEmbed embed=parseCard(result);
					EmbedBuilder eb = new EmbedBuilder(embed);
					if (liste.size() > 1)
						eb.setFooter("Result " + (resultIndex + 1) + "/" + liste.size(), null);
					
					return eb.build();
				};
				int finalIndex = x;
				builder.addEmbed(() -> getEmbed.apply(result, finalIndex));
			}
			
			NavigableEmbed navEb = builder.build();
			
			
			if(liste.size()>1)
			{
				applyControl(EmbedButton.PREVIOUS.getIcon(), navEb.getMessage(), navEb.getWidth() > 1);
				applyControl(EmbedButton.NEXT.getIcon(), navEb.getMessage(), navEb.getWidth() > 1);
		
				ReactionListener rl = new ReactionListener(jda, navEb.getMessage(), false, 30L * 1000L);
				rl.addController(event.getAuthor());
				rl.addResponse(EmbedButton.PREVIOUS.getIcon(), ev -> {
					navEb.setY(0);
					if (navEb.getX() > 0) navEb.left();
					applyControl(EmbedButton.PREVIOUS.getIcon(), navEb.getMessage(), navEb.getWidth() > 1);
				});
				rl.addResponse(EmbedButton.NEXT.getIcon(), ev -> {
					navEb.setY(0);
					if (navEb.getX() < navEb.getWidth() - 1) navEb.right();
					applyControl(EmbedButton.NEXT.getIcon(), navEb.getMessage(), navEb.getWidth() > 1);
				});

			}
		}	
		
	
	
}
 
Example #18
Source File: NewContext.java    From MantaroBot with GNU General Public License v3.0 4 votes vote down vote up
public MessageChannel getChannel() {
    return message.getChannel();
}
 
Example #19
Source File: ImageGame.java    From MantaroBot with GNU General Public License v3.0 4 votes vote down vote up
protected RestAction<Message> sendEmbedImage(MessageChannel channel, String url, Consumer<EmbedBuilder> embedConfigurator) {
    EmbedBuilder eb = new EmbedBuilder();
    embedConfigurator.accept(eb);
    eb.setImage("attachment://image.png");
    return channel.sendMessage(new MessageBuilder().setEmbed(eb.build()).build()).addFile(cache.getInput(url), "image.png");
}
 
Example #20
Source File: MessageServiceImpl.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onError(MessageChannel sourceChannel, String code, Object... args) {
    onError(sourceChannel, "discord.message.title.error", code, args);
}
 
Example #21
Source File: MessageServiceImpl.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onError(MessageChannel sourceChannel, String titleCode, String code, Object... args) {
    sendMessageSilent(sourceChannel::sendMessage, createMessage(titleCode, code, args)
            .setColor(Color.RED).build());
}
 
Example #22
Source File: MessageServiceImpl.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onMessage(MessageChannel sourceChannel, String code, Object... args) {
    onTitledMessage(sourceChannel, null, code, args);
}
 
Example #23
Source File: MessageServiceImpl.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onEmbedMessage(MessageChannel sourceChannel, String code, Object... args) {
    EmbedBuilder builder = getBaseEmbed();
    builder.setDescription(getMessage(code, args));
    sendMessageSilent(sourceChannel::sendMessage, builder.build());
}
 
Example #24
Source File: MessageServiceImpl.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onTempEmbedMessage(MessageChannel sourceChannel, int sec, String code, Object... args) {
    EmbedBuilder builder = getBaseEmbed();
    builder.setDescription(getMessage(code, args));
    sendTempMessageSilent(sourceChannel::sendMessage, builder.build(), sec);
}
 
Example #25
Source File: MessageServiceImpl.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onTempMessage(MessageChannel sourceChannel, int sec, String code, Object... args) {
    onTempPlainMessage(sourceChannel, sec, getMessage(code, args));
}
 
Example #26
Source File: MessageServiceImpl.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onTempPlainMessage(MessageChannel sourceChannel, int sec, String text) {
    sendTempMessageSilent(sourceChannel::sendMessage, text, sec);
}
 
Example #27
Source File: InteractiveOperations.java    From MantaroBot with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns a Future<Void> representing the current RunningOperation instance on the specified channel.
 *
 * @param channel The MessageChannel to check.
 * @return Future<Void> or null if there's none.
 */
public static List<Future<Void>> get(MessageChannel channel) {
    return get(channel.getIdLong());
}
 
Example #28
Source File: MessagePaginationAction.java    From JDA with Apache License 2.0 2 votes vote down vote up
/**
 * The targeted {@link net.dv8tion.jda.api.entities.MessageChannel MessageChannel}
 *
 * @return The MessageChannel instance
 */
@Nonnull
MessageChannel getChannel();
 
Example #29
Source File: MessageAction.java    From JDA with Apache License 2.0 2 votes vote down vote up
/**
 * The target {@link MessageChannel} for this message
 *
 * @return The target channel
 */
@Nonnull
MessageChannel getChannel();
 
Example #30
Source File: InteractiveOperations.java    From MantaroBot with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a new {@link InteractiveOperation} on the specified {@link net.dv8tion.jda.api.entities.TextChannel} id provided.
 * This method will not make a new {@link InteractiveOperation} if there's already another one running.
 * You can check the return type to give a response to the user.
 *
 * @param channel        The id of the {@link net.dv8tion.jda.api.entities.TextChannel} we want this Operation to run on.
 * @param timeoutSeconds How much seconds until it stops listening to us.
 * @param operation      The {@link InteractiveOperation} itself.
 * @return The uncompleted {@link Future<Void>} of this InteractiveOperation.
 */
public static Future<Void> create(MessageChannel channel, long userId, long timeoutSeconds, InteractiveOperation operation) {
    return create(channel.getIdLong(), userId, timeoutSeconds, operation);
}