small changes
This commit is contained in:
parent
d242952d4a
commit
f8ad6dda50
@ -253,10 +253,9 @@ namespace NadekoBot.Modules.Music
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public Task Destroy()
|
||||
public async Task Destroy()
|
||||
{
|
||||
_music.DestroyPlayer(Context.Guild.Id);
|
||||
return Task.CompletedTask;
|
||||
await _music.DestroyPlayer(Context.Guild.Id);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
|
@ -15,7 +15,7 @@ namespace NadekoBot.Services.Music
|
||||
Playing,
|
||||
Completed
|
||||
}
|
||||
public class MusicPlayer : IDisposable
|
||||
public class MusicPlayer
|
||||
{
|
||||
private readonly Task _player;
|
||||
private readonly IVoiceChannel VoiceChannel;
|
||||
@ -92,7 +92,12 @@ namespace NadekoBot.Services.Music
|
||||
});
|
||||
var ac = await GetAudioClient();
|
||||
if (ac == null)
|
||||
{
|
||||
await Task.Delay(900);
|
||||
// just wait some time, maybe bot doesn't even have perms to join that voice channel,
|
||||
// i don't want to spam connection attempts
|
||||
continue;
|
||||
}
|
||||
var pcm = ac.CreatePCMStream(AudioApplication.Music);
|
||||
|
||||
OnStarted?.Invoke(this, data.Song);
|
||||
@ -175,9 +180,9 @@ namespace NadekoBot.Services.Music
|
||||
{
|
||||
Stopped = false;
|
||||
Unpause();
|
||||
}
|
||||
CancelCurrentSong();
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop(bool clearQueue = false)
|
||||
{
|
||||
@ -188,9 +193,9 @@ namespace NadekoBot.Services.Music
|
||||
if (clearQueue)
|
||||
Queue.Clear();
|
||||
Unpause();
|
||||
}
|
||||
CancelCurrentSong();
|
||||
}
|
||||
}
|
||||
|
||||
private void Unpause()
|
||||
{
|
||||
@ -283,19 +288,23 @@ namespace NadekoBot.Services.Music
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public async Task Destroy()
|
||||
{
|
||||
_log.Info("Disposing");
|
||||
_log.Info("Destroying");
|
||||
lock (locker)
|
||||
{
|
||||
Stop();
|
||||
Exited = true;
|
||||
Unpause();
|
||||
}
|
||||
CancelCurrentSong();
|
||||
|
||||
OnCompleted = null;
|
||||
OnPauseChanged = null;
|
||||
OnStarted = null;
|
||||
}
|
||||
var ac = _audioClient;
|
||||
if (ac != null)
|
||||
await ac.StopAsync();
|
||||
}
|
||||
|
||||
|
||||
//private IAudioClient AudioClient { get; set; }
|
||||
|
@ -112,8 +112,11 @@ namespace NadekoBot.Services.Music
|
||||
}
|
||||
|
||||
public void ResetCurrent()
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
CurrentIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,9 @@ using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Text.RegularExpressions;
|
||||
using NLog;
|
||||
using System.IO;
|
||||
using VideoLibrary;
|
||||
using System.Net.Http;
|
||||
using System.Collections.Generic;
|
||||
using Discord.Commands;
|
||||
|
||||
@ -235,10 +233,10 @@ namespace NadekoBot.Services.Music
|
||||
return song;
|
||||
}
|
||||
|
||||
public void DestroyPlayer(ulong id)
|
||||
public async Task DestroyPlayer(ulong id)
|
||||
{
|
||||
if (MusicPlayers.TryRemove(id, out var mp))
|
||||
mp.Dispose();
|
||||
await mp.Destroy();
|
||||
}
|
||||
|
||||
// public async Task QueueSong(IGuildUser queuer, ITextChannel textCh, IVoiceChannel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal)
|
||||
|
Loading…
Reference in New Issue
Block a user