small changes, music queue to 50, takes 30 from pl

This commit is contained in:
Master Kwoth 2016-02-23 01:21:22 +01:00
parent 7d11f94088
commit 8d0fc191d8
10 changed files with 27 additions and 24 deletions

View File

@ -69,7 +69,7 @@ namespace NadekoBot.Classes.Music {
if (VoiceClient == null) {
Console.WriteLine($"Joining voice channel [{DateTime.Now.Second}]");
//todo add a new event, to tell people nadeko is trying to join
VoiceClient = await VoiceChannel.JoinAudio();
VoiceClient = await Task.Run(async () => await VoiceChannel.JoinAudio());
Console.WriteLine($"Joined voicechannel [{DateTime.Now.Second}]");
}
await Task.Factory.StartNew(async () => await CurrentSong?.Start(), TaskCreationOptions.LongRunning).Unwrap();

View File

@ -74,6 +74,8 @@ namespace NadekoBot.Classes.Music {
if (OnResolving != null)
OnResolving();
var links = await SearchHelper.FindYoutubeUrlByKeywords(Query);
if (links == String.Empty)
throw new OperationCanceledException("Not a valid youtube query.");
var allVideos = await Task.Factory.StartNew(async () => await YouTube.Default.GetAllVideosAsync(links)).Unwrap();
var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio);
var video = videos

View File

@ -21,13 +21,13 @@ namespace NadekoBot.Classes {
}
}
public static async Task<string> GetResponseAsync(string v) =>
await new StreamReader((await ((HttpWebRequest)WebRequest.Create(v)).GetResponseAsync()).GetResponseStream()).ReadToEndAsync();
public static async Task<string> GetResponseAsync(string v, WebHeaderCollection headers) {
public static async Task<string> GetResponseAsync(string v, WebHeaderCollection headers = null) {
var wr = (HttpWebRequest)WebRequest.Create(v);
wr.Headers = headers;
return await new StreamReader((await wr.GetResponseAsync()).GetResponseStream()).ReadToEndAsync();
if (headers != null)
wr.Headers = headers;
using (var sr = new StreamReader((await wr.GetResponseAsync()).GetResponseStream())) {
return await sr.ReadToEndAsync();
}
}
private static string token = "";
@ -112,10 +112,11 @@ namespace NadekoBot.Classes {
WebRequest wr = WebRequest.Create("https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=" + Uri.EscapeDataString(v) + "&key=" + NadekoBot.GoogleAPIKey);
var sr = new StreamReader((await wr.GetResponseAsync()).GetResponseStream());
using (var sr = new StreamReader((await wr.GetResponseAsync()).GetResponseStream())) {
dynamic obj = JObject.Parse(await sr.ReadToEndAsync());
return "http://www.youtube.com/watch?v=" + obj.items[0].id.videoId.ToString();
dynamic obj = JObject.Parse(await sr.ReadToEndAsync());
return "http://www.youtube.com/watch?v=" + obj.items[0].id.videoId.ToString();
}
}
catch (Exception ex) {
Console.WriteLine($"Error in findyoutubeurl: {ex.Message}");
@ -150,7 +151,7 @@ namespace NadekoBot.Classes {
}
try {
WebRequest wr = WebRequest.Create($"https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults={25}&playlistId={v}&key={ NadekoBot.creds.GoogleAPIKey }");
WebRequest wr = WebRequest.Create($"https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults={30}&playlistId={v}&key={ NadekoBot.creds.GoogleAPIKey }");
var sr = new StreamReader((await wr.GetResponseAsync()).GetResponseStream());

View File

@ -77,12 +77,12 @@ namespace NadekoBot.Classes.Trivia {
// load next question if game is still running
await Task.Delay(2000);
}
End();
End().Wait();
}
private void End() {
_channel.SendMessage("**Trivia game ended**");
_channel.SendMessage(GetLeaderboard());
private async Task End() {
await _channel.SendMessage("**Trivia game ended**");
await _channel.SendMessage(GetLeaderboard());
TriviaGame throwAwayValue;
Commands.Trivia.runningTrivias.TryRemove(_server, out throwAwayValue);
}

View File

@ -337,7 +337,7 @@ namespace NadekoBot.Commands {
bases[i].TimeAdded = DateTime.Now;
}
Task.Run(async () => await ClearArray());
await Task.Delay(new TimeSpan(23, 0, 0), endTokenSource.Token);
await Task.Delay(new TimeSpan(24, 0, 0), endTokenSource.Token);
}
catch (Exception) { }
finally {

View File

@ -79,7 +79,7 @@ namespace NadekoBot.Modules {
}
var player = musicPlayers[e.Server];
string toSend = "🎵 **" + player.SongQueue.Count + "** `videos currently queued.` ";
if (player.SongQueue.Count >= 25)
if (player.SongQueue.Count >= 50)
toSend += "**Song queue is full!**\n";
await e.Channel.SendMessage(toSend);
int number = 1;
@ -190,12 +190,12 @@ namespace NadekoBot.Modules {
.Parameter("playlist", ParameterType.Unparsed)
.Do(async e => {
if (e.User.VoiceChannel?.Server != e.Server) {
await e.Channel.SendMessage("💢 You need to be in the voice channel on this server.");
await e.Channel.SendMessage("💢 You need to be in the voice channel on this server.\n If you already are in a voice channel, try rejoining it.");
return;
}
var ids = await SearchHelper.GetVideoIDs(await SearchHelper.GetPlaylistIdByKeyword(e.GetArg("playlist")));
//todo TEMPORARY SOLUTION, USE RESOLVE QUEUE IN THE FUTURE
var msg = await e.Channel.SendMessage($"🎵 `Attempting to queue **{ids.Count}** songs".SnPl(ids.Count)+"...`");
var msg = await e.Channel.SendMessage($"🎵 `Attempting to queue {ids.Count} songs".SnPl(ids.Count)+"...`");
foreach (var id in ids) {
Task.Run(async () => await QueueSong(e, id, true)).ConfigureAwait(false);
await Task.Delay(150);
@ -208,7 +208,7 @@ namespace NadekoBot.Modules {
.Parameter("radio_link", ParameterType.Required)
.Do(async e => {
if (e.User.VoiceChannel?.Server != e.Server) {
await e.Channel.SendMessage("💢 You need to be in the voice channel on this server.");
await e.Channel.SendMessage("💢 You need to be in the voice channel on this server.\n If you already are in a voice channel, try rejoining it.");
return;
}
await QueueSong(e, e.GetArg("radio_link"), radio: true);
@ -235,7 +235,7 @@ namespace NadekoBot.Modules {
}
if (arg?.ToLower() == "all") {
mc.SongQueue?.Clear();
await e.Channel.SendMessage($"🎵Queue cleared!");
await e.Channel.SendMessage($"🎵`Queue cleared!`");
return;
}
int num;
@ -246,7 +246,7 @@ namespace NadekoBot.Modules {
return;
mc.SongQueue.RemoveAt(num - 1);
await e.Channel.SendMessage($"🎵Song at position `{num}` has been removed.");
await e.Channel.SendMessage($"🎵**Track at position `#{num}` has been removed.**");
});
cgb.CreateCommand("debug")
@ -263,7 +263,7 @@ namespace NadekoBot.Modules {
private async Task QueueSong(CommandEventArgs e, string query, bool silent = false, bool radio = false) {
if (e.User.VoiceChannel?.Server != e.Server) {
await e.Channel.SendMessage("💢 You need to be in the voice channel on this server.");
await e.Channel.SendMessage("💢 You need to be in the voice channel on this server.\n If you are already in a voice channel, try rejoining.");
return;
}
@ -291,7 +291,7 @@ namespace NadekoBot.Modules {
var player = musicPlayers[e.Server];
if (player.SongQueue.Count >= 25) return;
if (player.SongQueue.Count >= 50) return;
try {
var sr = new StreamRequest(e, query, player, radio);

Binary file not shown.