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());
}
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);
}
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();
}
}
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();
}
}
}
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());
}
Aggregations