Search in sources :

Example 1 with Guild

use of discord4j.core.object.entity.Guild in project lavaplayer by sedmelluq.

the class Main method attachToFirstVoiceChannel.

private static void attachToFirstVoiceChannel(Guild guild, D4jAudioProvider provider) {
    VoiceChannel voiceChannel = guild.getChannels().ofType(VoiceChannel.class).blockFirst();
    boolean inVoiceChannel = // Check if any VoiceState for this guild relates to bot
    guild.getVoiceStates().any(voiceState -> guild.getClient().getSelfId().map(voiceState.getUserId()::equals).orElse(false)).block();
    if (!inVoiceChannel) {
        voiceChannel.join(spec -> spec.setProvider(provider)).block();
    }
}
Also used : FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) Guild(discord4j.core.object.entity.Guild) MessageCreateEvent(discord4j.core.event.domain.message.MessageCreateEvent) Logger(org.slf4j.Logger) DefaultAudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager) VoiceChannel(discord4j.core.object.entity.VoiceChannel) EventDispatcher(discord4j.core.event.EventDispatcher) DiscordClientBuilder(discord4j.core.DiscordClientBuilder) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LoggerFactory(org.slf4j.LoggerFactory) DiscordClient(discord4j.core.DiscordClient) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager) Message(discord4j.core.object.entity.Message) Map(java.util.Map) MessageChannel(discord4j.core.object.entity.MessageChannel) AudioSourceManagers(com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) TextChannel(discord4j.core.object.entity.TextChannel) VoiceChannel(discord4j.core.object.entity.VoiceChannel)

Example 2 with Guild

use of discord4j.core.object.entity.Guild 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 Guild

use of discord4j.core.object.entity.Guild 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)

Aggregations

MessageCreateEvent (discord4j.core.event.domain.message.MessageCreateEvent)3 Guild (discord4j.core.object.entity.Guild)3 Message (discord4j.core.object.entity.Message)3 AbstractCommand (commands.model.AbstractCommand)2 Snowflake (discord4j.common.util.Snowflake)2 MessageChannel (discord4j.core.object.entity.channel.MessageChannel)2 Language (enums.Language)2 exceptions (exceptions)2 Matcher (java.util.regex.Matcher)2 Translator (util.Translator)2 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)1 AudioPlayerManager (com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager)1 DefaultAudioPlayerManager (com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager)1 AudioSourceManagers (com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers)1 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)1 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)1 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 Constants (data.Constants)1 DiscordClient (discord4j.core.DiscordClient)1 DiscordClientBuilder (discord4j.core.DiscordClientBuilder)1