Search in sources :

Example 6 with GuildMusic

use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.

the class StopCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException {
    GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
    if (guildMusic == null) {
        BotUtils.sendMessage(TextUtils.NO_PLAYING_MUSIC, context.getChannel());
        return;
    }
    guildMusic.leaveVoiceChannel();
    BotUtils.sendMessage(String.format(Emoji.INFO + " Music stopped by **%s**.", context.getAuthorName()), context.getChannel());
}
Also used : GuildMusic(me.shadorc.shadbot.music.GuildMusic)

Example 7 with GuildMusic

use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.

the class ShutdownCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    if (!context.hasArg()) {
        MessageManager.addListener(context.getChannel(), this);
        BotUtils.sendMessage(String.format(Emoji.QUESTION + " Do you really want to shutdown %s ? Yes/No", context.getClient().getOurUser().mention()), context.getChannel());
        return;
    }
    List<String> splitArgs = StringUtils.split(context.getArg(), 2);
    if (splitArgs.size() != 2) {
        throw new MissingArgumentException();
    }
    Integer delay = CastUtils.asPositiveInt(splitArgs.get(0));
    if (delay == null) {
        throw new IllegalCmdArgumentException(String.format("`%s` is not a valid time.", splitArgs.get(0)));
    }
    String message = splitArgs.get(1);
    for (IGuild guild : context.getClient().getGuilds()) {
        GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(guild.getLongID());
        if (guildMusic != null && guildMusic.getChannel() != null) {
            BotUtils.sendMessage(Emoji.INFO + " " + message, guildMusic.getChannel());
        }
    }
    Shadbot.getScheduler().schedule(() -> System.exit(0), delay, TimeUnit.SECONDS);
    LogUtils.warnf("Shadbot will restart in %d seconds. (Message: %s)", delay, message);
}
Also used : IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) GuildMusic(me.shadorc.shadbot.music.GuildMusic) IGuild(sx.blah.discord.handle.obj.IGuild)

Example 8 with GuildMusic

use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.

the class UserVoiceChannelListener method check.

private synchronized void check(IGuild guild) {
    IVoiceChannel botVoiceChannel = guild.getClient().getOurUser().getVoiceStateForGuild(guild).getChannel();
    if (botVoiceChannel == null) {
        return;
    }
    GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(guild.getLongID());
    if (guildMusic == null) {
        return;
    }
    if (this.isAlone(botVoiceChannel) && !guildMusic.isLeavingScheduled()) {
        BotUtils.sendMessage(Emoji.INFO + " Nobody is listening anymore, music paused. I will leave the voice channel in 1 minute.", guildMusic.getChannel());
        guildMusic.getScheduler().getAudioPlayer().setPaused(true);
        guildMusic.scheduleLeave();
    } else if (!this.isAlone(botVoiceChannel) && guildMusic.isLeavingScheduled()) {
        BotUtils.sendMessage(Emoji.INFO + " Somebody joined me, music resumed.", guildMusic.getChannel());
        guildMusic.getScheduler().getAudioPlayer().setPaused(false);
        guildMusic.cancelLeave();
    }
}
Also used : GuildMusic(me.shadorc.shadbot.music.GuildMusic) IVoiceChannel(sx.blah.discord.handle.obj.IVoiceChannel)

Example 9 with GuildMusic

use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.

the class VoiceChannelListener method onVoiceDisconnectedEvent.

private void onVoiceDisconnectedEvent(VoiceDisconnectedEvent event) {
    GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(event.getGuild().getLongID());
    if (guildMusic != null) {
        guildMusic.delete();
        LogUtils.infof("{Guild ID: %d} Voice channel left.", event.getGuild().getLongID());
        // If not, this line will do nothing
        if (event.getVoiceChannel() != null && event.getVoiceChannel().getShard().isReady()) {
            event.getVoiceChannel().leave();
        }
    }
}
Also used : GuildMusic(me.shadorc.shadbot.music.GuildMusic)

Example 10 with GuildMusic

use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.

the class VolumeCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
    if (guildMusic == null || guildMusic.getScheduler().isStopped()) {
        BotUtils.sendMessage(TextUtils.NO_PLAYING_MUSIC, context.getChannel());
        return;
    }
    TrackScheduler scheduler = guildMusic.getScheduler();
    if (!context.hasArg()) {
        BotUtils.sendMessage(String.format(Emoji.SOUND + " Current volume level: **%d%%**", scheduler.getAudioPlayer().getVolume()), context.getChannel());
        return;
    }
    Integer volume = CastUtils.asPositiveInt(context.getArg());
    if (volume == null) {
        throw new IllegalCmdArgumentException(String.format("`%s` is not a valid volume.", context.getArg()));
    }
    scheduler.setVolume(volume);
    BotUtils.sendMessage(String.format(Emoji.SOUND + " Volume level set to **%s%%**", scheduler.getAudioPlayer().getVolume()), context.getChannel());
}
Also used : IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) GuildMusic(me.shadorc.shadbot.music.GuildMusic) TrackScheduler(me.shadorc.shadbot.music.TrackScheduler)

Aggregations

GuildMusic (me.shadorc.shadbot.music.GuildMusic)15 IllegalCmdArgumentException (me.shadorc.shadbot.exception.IllegalCmdArgumentException)6 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)5 TrackScheduler (me.shadorc.shadbot.music.TrackScheduler)2 IVoiceChannel (sx.blah.discord.handle.obj.IVoiceChannel)2 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)1 AudioLoadResultListener (me.shadorc.shadbot.listener.music.AudioLoadResultListener)1 RepeatMode (me.shadorc.shadbot.music.RepeatMode)1 IGuild (sx.blah.discord.handle.obj.IGuild)1 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)1