public async Task ClearMessages(int amount = 100) { try { const int max = 100; if (amount <= 0 || amount > max) { throw new ArgumentException("Messages to remove must be between 1 and 100"); } var messages = amount == -1 ? Context.Channel.GetMessagesAsync().FlattenAsync().Result : Context.Channel.GetMessagesAsync(amount).FlattenAsync().Result; var channel = Context.Channel as SocketTextChannel; try { await channel.DeleteMessagesAsync(messages); } catch (Exception ex) { throw new InvalidOperationException(ex.Message); } var reply = await ReplyAsync(await EmbedHandler.CreateSimpleEmbed("Clear", $"Cleared `{messages.Count()}` messages from {channel.Mention}", Color.Blue)); await Task.Delay(4000); await reply.DeleteAsync(); } catch (ArgumentException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } catch (InvalidOperationException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
//!kick, To kick bot from voice channel, still needs some autokick feature to get rid of some bugs **TODO** public async Task <Embed> LeaveChannelAsync(ulong guildID) { try { var player = _lavalink.DefaultNode.GetPlayer(guildID); if (player.IsPlaying || player.IsPaused) { await player.StopAsync(); } //Leave voice channel var channelName = player.VoiceChannel.Name; await _lavalink.DefaultNode.DisconnectAsync(guildID); await BotService.SetBotStatus(_client, "Ordering beer.."); await LoggingService.LogInformationAsync("Node", $"Bot disconnected from voice channel: {player.VoiceChannel.Name} + {currentGuild}"); return(await EmbedHandler.CreateBasicEmbed($"Music, Leave", $"Leaving channel {channelName}", Color.Green)); } // If something goes wrong, gives error info catch (InvalidOperationException ex) { return(await EmbedHandler.CreateErrorEmbed("Music, Leave", ex.ToString())); } }
public async Task ShowRankEXP(int rank) { try { if (rank <= 0) { throw new ArgumentException("Rank cannot be less than 0"); } var rankedUsers = await GuildUsers.GetRankedGuildUsersAsync(Context.Guild); if (rank > rankedUsers.Count) { throw new ArgumentException("Rank exceeds number of ranked users"); } var target = rankedUsers[rank - 1]; if (target is null) { throw new InvalidOperationException($"User at rank `{rank}` could not be found"); } string imageURL = $"{Global.Config.DashboardURL}/api/servers/{target.Guild.Id}/users/{target.Id}/xp-card"; var stream = await CommandUtils.DownloadData(imageURL); await Context.Channel.SendFileAsync(stream, "server-xp-card.png"); } catch (ArgumentException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
// Called when the bot leaves the channel public async Task <Embed> LeaveAsync(IGuild guild) { try { //Get The Player Via GuildID. var player = _lavaNode.GetPlayer(guild); //if The Player is playing, Stop it. if (player.PlayerState is PlayerState.Playing) { await player.StopAsync(); } //Leave the voice channel. await _lavaNode.LeaveAsync(player.VoiceChannel); await player.DisposeAsync(); Log.Information("Music", $"Bot has left."); return(await EmbedHandler.CreateBasicEmbed("Night Rune", $"Leaving voice channel.", Color.Blue)); } //Tell the user about the error so they can report it back to us. catch (InvalidOperationException ex) { return(await EmbedHandler.CreateErrorEmbed("Music, Leave", ex.Message)); } }
public async Task BanUser(SocketGuildUser target, string duration = "1d", [Remainder] string reason = "No reason provided.") { try { var user = await GuildUsers.GetAsync(target); var banDuration = CommandUtils.ParseDuration(duration); if (user.Status.IsBanned) { throw new InvalidOperationException($"User is banned"); } var targetHighest = target.Hierarchy; var senderHighest = (Context.Message.Author as SocketGuildUser).Hierarchy; if (targetHighest >= senderHighest) { throw new InvalidOperationException($"Higher rank user cannot be banned"); } else { await user.BanAsync(banDuration, reason, Context.User); await ReplyAsync(await EmbedHandler.CreateBasicEmbed(ModuleName, $"Banned {target.Mention} for `{duration}` - `{reason}`.", Color.Orange)); } } catch (InvalidOperationException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
public async Task Replay() { try { Player ??= await JoinAndGetPlayer(); AudioService.Tracks.TryGetValue(Context.Guild.Id, out var trackOptions); string lastTrackID = trackOptions?.LastOrDefault().ID; if (trackOptions is null || lastTrackID is null) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, "👀 No tracks found to replay.")); return; } var search = await lavaRestClient.SearchTracksAsync(lastTrackID); var track = search.Tracks.First(); if (Player.IsPlaying) { Player.Queue.Enqueue(track); await SendEnqueuedEmbed(track); } else { await Player.PlayAsync(track); await SendNowPlayingEmbed(Player); } } catch (InvalidOperationException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
/*** * Stops and clears the queue */ public async Task <Embed> StopAsync(IGuild guild) { try { var player = _lavaNode.GetPlayer(guild); if (player == null) { return(await EmbedHandler.CreateErrorEmbed("Music, Queue", $"Could not aquire player.\nAre you using the bot right now? check{GlobalData.Config.DefaultPrefix}help for info on how to use the bot.")); } /* Check if the player exists, if it does, check if it is playing. * If it is playing, we can stop.*/ if (player.PlayerState is PlayerState.Playing) { await player.StopAsync(); } Log.Information("Music", $"Bot has stopped playback."); return(await EmbedHandler.CreateBasicEmbed("Music Stop", "I Have stopped playback & the queue has been cleared.", Color.Blue)); } catch (Exception ex) { return(await EmbedHandler.CreateErrorEmbed("Music, Stop", ex.Message)); } }
public async Task <Embed> SkipCurrentlyPlayingTrack(SocketGuildUser user, IMessageChannel channel) { LavaPlayer player = lavalink.DefaultNode.GetPlayer(Config.Bot.ServerID); player.TextChannel = channel; if (player.CurrentTrack != null && player.IsPlaying) { WasSkipped = true; LavaTrack track = player.CurrentTrack; await player.StopAsync(); if (player.Queue.Count > 0) { await player.PlayAsync(player.Queue.Items.ElementAt(0)); return(await EmbedHandler.CreateEmbed("Audio", string.Format("{0} was skipped.\nNext song: {1}.", track.Title, player.CurrentTrack.Title))); } else { return(await EmbedHandler.CreateEmbed("Audio", string.Format("{0} was skipped.\nThere are no more tracks in the queue.", track.Title))); } } else { return(await EmbedHandler.CreateErrorEmbed("Audio, Current Track", "There Are No Current Track.")); } }
public async Task Replay(int seconds = -1) { try { await CheckPlayer(); await CheckIsPlaying("replay"); var trackLength = Player.CurrentTrack.Length; int totalSeconds = (int)trackLength.TotalSeconds; if (seconds == -1) { await ReplyAsync(embed : EmbedHandler.CreateBasicEmbed(ModuleName, $"{Hyperlink(Player.CurrentTrack)} is `{totalSeconds}` seconds long.", Color.Blue)); return; } if (seconds < 0 || seconds > totalSeconds) { throw new InvalidOperationException($"Track length must be between `0` seconds and `{totalSeconds}`."); } await Player.SeekAsync(TimeSpan.FromSeconds(seconds)); await ReplyAsync(EmbedHandler.CreateBasicEmbed(ModuleName, $"Position is now at {GetPosition(Player.CurrentTrack)}.", Color.Blue)); } catch (InvalidOperationException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
public async Task Volume(int volume = -1) { try { await CheckPlayer(); if (volume == -1) { await ReplyAsync(EmbedHandler.CreateBasicEmbed(ModuleName, $"**Current Volume:** `{Player.CurrentVolume}`", Color.Blue)); } else if (volume < 0 || volume > 200) { throw new ArgumentException("Volume must be between 0 and 200."); } else { await Player.SetVolumeAsync(volume); string warning = volume > 150 && CurrentGuild.Music.HeadphoneWarning ? "**HEADPHONE WARNING** ⚠\n" : ""; await ReplyAsync(EmbedHandler.CreateBasicEmbed(ModuleName, $"{warning}Volume has been set to `{volume}`.", Color.Blue)); } } catch (InvalidOperationException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } catch (ArgumentException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
public async Task OnFinished(LavaPlayer player, LavaTrack track, TrackEndReason reason) { if (reason is TrackEndReason.Cleanup || reason is TrackEndReason.Replaced) { return; } else if (reason is TrackEndReason.Stopped) { // TODO(Adam): add auto disconnect return; } else if (reason is TrackEndReason.LoadFailed) { if (player.TextChannel != null) { await player.TextChannel.SendMessageAsync(embed : await EmbedHandler.CreateErrorEmbed("Load Failed", $"Failed to load `{Hyperlink(track)}`.")); } return; } player.Queue.TryDequeue(out var queueObject); var nextTrack = queueObject as LavaTrack; if (nextTrack != null) { await player.PlayAsync(nextTrack); if (player.TextChannel != null) { await player.TextChannel.SendMessageAsync(embed : await EmbedHandler.CreateBasicEmbed("Now Playing", $"{Hyperlink(nextTrack)}", Color.Blue)); } } }
public async Task SetPrefix([Remainder] string prefix = "") { try { CurrentGuild ??= await Guilds.GetAsync(Context.Guild); if (string.IsNullOrEmpty(prefix)) { await ReplyAsync(EmbedHandler.CreateBasicEmbed(ModuleName, $"**Current Prefix**: `{CurrentGuild.General.CommandPrefix}`", ModuleColour)); return; } const int maxLength = 16; if (prefix.Length > maxLength) { throw new ArgumentException($"Prefix must be less than {maxLength + 1} characters long."); } CurrentGuild.General.CommandPrefix = prefix; await Guilds.Save(CurrentGuild); await ReplyAsync(EmbedHandler.CreateBasicEmbed(ModuleName, $"Prefix has been set to `{prefix}`", Color.Green)); } catch (ArgumentException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
public async Task Suggest([Remainder] string details) { try { var features = details.Split("|"); if (features.Length < 3) { throw new ArgumentException("Suggest", "Please seperate *Title*, *Subtitle*, and *Description* with | (vertical bar)."); } else if (string.IsNullOrWhiteSpace(details.Replace("|", ""))) { throw new ArgumentException("Suggest", "Please add content to the suggestion."); } string title = features[0]; string subtitle = features[1]; string description = features[2]; var embed = new EmbedBuilder() .WithTitle(title) .AddField(subtitle, description) .WithColor(Color.DarkBlue) .WithFooter($"By {Context.User.Username}#{Context.User.Discriminator}") .WithCurrentTimestamp(); var suggestMessage = await ReplyAsync(embed); Emoji[] emotes = { new Emoji(CurrentGuild.General.UpvoteEmote), new Emoji(CurrentGuild.General.DownvoteEmote) }; emotes = emotes.Where(e => e != null).ToArray(); await suggestMessage.AddReactionsAsync(emotes); } catch (ArgumentException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
//!play, Plays requested song by a user public async Task <Embed> PlaySongAsync(SocketGuildUser user, string query) { if (user.VoiceChannel == null) { return(await EmbedHandler.CreateErrorEmbed("Music, Play", "You must be in voice channel in order to use this command!")); } else { try { Options.TryAdd(user.Guild.Id, new AudioOptions { Summoner = user }); var player = _lavalink.DefaultNode.GetPlayer(user.Guild.Id); if (player == null) { return(await EmbedHandler.CreateBasicEmbed("Music, Play", "AmarilloBot must be in a voice channel to play songs! \nHOW? \n1. Connect to a voice channel \n2. Use command '!join'", Color.Orange)); } else { LavaTrack track; var search = await _lavalink.DefaultNode.SearchYouTubeAsync(query); if (search.LoadResultType == LoadResultType.NoMatches) { return(await EmbedHandler.CreateErrorEmbed("Sad face", $"Couldn't find anything in youtube that matches the {query}...")); } track = search.Tracks.FirstOrDefault(); if (player.CurrentTrack != null && player.IsPlaying || player.IsPaused) { player.Queue.Enqueue(track); return(await EmbedHandler.CreateBasicEmbed("Music, Play", $"Added song {track.Title} to queue \nPosition: {player.Queue.Count}\nDuration: {track.Length}", Color.Green)); } // Was not playing anything, so we play requested track await player.PlayAsync(track); await player.SetVolumeAsync(100); await LoggingService.LogInformationAsync("Node", $"Now playing {track.Title}, {track.Uri}"); return(await EmbedHandler.CreateBasicEmbed("Music, Play", $"Now Playing: {track.Title} - {track.Uri} \nDuration: {track.Length}", Color.Green)); } } catch (Exception ex) { return(await EmbedHandler.CreateErrorEmbed("Music, Play", $"{ex.ToString()}")); } } }
public async Task Join() { try { var user = Context.User as SocketGuildUser; Player = await JoinAndGetPlayer(); await ReplyAsync(EmbedHandler.CreateBasicEmbed(ModuleName, $"Now connected to `{user.VoiceChannel.Name}` and bound to `{Player.TextChannel.Name}`.", Color.Blue)); } catch (InvalidOperationException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
public async Task Shuffle() { try { await CheckPlayer(); Player.Queue.Shuffle(); await ReplyAsync(EmbedHandler.CreateBasicEmbed(ModuleName, $"Shuffled playlist.", Color.Blue)); } catch (InvalidOperationException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
public async Task NowPlaying() { try { await CheckPlayer(); await CheckIsPlaying("show track"); await SendNowPlayingEmbed(Player); } catch (InvalidOperationException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
public async Task <Embed> JoinOrPlayAsync(SocketGuildUser user, IMessageChannel textChannel, ulong guildId, string query = null) { if (user.VoiceChannel == null) { return(await EmbedHandler.CreateErrorEmbed("Music Join/Play", "You must first join a voice channel!")); } if (Options.TryGetValue(user.Guild.Id, out var options) && options.Summoner.Id != user.Id) { return(await EmbedHandler.CreateErrorEmbed("Music, Join/Play", $"I can't join another voice channel until {options.Summoner} disconnects me.")); } try { _lavaPlayer = _lavaShardClient.GetPlayer(guildId); if (_lavaPlayer == null) { await _lavaShardClient.ConnectAsync(user.VoiceChannel); Options.TryAdd(user.Guild.Id, new AudioOptions { Summoner = user }); _lavaPlayer = _lavaShardClient.GetPlayer(guildId); } LavaTrack track; var search = await _lavaRestClient.SearchYouTubeAsync(query); if (search.LoadType == LoadType.NoMatches && query != null) { return(await EmbedHandler.CreateErrorEmbed("Music", $"I wasn't able to find anything for {query}.")); } if (search.LoadType == LoadType.LoadFailed && query != null) { return(await EmbedHandler.CreateErrorEmbed("Music", $"I failed to load {query}.")); } track = search.Tracks.FirstOrDefault(); if (_lavaPlayer.CurrentTrack != null && _lavaPlayer.IsPlaying || _lavaPlayer.IsPaused) { _lavaPlayer.Queue.Enqueue(track); return(await EmbedHandler.CreateBasicEmbed("Music", $"{track.Title} has been added to queue.")); } await _lavaPlayer.PlayAsync(track); return(await EmbedHandler.CreateMusicEmbed("Music", $"Now Playing: {track.Title}\nUrl: {track.Uri}")); } catch (Exception e) { return(await EmbedHandler.CreateErrorEmbed("Music, Join/Play", e.Message)); } }
public async Task <Embed> SetVolume(SocketGuildUser user, IMessageChannel channel, int volume) { LavaPlayer player = lavalink.DefaultNode.GetPlayer(Config.Bot.ServerID); if (player.VoiceChannel != null) { await player.SetVolumeAsync(volume); return(await EmbedHandler.CreateEmbed("Audio", string.Format("{0} changed volume to {1}.", user.Username, volume.ToString()))); } else { return(await EmbedHandler.CreateErrorEmbed("Audio, Volume", "Not In a Voice Channel.")); } }
public async Task SendImage([Remainder] string url) { try { if (url is null) { throw new ArgumentException("Command argument must contain image URL."); } var embed = new EmbedBuilder(); embed.WithImageUrl(url); await ReplyAsync(embed); } catch (ArgumentException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
public async Task <Embed> ListAsync(ulong guildId) { var config = GlobalGuildAccounts.GetGuildAccount(guildId); var cmdPrefix = config.CommandPrefix; try { var descriptionBuilder = new StringBuilder(); var player = _lavaShardClient.GetPlayer(guildId); if (player == null) { return(await EmbedHandler.CreateErrorEmbed("Music Queue", $"Could not aquire music player.\nAre you using the music service right now? See `{cmdPrefix}h m` for proper usage.")); } if (player.IsPlaying) { if (player.Queue.Count < 1 && player.CurrentTrack != null) { return(await EmbedHandler.CreateBasicEmbed($"Now Playing: {player.CurrentTrack.Title}", "There are no other items in the queue.")); } else { var trackNum = 2; foreach (LavaTrack track in player.Queue.Items) { if (trackNum == 2) { descriptionBuilder.Append($"Up Next: [{track.Title}]({track.Uri})\n"); trackNum++; } else { descriptionBuilder.Append($"#{trackNum}: [{track.Title}]({track.Uri})\n"); trackNum++; } } return(await EmbedHandler.CreateBasicEmbed("Music Playlist", $"Now Playing: [{player.CurrentTrack.Title}]({player.CurrentTrack.Uri})\n{descriptionBuilder.ToString()}")); } } else { return(await EmbedHandler.CreateErrorEmbed("Music Queue", "Player doesn't seem to be playing anything right now. If this is an error, Please contact Stage in the Kaguya support server.")); } } catch (Exception ex) { return(await EmbedHandler.CreateErrorEmbed("Music, List", ex.Message)); } }
public async Task Resume() { try { await CheckPlayer(); if (!Player.IsPaused) { throw new InvalidOperationException($"Track already resumed."); } await Player.ResumeAsync(); await ReplyAsync(EmbedHandler.CreateBasicEmbed(ModuleName, $"**Resumed:** Now Playing {Hyperlink(Player.CurrentTrack)}.", Color.Blue)); } catch (InvalidOperationException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
public async Task UnmuteUser(SocketGuildUser target, [Remainder] string reason = "No reason provided.") { try { var user = await GuildUsers.GetAsync(target); if (!user.Status.IsMuted) { throw new InvalidOperationException($"User is not muted"); } await user.UnmuteAsync(reason, Context.User); await ReplyAsync(await EmbedHandler.CreateBasicEmbed(ModuleName, $"Unmuted {target.Mention} - `{reason}`.", Color.Orange)); } catch (InvalidOperationException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
public async Task KickUser(SocketGuildUser target, [Remainder] string reason = "No reason provided.") { try { var user = await GuildUsers.GetAsync(target); if (target.GuildPermissions.Administrator) { throw new InvalidOperationException($"Admins can't be kicked."); } await user.KickAsync(reason, Context.User); await ReplyAsync(await EmbedHandler.CreateBasicEmbed(ModuleName, $"Kicked {target.Mention} - `{reason}`.", Color.Orange)); } catch (InvalidOperationException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
public async Task Play([Remainder] string query) { try { Player = await JoinAndGetPlayer(); query = query.Replace("https://www.youtube.com/watch?v=", ""); var search = await lavaRestClient.SearchYouTubeAsync(query); if (search.LoadType == LoadType.NoMatches) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, $"OOF! I wasn't able to find anything for '{query}'.")); return; } var track = search.Tracks.FirstOrDefault(); if (track is null) { await ReplyAsync(EmbedHandler.CreateBasicEmbed(ModuleName, "No results found.", Color.Red)); return; } else if (track.Length > TimeSpan.FromHours(CurrentGuild.Music.MaxTrackHours)) { throw new ArgumentException($"Track duration must be less than `{CurrentGuild.Music.MaxTrackHours} hours`."); } if (Player.CurrentTrack != null || Player.IsPaused) { Player.Queue.Enqueue(track); AddEnqueuedTrack(track); await SendEnqueuedEmbed(track); } else { AddEnqueuedTrack(track); await Player.PlayAsync(track); await Player.SetVolumeAsync(CurrentGuild.Music.DefaultVolume); await ReplyAsync(EmbedHandler.CreateBasicEmbed(ModuleName, $"**Now playing**: {FullHyperlink(track)}", Color.Blue)); } } catch (InvalidOperationException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } catch (ArgumentException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
public async Task User(SocketGuildUser target = null, [Remainder] string action = "") { try { target ??= Context.User as SocketGuildUser; var user = await GuildUsers.GetAsync(target); if (action == "reset") { await ResetUser(target); return; } var embed = new EmbedBuilder() .WithThumbnailUrl(target.GetAvatarUrl()) .WithColor(Color.Orange) .WithTitle($"**{target.Username}**") .AddField("Warnings", user.Status.WarningsCount, inline: true); embed.AddField("Is Banned", user.Status.IsBanned, inline: true); if (user.Status.IsBanned) { var ban = user.Status.Bans.Last(); embed.AddField("Ban Reason", ban.Reason, inline: true); embed.AddField("Start of Ban", ban.Start, inline: true); embed.AddField("End of Ban", ban.End, inline: true); } embed.AddField("Is Muted", user.Status.IsMuted, inline: true); if (user.Status.IsMuted) { var mute = user.Status.Mutes.Last(); embed.AddField("Mute Reason", mute.Reason, inline: true); embed.AddField("Start of Mute", mute.Start, inline: true); embed.AddField("End of Mute", mute.End, inline: true); } var userInCooldown = await user.XP.GetXPCooldown(); embed.AddField("In XP Cooldown", userInCooldown, inline: true); await ReplyAsync(embed); } catch (ArgumentException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); } }
public async Task <Embed> ShowQueue(IGuild guild) { try { /* Create a string builder we can use to format how we want our list to be displayed. */ var descriptionBuilder = new StringBuilder(); /* Get The Player and make sure it isn't null. */ var player = _lavaNode.GetPlayer(guild); if (player == null) { return(await EmbedHandler.CreateErrorEmbed("Music, Queue", $"Could not aquire player.\nAre you using the bot right now? check{GlobalData.Config.DefaultPrefix}help for info on how to use the bot.")); } if (player.PlayerState is PlayerState.Playing) { /*If the queue count is less than 1 and the current track IS NOT null then we wont have a list to reply with. * In this situation we simply return an embed that displays the current track instead. */ if (player.Queue.Count < 1 && player.Track != null) { return(await EmbedHandler.CreateBasicEmbed($"Now Playing: {player.Track.Title}", "Nothing Else Is Queued.", Color.Blue)); } else { /* Now we know if we have something in the queue worth replying with, so we itterate through all the Tracks in the queue. * Next Add the Track title and the url however make use of Discords Markdown feature to display everything neatly. * This trackNum variable is used to display the number in which the song is in place. (Start at 2 because we're including the current song.*/ var trackNum = 2; foreach (LavaTrack track in player.Queue.Items) { descriptionBuilder.Append($"{trackNum}: [{track.Title}]({track.Url}) - {track.Id}\n"); trackNum++; } return(await EmbedHandler.CreateBasicEmbed("Queue", $"Now Playing: [{player.Track.Title}]({player.Track.Url}) \n{descriptionBuilder}", Color.Blue)); } } else { return(await EmbedHandler.CreateErrorEmbed("Music, Queue", "Player doesn't seem to be playing anything right now. If this is an error, Please Contact DekuTree.")); } } catch (Exception ex) { return(await EmbedHandler.CreateErrorEmbed("Music, Queue", ex.Message)); } }
// !list, displays songs in a queue as embed message in textchannel public async Task <Embed> ListSongsAsync(ulong guildId) { try { var player = _lavalink.DefaultNode.GetPlayer(guildId); if (player == null) { return(await EmbedHandler.CreateErrorEmbed("Music, List", "Could not aqcuire player. Are you using the bot right now?")); } if (player.IsPlaying) { if (player.Queue.Count < 1 && player.CurrentTrack != null) { return(await EmbedHandler.CreateBasicEmbed($"Currently playing {player.CurrentTrack.Title}", "No songs in queue\nHow to add? '!Play (songname)'", Color.LightOrange)); } else { var listBuilder = new StringBuilder(); var trackNum = 2; foreach (var track in player.Queue.Items) { listBuilder.Append($"{trackNum}: [{track.Title}]({track.Uri}) - {track.Id}\n"); trackNum++; } return(await EmbedHandler.CreateBasicEmbed("Music Playlist", $"Now Playing: [{player.CurrentTrack.Title}]({player.CurrentTrack.Uri})\n{listBuilder.ToString()}", Color.Blue)); } } else { return(await EmbedHandler.CreateBasicEmbed("Music, List", "Not playing currently anything\nUse '!pause' or '!play (songname)'", Color.Purple)); } } catch (Exception ex) { return(await EmbedHandler.CreateErrorEmbed("Music, List", ex.ToString())); } }
public async Task <Embed> JoinOrPlay(SocketGuildUser user, IMessageChannel channel, string query = null) { if (user.VoiceChannel == null) { return(await EmbedHandler.CreateErrorEmbed("Audio, Join/Play", "You Need To Be In a Voice Channel.")); } await lavalink.DefaultNode.ConnectAsync(user.VoiceChannel); if (query != null) { LavaPlayer player = lavalink.DefaultNode.GetPlayer(Config.Bot.ServerID); player.TextChannel = channel; IUserMessage message = await player.TextChannel.SendMessageAsync("Searching..."); LavaTrack track; LavaResult search = await lavalink.DefaultNode.SearchYouTubeAsync(query); if (search.LoadResultType == LoadResultType.NoMatches) { await message.DeleteAsync(); return(await EmbedHandler.CreateErrorEmbed("Audio, Query", "There Were No Query Results.")); } else { track = search.Tracks.FirstOrDefault(); await message.DeleteAsync(); if (player.CurrentTrack != null && player.IsPlaying || player.IsPaused) { player.Queue.Enqueue(track); return(await EmbedHandler.CreateEmbed("Audio", string.Format("{0} has been added to the queue.", track.Title))); } else { await player.PlayAsync(track); return(await EmbedHandler.CreateEmbed("Audio", string.Format("Now Playing: {0}.", track.Title))); } } } return(await EmbedHandler.CreateEmbed("Audio", "Joined voice channel " + user.VoiceChannel + ".")); }
public async Task <Embed> VolumeAsync(ulong guildId, int volume) { if (volume >= 150 || volume <= 0) { return(await EmbedHandler.CreateErrorEmbed($"Music Volume", $"Volume must be between 1 and 149.")); } try { var player = _lavaShardClient.GetPlayer(guildId); await player.SetVolumeAsync(volume); return(await EmbedHandler.CreateBasicEmbed($"🔊 Music Volume", $"Volume has been set to {volume}.")); } catch (InvalidOperationException ex) { return(await EmbedHandler.CreateErrorEmbed("Music Volume", $"{ex.Message}", "Please contact Stage in the support server if this is a recurring issue.")); } }