2016-08-21 22:37:39 +00:00
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using Discord.WebSocket;
|
|
|
|
|
using NadekoBot.Services;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Discord;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using NadekoBot.Attributes;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NadekoBot.Extensions;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using System.Collections.Generic;
|
2016-10-01 03:49:05 +00:00
|
|
|
|
using NadekoBot.Services.Database.Models;
|
2016-12-21 12:14:24 +00:00
|
|
|
|
using System.Threading;
|
2017-05-14 19:00:35 +00:00
|
|
|
|
using NadekoBot.Services.Music;
|
2017-05-29 04:13:22 +00:00
|
|
|
|
using NadekoBot.DataStructures;
|
2016-08-21 22:37:39 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Music
|
|
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
|
[NoPublicBot]
|
2017-04-08 19:03:07 +00:00
|
|
|
|
public class Music : NadekoTopLevelModule
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2017-05-24 04:43:00 +00:00
|
|
|
|
private static MusicService _music;
|
|
|
|
|
private readonly DiscordShardedClient _client;
|
|
|
|
|
private readonly IBotCredentials _creds;
|
|
|
|
|
private readonly IGoogleApiService _google;
|
2017-05-29 04:13:22 +00:00
|
|
|
|
private readonly DbService _db;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
|
|
|
|
|
public Music(DiscordShardedClient client, IBotCredentials creds, IGoogleApiService google,
|
2017-05-29 04:13:22 +00:00
|
|
|
|
DbService db, MusicService music)
|
2017-05-24 04:43:00 +00:00
|
|
|
|
{
|
|
|
|
|
_client = client;
|
|
|
|
|
_creds = creds;
|
|
|
|
|
_google = google;
|
|
|
|
|
_db = db;
|
|
|
|
|
_music = music;
|
2016-08-21 22:37:39 +00:00
|
|
|
|
//it can fail if its currenctly opened or doesn't exist. Either way i don't care
|
2017-05-14 19:00:35 +00:00
|
|
|
|
|
2017-05-24 04:43:00 +00:00
|
|
|
|
_client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated;
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
2016-12-21 12:14:24 +00:00
|
|
|
|
|
2017-05-24 04:43:00 +00:00
|
|
|
|
private Task Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState)
|
2016-12-14 19:48:44 +00:00
|
|
|
|
{
|
2016-12-17 00:16:14 +00:00
|
|
|
|
var usr = iusr as SocketGuildUser;
|
2016-12-14 19:48:44 +00:00
|
|
|
|
if (usr == null ||
|
|
|
|
|
oldState.VoiceChannel == newState.VoiceChannel)
|
2017-01-15 17:25:53 +00:00
|
|
|
|
return Task.CompletedTask;
|
2016-12-14 19:48:44 +00:00
|
|
|
|
|
|
|
|
|
MusicPlayer player;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((player = _music.GetPlayer(usr.Guild.Id)) == null)
|
2017-01-15 17:25:53 +00:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
2016-12-31 12:21:18 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-01-15 02:18:13 +00:00
|
|
|
|
//if bot moved
|
|
|
|
|
if ((player.PlaybackVoiceChannel == oldState.VoiceChannel) &&
|
2017-05-24 04:43:00 +00:00
|
|
|
|
usr.Id == _client.CurrentUser.Id)
|
2017-01-15 02:18:13 +00:00
|
|
|
|
{
|
|
|
|
|
if (player.Paused && newState.VoiceChannel.Users.Count > 1) //unpause if there are people in the new channel
|
|
|
|
|
player.TogglePause();
|
|
|
|
|
else if (!player.Paused && newState.VoiceChannel.Users.Count <= 1) // pause if there are no users in the new channel
|
|
|
|
|
player.TogglePause();
|
|
|
|
|
|
2017-01-15 17:25:53 +00:00
|
|
|
|
return Task.CompletedTask;
|
2017-01-15 02:18:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if some other user moved
|
2016-12-31 12:21:18 +00:00
|
|
|
|
if ((player.PlaybackVoiceChannel == newState.VoiceChannel && //if joined first, and player paused, unpause
|
|
|
|
|
player.Paused &&
|
2017-01-15 02:18:13 +00:00
|
|
|
|
newState.VoiceChannel.Users.Count == 2) || // keep in mind bot is in the channel (+1)
|
2016-12-31 12:21:18 +00:00
|
|
|
|
(player.PlaybackVoiceChannel == oldState.VoiceChannel && // if left last, and player unpaused, pause
|
|
|
|
|
!player.Paused &&
|
2017-01-15 02:18:13 +00:00
|
|
|
|
oldState.VoiceChannel.Users.Count == 1))
|
2016-12-31 12:21:18 +00:00
|
|
|
|
{
|
|
|
|
|
player.TogglePause();
|
2017-01-15 17:25:53 +00:00
|
|
|
|
return Task.CompletedTask;
|
2016-12-31 12:21:18 +00:00
|
|
|
|
}
|
2017-01-15 02:18:13 +00:00
|
|
|
|
|
2016-12-31 12:21:18 +00:00
|
|
|
|
}
|
2017-02-17 12:11:24 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2017-01-15 17:25:53 +00:00
|
|
|
|
return Task.CompletedTask;
|
2016-12-14 19:48:44 +00:00
|
|
|
|
}
|
2016-08-21 22:37:39 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public Task Next(int skipCount = 1)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2016-10-28 12:08:02 +00:00
|
|
|
|
if (skipCount < 1)
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
2016-08-21 22:37:39 +00:00
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2017-05-14 19:00:35 +00:00
|
|
|
|
return Task.CompletedTask;
|
2016-12-16 18:43:57 +00:00
|
|
|
|
if (musicPlayer.PlaybackVoiceChannel == ((IGuildUser)Context.User).VoiceChannel)
|
2016-10-28 12:08:02 +00:00
|
|
|
|
{
|
|
|
|
|
while (--skipCount > 0)
|
|
|
|
|
{
|
|
|
|
|
musicPlayer.RemoveSongAt(0);
|
|
|
|
|
}
|
2016-08-21 22:37:39 +00:00
|
|
|
|
musicPlayer.Next();
|
2016-10-28 12:08:02 +00:00
|
|
|
|
}
|
2016-09-10 19:40:25 +00:00
|
|
|
|
return Task.CompletedTask;
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public Task Stop()
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2017-05-14 19:00:35 +00:00
|
|
|
|
return Task.CompletedTask;
|
2016-12-16 18:43:57 +00:00
|
|
|
|
if (((IGuildUser)Context.User).VoiceChannel == musicPlayer.PlaybackVoiceChannel)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
musicPlayer.Autoplay = false;
|
|
|
|
|
musicPlayer.Stop();
|
|
|
|
|
}
|
2016-09-10 19:40:25 +00:00
|
|
|
|
return Task.CompletedTask;
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-01-05 20:58:11 +00:00
|
|
|
|
public Task Destroy()
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2017-01-04 12:23:30 +00:00
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2017-05-14 19:00:35 +00:00
|
|
|
|
return Task.CompletedTask;
|
2017-01-04 12:23:30 +00:00
|
|
|
|
if (((IGuildUser)Context.User).VoiceChannel == musicPlayer.PlaybackVoiceChannel)
|
2017-05-24 04:43:00 +00:00
|
|
|
|
_music.DestroyPlayer(Context.Guild.Id);
|
2017-01-04 12:23:30 +00:00
|
|
|
|
|
2017-01-05 20:58:11 +00:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public Task Pause()
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2017-05-14 19:00:35 +00:00
|
|
|
|
return Task.CompletedTask;
|
2016-12-16 18:43:57 +00:00
|
|
|
|
if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
|
2016-12-15 15:51:09 +00:00
|
|
|
|
return Task.CompletedTask;
|
2016-08-21 22:37:39 +00:00
|
|
|
|
musicPlayer.TogglePause();
|
2016-12-15 15:51:09 +00:00
|
|
|
|
return Task.CompletedTask;
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-25 05:39:04 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-31 10:55:12 +00:00
|
|
|
|
public async Task Fairplay()
|
2016-12-25 05:39:04 +00:00
|
|
|
|
{
|
2016-12-31 10:55:12 +00:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
2016-12-25 05:39:04 +00:00
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2017-05-14 19:00:35 +00:00
|
|
|
|
return;
|
2016-12-31 12:21:18 +00:00
|
|
|
|
if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
|
2016-12-25 05:39:04 +00:00
|
|
|
|
return;
|
|
|
|
|
var val = musicPlayer.FairPlay = !musicPlayer.FairPlay;
|
|
|
|
|
|
2017-02-25 01:04:32 +00:00
|
|
|
|
if (val)
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("fp_enabled").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("fp_disabled").ConfigureAwait(false);
|
|
|
|
|
}
|
2016-12-25 05:39:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task Queue([Remainder] string query)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2017-05-24 04:43:00 +00:00
|
|
|
|
await _music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, query).ConfigureAwait(false);
|
2016-12-17 04:09:04 +00:00
|
|
|
|
if ((await Context.Guild.GetCurrentUserAsync()).GetPermissions((IGuildChannel)Context.Channel).ManageMessages)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2016-12-31 10:55:12 +00:00
|
|
|
|
Context.Message.DeleteAfter(10);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task SoundCloudQueue([Remainder] string query)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2017-05-24 04:43:00 +00:00
|
|
|
|
await _music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, query, musicType: MusicType.Soundcloud).ConfigureAwait(false);
|
2016-12-17 04:09:04 +00:00
|
|
|
|
if ((await Context.Guild.GetCurrentUserAsync()).GetPermissions((IGuildChannel)Context.Channel).ManageMessages)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2016-12-31 12:21:18 +00:00
|
|
|
|
Context.Message.DeleteAfter(10);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task ListQueue(int page = 1)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2017-02-25 01:04:32 +00:00
|
|
|
|
Song currentSong;
|
2016-08-21 22:37:39 +00:00
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2017-05-14 19:00:35 +00:00
|
|
|
|
return;
|
|
|
|
|
if ((currentSong = musicPlayer?.CurrentSong) == null)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2017-02-25 11:16:48 +00:00
|
|
|
|
await ReplyErrorLocalized("no_player").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (page <= 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-12-22 03:49:33 +00:00
|
|
|
|
try { await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false); } catch { }
|
2016-12-21 11:59:25 +00:00
|
|
|
|
|
2016-12-22 03:49:33 +00:00
|
|
|
|
const int itemsPerPage = 10;
|
|
|
|
|
|
2016-12-27 14:18:12 +00:00
|
|
|
|
var total = musicPlayer.TotalPlaytime;
|
2017-02-25 01:04:32 +00:00
|
|
|
|
var totalStr = total == TimeSpan.MaxValue ? "∞" : GetText("time_format",
|
|
|
|
|
(int) total.TotalHours,
|
|
|
|
|
total.Minutes,
|
|
|
|
|
total.Seconds);
|
2016-12-27 14:18:12 +00:00
|
|
|
|
var maxPlaytime = musicPlayer.MaxPlaytimeSeconds;
|
2017-01-11 16:15:59 +00:00
|
|
|
|
var lastPage = musicPlayer.Playlist.Count / itemsPerPage;
|
2017-02-25 01:04:32 +00:00
|
|
|
|
Func<int, EmbedBuilder> printAction = curPage =>
|
2016-12-22 03:49:33 +00:00
|
|
|
|
{
|
2017-02-25 01:04:32 +00:00
|
|
|
|
var startAt = itemsPerPage * (curPage - 1);
|
2017-01-11 16:15:59 +00:00
|
|
|
|
var number = 0 + startAt;
|
2017-01-23 01:04:15 +00:00
|
|
|
|
var desc = string.Join("\n", musicPlayer.Playlist
|
|
|
|
|
.Skip(startAt)
|
|
|
|
|
.Take(itemsPerPage)
|
|
|
|
|
.Select(v => $"`{++number}.` {v.PrettyFullName}"));
|
2017-02-17 12:11:24 +00:00
|
|
|
|
|
|
|
|
|
desc = $"`🔊` {currentSong.PrettyFullName}\n\n" + desc;
|
2017-01-23 01:04:15 +00:00
|
|
|
|
|
|
|
|
|
if (musicPlayer.RepeatSong)
|
2017-02-25 01:04:32 +00:00
|
|
|
|
desc = "🔂 " + GetText("repeating_cur_song") +"\n\n" + desc;
|
2017-01-23 01:04:15 +00:00
|
|
|
|
else if (musicPlayer.RepeatPlaylist)
|
2017-02-25 01:04:32 +00:00
|
|
|
|
desc = "🔁 " + GetText("repeating_playlist")+"\n\n" + desc;
|
|
|
|
|
|
2017-01-23 01:04:15 +00:00
|
|
|
|
|
|
|
|
|
|
2017-01-11 16:15:59 +00:00
|
|
|
|
var embed = new EmbedBuilder()
|
2017-02-25 01:04:32 +00:00
|
|
|
|
.WithAuthor(eab => eab.WithName(GetText("player_queue", curPage, lastPage + 1))
|
|
|
|
|
.WithMusicIcon())
|
2017-01-23 01:04:15 +00:00
|
|
|
|
.WithDescription(desc)
|
2017-01-11 16:15:59 +00:00
|
|
|
|
.WithFooter(ef => ef.WithText($"{musicPlayer.PrettyVolume} | {musicPlayer.Playlist.Count} " +
|
2017-02-25 01:04:32 +00:00
|
|
|
|
$"{("tracks".SnPl(musicPlayer.Playlist.Count))} | {totalStr} | " +
|
|
|
|
|
(musicPlayer.FairPlay
|
|
|
|
|
? "✔️" + GetText("fairplay")
|
|
|
|
|
: "✖️" + GetText("fairplay")) + " | " +
|
|
|
|
|
(maxPlaytime == 0 ? "unlimited" : GetText("play_limit", maxPlaytime))))
|
2017-01-11 16:15:59 +00:00
|
|
|
|
.WithOkColor();
|
|
|
|
|
|
|
|
|
|
return embed;
|
|
|
|
|
};
|
2017-05-24 04:43:00 +00:00
|
|
|
|
await Context.Channel.SendPaginatedConfirmAsync(_client, page, printAction, lastPage, false).ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task NowPlaying()
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
|
|
|
|
var currentSong = musicPlayer.CurrentSong;
|
|
|
|
|
if (currentSong == null)
|
|
|
|
|
return;
|
2016-12-22 22:29:25 +00:00
|
|
|
|
try { await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false); } catch { }
|
2016-10-19 10:40:43 +00:00
|
|
|
|
|
2016-12-27 13:32:58 +00:00
|
|
|
|
var embed = new EmbedBuilder().WithOkColor()
|
2017-02-25 01:04:32 +00:00
|
|
|
|
.WithAuthor(eab => eab.WithName(GetText("now_playing")).WithMusicIcon())
|
2016-12-27 13:32:58 +00:00
|
|
|
|
.WithDescription(currentSong.PrettyName)
|
2016-12-31 12:21:18 +00:00
|
|
|
|
.WithThumbnailUrl(currentSong.Thumbnail)
|
2016-12-27 14:18:12 +00:00
|
|
|
|
.WithFooter(ef => ef.WithText(musicPlayer.PrettyVolume + " | " + currentSong.PrettyFullTime + $" | {currentSong.PrettyProvider} | {currentSong.QueuerName}"));
|
2016-12-27 13:32:58 +00:00
|
|
|
|
|
2016-12-31 12:21:18 +00:00
|
|
|
|
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task Volume(int val)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
2016-12-16 18:43:57 +00:00
|
|
|
|
if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
2017-02-25 01:04:32 +00:00
|
|
|
|
if (val < 0 || val > 100)
|
|
|
|
|
{
|
|
|
|
|
await ReplyErrorLocalized("volume_input_invalid").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
2017-02-25 01:04:32 +00:00
|
|
|
|
}
|
2016-08-21 22:37:39 +00:00
|
|
|
|
var volume = musicPlayer.SetVolume(val);
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyConfirmLocalized("volume_set", volume).ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
2016-08-30 01:22:15 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-30 01:22:15 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task Defvol([Remainder] int val)
|
2016-08-30 01:22:15 +00:00
|
|
|
|
{
|
|
|
|
|
if (val < 0 || val > 100)
|
|
|
|
|
{
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyErrorLocalized("volume_input_invalid").ConfigureAwait(false);
|
2016-08-30 01:22:15 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-24 04:43:00 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-08-30 01:22:15 +00:00
|
|
|
|
{
|
2016-12-17 00:16:14 +00:00
|
|
|
|
uow.GuildConfigs.For(Context.Guild.Id, set => set).DefaultMusicVolume = val / 100.0f;
|
2016-08-30 01:22:15 +00:00
|
|
|
|
uow.Complete();
|
|
|
|
|
}
|
2017-02-26 21:56:24 +00:00
|
|
|
|
await ReplyConfirmLocalized("defvol_set", val).ConfigureAwait(false);
|
2016-08-30 01:22:15 +00:00
|
|
|
|
}
|
2016-08-21 22:37:39 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task ShufflePlaylist()
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
2016-12-16 18:43:57 +00:00
|
|
|
|
if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
|
|
|
|
if (musicPlayer.Playlist.Count < 2)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
musicPlayer.Shuffle();
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyConfirmLocalized("songs_shuffled").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task Playlist([Remainder] string playlist)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2016-12-21 12:14:24 +00:00
|
|
|
|
|
2016-08-21 22:37:39 +00:00
|
|
|
|
var arg = playlist;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(arg))
|
|
|
|
|
return;
|
2016-12-17 00:16:14 +00:00
|
|
|
|
if (((IGuildUser)Context.User).VoiceChannel?.Guild != Context.Guild)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyErrorLocalized("must_be_in_voice").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-24 04:43:00 +00:00
|
|
|
|
var plId = (await _google.GetPlaylistIdsByKeywordsAsync(arg).ConfigureAwait(false)).FirstOrDefault();
|
2016-08-21 22:37:39 +00:00
|
|
|
|
if (plId == null)
|
|
|
|
|
{
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyErrorLocalized("no_search_results").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-24 04:43:00 +00:00
|
|
|
|
var ids = await _google.GetPlaylistTracksAsync(plId, 500).ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
if (!ids.Any())
|
|
|
|
|
{
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyErrorLocalized("no_search_results").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-12-24 01:45:51 +00:00
|
|
|
|
var count = ids.Count();
|
2017-03-02 09:47:15 +00:00
|
|
|
|
var msg = await Context.Channel.SendMessageAsync("🎵 " + GetText("attempting_to_queue",
|
|
|
|
|
Format.Bold(count.ToString()))).ConfigureAwait(false);
|
2016-12-27 00:35:46 +00:00
|
|
|
|
|
2016-12-21 12:14:24 +00:00
|
|
|
|
var cancelSource = new CancellationTokenSource();
|
|
|
|
|
|
2016-12-31 12:21:18 +00:00
|
|
|
|
var gusr = (IGuildUser)Context.User;
|
2016-12-27 00:35:46 +00:00
|
|
|
|
while (ids.Any() && !cancelSource.IsCancellationRequested)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2017-01-05 20:45:40 +00:00
|
|
|
|
var tasks = Task.WhenAll(ids.Take(5).Select(async id =>
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2016-12-24 01:45:51 +00:00
|
|
|
|
if (cancelSource.Token.IsCancellationRequested)
|
2016-12-27 00:35:46 +00:00
|
|
|
|
return;
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-24 04:43:00 +00:00
|
|
|
|
await _music.QueueSong(gusr, (ITextChannel)Context.Channel, gusr.VoiceChannel, id, true).ConfigureAwait(false);
|
2016-12-27 00:35:46 +00:00
|
|
|
|
}
|
|
|
|
|
catch (SongNotFoundException) { }
|
|
|
|
|
catch { try { cancelSource.Cancel(); } catch { } }
|
|
|
|
|
}));
|
2016-12-21 12:14:24 +00:00
|
|
|
|
|
2016-12-27 00:35:46 +00:00
|
|
|
|
await Task.WhenAny(tasks, Task.Delay(Timeout.Infinite, cancelSource.Token));
|
|
|
|
|
ids = ids.Skip(5);
|
|
|
|
|
}
|
2016-12-21 12:14:24 +00:00
|
|
|
|
|
2017-03-02 09:47:15 +00:00
|
|
|
|
await msg.ModifyAsync(m => m.Content = "✅ " + Format.Bold(GetText("playlist_queue_complete"))).ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task SoundCloudPl([Remainder] string pl)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2016-12-21 12:14:24 +00:00
|
|
|
|
|
2016-08-21 22:37:39 +00:00
|
|
|
|
pl = pl?.Trim();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(pl))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
using (var http = new HttpClient())
|
|
|
|
|
{
|
2017-05-24 04:43:00 +00:00
|
|
|
|
var scvids = JObject.Parse(await http.GetStringAsync($"http://api.soundcloud.com/resolve?url={pl}&client_id={_creds.SoundCloudClientId}").ConfigureAwait(false))["tracks"].ToObject<SoundCloudVideo[]>();
|
|
|
|
|
await _music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, scvids[0].TrackLink).ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
|
2017-05-14 19:00:35 +00:00
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (var svideo in scvids.Skip(1))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-14 19:00:35 +00:00
|
|
|
|
musicPlayer.AddSong(new Song(new SongInfo
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
Title = svideo.FullName,
|
|
|
|
|
Provider = "SoundCloud",
|
2017-05-24 04:43:00 +00:00
|
|
|
|
Uri = svideo.GetStreamLink(_creds),
|
2016-08-21 22:37:39 +00:00
|
|
|
|
ProviderType = MusicType.Normal,
|
|
|
|
|
Query = svideo.TrackLink,
|
2016-12-16 18:43:57 +00:00
|
|
|
|
}), ((IGuildUser)Context.User).Username);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
catch (PlaylistFullException) { break; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-09-30 02:20:09 +00:00
|
|
|
|
[OwnerOnly]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task LocalPl([Remainder] string directory)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2016-12-21 12:14:24 +00:00
|
|
|
|
|
2016-08-21 22:37:39 +00:00
|
|
|
|
var arg = directory;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(arg))
|
|
|
|
|
return;
|
2017-02-14 13:30:21 +00:00
|
|
|
|
var dir = new DirectoryInfo(arg);
|
|
|
|
|
var fileEnum = dir.GetFiles("*", SearchOption.AllDirectories)
|
|
|
|
|
.Where(x => !x.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System));
|
|
|
|
|
var gusr = (IGuildUser)Context.User;
|
|
|
|
|
foreach (var file in fileEnum)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2017-02-14 13:30:21 +00:00
|
|
|
|
try
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2017-05-24 04:43:00 +00:00
|
|
|
|
await _music.QueueSong(gusr, (ITextChannel)Context.Channel, gusr.VoiceChannel, file.FullName, true, MusicType.Local).ConfigureAwait(false);
|
2017-02-14 13:30:21 +00:00
|
|
|
|
}
|
|
|
|
|
catch (PlaylistFullException)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyConfirmLocalized("dir_queue_complete").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-02-25 01:04:32 +00:00
|
|
|
|
public async Task Radio(string radioLink)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2016-12-21 12:14:24 +00:00
|
|
|
|
|
2016-12-17 00:16:14 +00:00
|
|
|
|
if (((IGuildUser)Context.User).VoiceChannel?.Guild != Context.Guild)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyErrorLocalized("must_be_in_voice").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-24 04:43:00 +00:00
|
|
|
|
await _music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, radioLink, musicType: MusicType.Radio).ConfigureAwait(false);
|
2016-12-17 04:09:04 +00:00
|
|
|
|
if ((await Context.Guild.GetCurrentUserAsync()).GetPermissions((IGuildChannel)Context.Channel).ManageMessages)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2016-12-31 10:55:12 +00:00
|
|
|
|
Context.Message.DeleteAfter(10);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-09-30 02:20:09 +00:00
|
|
|
|
[OwnerOnly]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task Local([Remainder] string path)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2016-12-21 12:14:24 +00:00
|
|
|
|
|
2016-08-21 22:37:39 +00:00
|
|
|
|
var arg = path;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(arg))
|
|
|
|
|
return;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
await _music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, path, musicType: MusicType.Local).ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-15 02:18:13 +00:00
|
|
|
|
//[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
//[RequireContext(ContextType.Guild)]
|
|
|
|
|
//public async Task Move()
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
// MusicPlayer musicPlayer;
|
|
|
|
|
// var voiceChannel = ((IGuildUser)Context.User).VoiceChannel;
|
|
|
|
|
// if (voiceChannel == null || voiceChannel.Guild != Context.Guild || !MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer))
|
|
|
|
|
// return;
|
|
|
|
|
// await musicPlayer.MoveToVoiceChannel(voiceChannel);
|
|
|
|
|
//}
|
2016-08-21 22:37:39 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-10-19 08:10:57 +00:00
|
|
|
|
[Priority(0)]
|
2017-06-02 01:44:59 +00:00
|
|
|
|
public Task SongRemove(int num)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2017-01-05 20:58:11 +00:00
|
|
|
|
return Task.CompletedTask;
|
2016-12-16 18:43:57 +00:00
|
|
|
|
if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
|
2017-01-05 20:58:11 +00:00
|
|
|
|
return Task.CompletedTask;
|
2017-01-03 15:02:02 +00:00
|
|
|
|
|
2017-01-03 14:46:16 +00:00
|
|
|
|
musicPlayer.RemoveSongAt(num - 1);
|
2017-01-05 20:58:11 +00:00
|
|
|
|
return Task.CompletedTask;
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
2016-09-03 13:04:07 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-10-19 08:10:57 +00:00
|
|
|
|
[Priority(1)]
|
2017-06-02 01:44:59 +00:00
|
|
|
|
public async Task SongRemove(string all)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
if (all.Trim().ToUpperInvariant() != "ALL")
|
|
|
|
|
return;
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2017-05-14 19:00:35 +00:00
|
|
|
|
return;
|
2016-08-21 22:37:39 +00:00
|
|
|
|
musicPlayer.ClearQueue();
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyConfirmLocalized("queue_cleared").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task MoveSong([Remainder] string fromto)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
2017-02-17 10:38:06 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(fromto))
|
|
|
|
|
return;
|
2016-12-17 00:16:14 +00:00
|
|
|
|
|
2016-08-21 22:37:39 +00:00
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
2017-05-14 19:00:35 +00:00
|
|
|
|
|
2016-08-21 22:37:39 +00:00
|
|
|
|
fromto = fromto?.Trim();
|
|
|
|
|
var fromtoArr = fromto.Split('>');
|
|
|
|
|
|
|
|
|
|
int n1;
|
|
|
|
|
int n2;
|
|
|
|
|
|
|
|
|
|
var playlist = musicPlayer.Playlist as List<Song> ?? musicPlayer.Playlist.ToList();
|
|
|
|
|
|
|
|
|
|
if (fromtoArr.Length != 2 || !int.TryParse(fromtoArr[0], out n1) ||
|
|
|
|
|
!int.TryParse(fromtoArr[1], out n2) || n1 < 1 || n2 < 1 || n1 == n2 ||
|
|
|
|
|
n1 > playlist.Count || n2 > playlist.Count)
|
|
|
|
|
{
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyConfirmLocalized("invalid_input").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var s = playlist[n1 - 1];
|
|
|
|
|
playlist.Insert(n2 - 1, s);
|
|
|
|
|
var nn1 = n2 < n1 ? n1 : n1 - 1;
|
|
|
|
|
playlist.RemoveAt(nn1);
|
2016-12-31 12:21:18 +00:00
|
|
|
|
|
|
|
|
|
var embed = new EmbedBuilder()
|
|
|
|
|
.WithTitle($"{s.SongInfo.Title.TrimTo(70)}")
|
2017-02-17 10:38:06 +00:00
|
|
|
|
.WithUrl(s.SongUrl)
|
2017-02-25 01:04:32 +00:00
|
|
|
|
.WithAuthor(eab => eab.WithName(GetText("song_moved")).WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/258605269972549642/music1.png"))
|
|
|
|
|
.AddField(fb => fb.WithName(GetText("from_position")).WithValue($"#{n1}").WithIsInline(true))
|
|
|
|
|
.AddField(fb => fb.WithName(GetText("to_position")).WithValue($"#{n2}").WithIsInline(true))
|
2016-12-31 12:21:18 +00:00
|
|
|
|
.WithColor(NadekoBot.OkColor);
|
|
|
|
|
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
|
2016-12-14 19:29:01 +00:00
|
|
|
|
//await channel.SendConfirmAsync($"🎵Moved {s.PrettyName} `from #{n1} to #{n2}`").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-02-05 06:52:39 +00:00
|
|
|
|
public async Task SetMaxQueue(uint size = 0)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
2016-12-31 12:21:18 +00:00
|
|
|
|
|
2016-08-21 22:37:39 +00:00
|
|
|
|
musicPlayer.MaxQueueSize = size;
|
2017-02-25 01:04:32 +00:00
|
|
|
|
|
|
|
|
|
if(size == 0)
|
|
|
|
|
await ReplyConfirmLocalized("max_queue_unlimited").ConfigureAwait(false);
|
|
|
|
|
else
|
|
|
|
|
await ReplyConfirmLocalized("max_queue_x", size).ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-31 10:55:12 +00:00
|
|
|
|
public async Task SetMaxPlaytime(uint seconds)
|
2016-12-27 13:32:58 +00:00
|
|
|
|
{
|
2016-12-27 14:18:12 +00:00
|
|
|
|
if (seconds < 15 && seconds != 0)
|
2016-12-27 13:32:58 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2016-12-31 10:55:12 +00:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
2016-12-27 13:32:58 +00:00
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2016-12-27 13:32:58 +00:00
|
|
|
|
return;
|
|
|
|
|
musicPlayer.MaxPlaytimeSeconds = seconds;
|
2016-12-31 12:21:18 +00:00
|
|
|
|
if (seconds == 0)
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyConfirmLocalized("max_playtime_none").ConfigureAwait(false);
|
2016-12-27 13:32:58 +00:00
|
|
|
|
else
|
2017-03-01 20:42:20 +00:00
|
|
|
|
await ReplyConfirmLocalized("max_playtime_set", seconds).ConfigureAwait(false);
|
2016-12-27 13:32:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-01-01 12:26:17 +00:00
|
|
|
|
public async Task ReptCurSong()
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
|
|
|
|
var currentSong = musicPlayer.CurrentSong;
|
|
|
|
|
if (currentSong == null)
|
|
|
|
|
return;
|
|
|
|
|
var currentValue = musicPlayer.ToggleRepeatSong();
|
2016-12-22 03:49:33 +00:00
|
|
|
|
|
|
|
|
|
if (currentValue)
|
2016-12-31 12:21:18 +00:00
|
|
|
|
await Context.Channel.EmbedAsync(new EmbedBuilder()
|
2016-12-22 03:49:33 +00:00
|
|
|
|
.WithOkColor()
|
2017-02-25 01:04:32 +00:00
|
|
|
|
.WithAuthor(eab => eab.WithMusicIcon().WithName("🔂 " + GetText("repeating_track")))
|
2016-12-24 19:49:29 +00:00
|
|
|
|
.WithDescription(currentSong.PrettyName)
|
2016-12-31 10:55:12 +00:00
|
|
|
|
.WithFooter(ef => ef.WithText(currentSong.PrettyInfo))).ConfigureAwait(false);
|
2016-12-22 03:49:33 +00:00
|
|
|
|
else
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await Context.Channel.SendConfirmAsync("🔂 " + GetText("repeating_track_stopped"))
|
2016-08-21 22:37:39 +00:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task RepeatPl()
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
|
|
|
|
var currentValue = musicPlayer.ToggleRepeatPlaylist();
|
2017-02-25 01:04:32 +00:00
|
|
|
|
if(currentValue)
|
|
|
|
|
await ReplyConfirmLocalized("rpl_enabled").ConfigureAwait(false);
|
|
|
|
|
else
|
|
|
|
|
await ReplyConfirmLocalized("rpl_disabled").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-10-01 03:49:05 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task Save([Remainder] string name)
|
2016-10-01 03:49:05 +00:00
|
|
|
|
{
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2016-10-01 03:49:05 +00:00
|
|
|
|
return;
|
2016-08-21 22:37:39 +00:00
|
|
|
|
|
2016-10-01 03:49:05 +00:00
|
|
|
|
var curSong = musicPlayer.CurrentSong;
|
|
|
|
|
var songs = musicPlayer.Playlist.Append(curSong)
|
2016-12-21 12:14:24 +00:00
|
|
|
|
.Select(s => new PlaylistSong()
|
|
|
|
|
{
|
2016-10-01 03:49:05 +00:00
|
|
|
|
Provider = s.SongInfo.Provider,
|
|
|
|
|
ProviderType = s.SongInfo.ProviderType,
|
|
|
|
|
Title = s.SongInfo.Title,
|
|
|
|
|
Uri = s.SongInfo.Uri,
|
|
|
|
|
Query = s.SongInfo.Query,
|
|
|
|
|
}).ToList();
|
2016-08-21 22:37:39 +00:00
|
|
|
|
|
2016-10-01 03:49:05 +00:00
|
|
|
|
MusicPlaylist playlist;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-10-01 03:49:05 +00:00
|
|
|
|
{
|
|
|
|
|
playlist = new MusicPlaylist
|
|
|
|
|
{
|
|
|
|
|
Name = name,
|
2016-12-16 18:43:57 +00:00
|
|
|
|
Author = Context.User.Username,
|
|
|
|
|
AuthorId = Context.User.Id,
|
2016-10-01 03:49:05 +00:00
|
|
|
|
Songs = songs,
|
|
|
|
|
};
|
|
|
|
|
uow.MusicPlaylists.Add(playlist);
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
2016-08-21 22:37:39 +00:00
|
|
|
|
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
|
|
|
|
|
.WithTitle(GetText("playlist_saved"))
|
|
|
|
|
.AddField(efb => efb.WithName(GetText("name")).WithValue(name))
|
|
|
|
|
.AddField(efb => efb.WithName(GetText("id")).WithValue(playlist.Id.ToString())));
|
2016-10-01 03:49:05 +00:00
|
|
|
|
}
|
2016-08-21 22:37:39 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-10-01 03:49:05 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task Load([Remainder] int id)
|
2016-10-01 03:49:05 +00:00
|
|
|
|
{
|
|
|
|
|
MusicPlaylist mpl;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-10-01 03:49:05 +00:00
|
|
|
|
{
|
|
|
|
|
mpl = uow.MusicPlaylists.GetWithSongs(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mpl == null)
|
|
|
|
|
{
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyErrorLocalized("playlist_id_not_found").ConfigureAwait(false);
|
2016-10-01 03:49:05 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-05 05:01:19 +00:00
|
|
|
|
IUserMessage msg = null;
|
2017-02-27 21:44:10 +00:00
|
|
|
|
try { msg = await Context.Channel.SendMessageAsync(GetText("attempting_to_queue", Format.Bold(mpl.Songs.Count.ToString()))).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
2016-10-01 03:49:05 +00:00
|
|
|
|
foreach (var item in mpl.Songs)
|
|
|
|
|
{
|
2016-12-16 18:43:57 +00:00
|
|
|
|
var usr = (IGuildUser)Context.User;
|
2016-10-01 03:49:05 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-24 04:43:00 +00:00
|
|
|
|
await _music.QueueSong(usr, (ITextChannel)Context.Channel, usr.VoiceChannel, item.Query, true, item.ProviderType).ConfigureAwait(false);
|
2016-10-01 03:49:05 +00:00
|
|
|
|
}
|
2016-11-14 23:07:36 +00:00
|
|
|
|
catch (SongNotFoundException) { }
|
2016-10-01 03:49:05 +00:00
|
|
|
|
catch { break; }
|
|
|
|
|
}
|
2016-10-05 05:01:19 +00:00
|
|
|
|
if (msg != null)
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await msg.ModifyAsync(m => m.Content = GetText("playlist_queue_complete")).ConfigureAwait(false);
|
2016-10-01 03:49:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-10-01 03:49:05 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task Playlists([Remainder] int num = 1)
|
2016-10-01 03:49:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (num <= 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
List<MusicPlaylist> playlists;
|
|
|
|
|
|
2017-05-24 04:43:00 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-10-01 03:49:05 +00:00
|
|
|
|
{
|
|
|
|
|
playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-22 03:49:33 +00:00
|
|
|
|
var embed = new EmbedBuilder()
|
2017-02-25 01:04:32 +00:00
|
|
|
|
.WithAuthor(eab => eab.WithName(GetText("playlists_page", num)).WithMusicIcon())
|
|
|
|
|
.WithDescription(string.Join("\n", playlists.Select(r =>
|
2017-03-10 22:06:22 +00:00
|
|
|
|
GetText("playlists", r.Id, r.Name, r.Author, r.Songs.Count))))
|
2016-12-22 03:49:33 +00:00
|
|
|
|
.WithOkColor();
|
2016-12-31 10:55:12 +00:00
|
|
|
|
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
2016-10-01 03:49:05 +00:00
|
|
|
|
|
|
|
|
|
}
|
2017-01-29 04:56:55 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-10-01 17:35:11 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task DeletePlaylist([Remainder] int id)
|
2016-10-01 17:35:11 +00:00
|
|
|
|
{
|
2017-02-25 01:04:32 +00:00
|
|
|
|
var success = false;
|
2016-10-02 01:00:03 +00:00
|
|
|
|
try
|
2016-10-01 17:35:11 +00:00
|
|
|
|
{
|
2017-05-24 04:43:00 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-10-01 17:35:11 +00:00
|
|
|
|
{
|
2017-02-25 01:04:32 +00:00
|
|
|
|
var pl = uow.MusicPlaylists.Get(id);
|
2016-10-02 01:00:03 +00:00
|
|
|
|
|
|
|
|
|
if (pl != null)
|
2016-10-01 17:35:11 +00:00
|
|
|
|
{
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if (_creds.IsOwner(Context.User) || pl.AuthorId == Context.User.Id)
|
2016-10-02 01:00:03 +00:00
|
|
|
|
{
|
|
|
|
|
uow.MusicPlaylists.Remove(pl);
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
success = true;
|
|
|
|
|
}
|
2016-10-01 17:35:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 01:00:03 +00:00
|
|
|
|
if (!success)
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyErrorLocalized("playlist_delete_fail").ConfigureAwait(false);
|
2016-10-02 01:00:03 +00:00
|
|
|
|
else
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyConfirmLocalized("playlist_deleted").ConfigureAwait(false);
|
2016-10-02 01:00:03 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2017-01-29 04:56:55 +00:00
|
|
|
|
_log.Warn(ex);
|
2016-10-02 01:00:03 +00:00
|
|
|
|
}
|
2016-10-01 17:35:11 +00:00
|
|
|
|
}
|
2016-08-21 22:37:39 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 19:45:46 +00:00
|
|
|
|
public async Task Goto(int time)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
2016-12-16 18:43:57 +00:00
|
|
|
|
if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (time < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var currentSong = musicPlayer.CurrentSong;
|
|
|
|
|
|
|
|
|
|
if (currentSong == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//currentSong.PrintStatusMessage = false;
|
|
|
|
|
var gotoSong = currentSong.Clone();
|
|
|
|
|
gotoSong.SkipTo = time;
|
|
|
|
|
musicPlayer.AddSong(gotoSong, 0);
|
|
|
|
|
musicPlayer.Next();
|
|
|
|
|
|
|
|
|
|
var minutes = (time / 60).ToString();
|
|
|
|
|
var seconds = (time % 60).ToString();
|
|
|
|
|
|
|
|
|
|
if (minutes.Length == 1)
|
|
|
|
|
minutes = "0" + minutes;
|
|
|
|
|
if (seconds.Length == 1)
|
|
|
|
|
seconds = "0" + seconds;
|
|
|
|
|
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyConfirmLocalized("skipped_to", minutes, seconds).ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-21 22:37:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-01-01 12:26:17 +00:00
|
|
|
|
public async Task Autoplay()
|
2016-08-21 22:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2016-08-21 22:37:39 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!musicPlayer.ToggleAutoplay())
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyConfirmLocalized("autoplay_disabled").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
else
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyConfirmLocalized("autoplay_enabled").ConfigureAwait(false);
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-30 04:40:19 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
[RequireUserPermission(GuildPermission.ManageMessages)]
|
|
|
|
|
public async Task SetMusicChannel()
|
|
|
|
|
{
|
|
|
|
|
MusicPlayer musicPlayer;
|
2017-05-24 04:43:00 +00:00
|
|
|
|
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
|
2017-01-30 04:40:19 +00:00
|
|
|
|
{
|
2017-02-28 02:22:46 +00:00
|
|
|
|
await ReplyErrorLocalized("no_player").ConfigureAwait(false);
|
2017-01-30 04:40:19 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
musicPlayer.OutputTextChannel = (ITextChannel)Context.Channel;
|
|
|
|
|
|
2017-02-25 01:04:32 +00:00
|
|
|
|
await ReplyConfirmLocalized("set_music_channel").ConfigureAwait(false);
|
2017-01-30 04:40:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-21 22:37:39 +00:00
|
|
|
|
}
|
2016-12-23 03:50:49 +00:00
|
|
|
|
}
|