stuff
This commit is contained in:
parent
9cab284d24
commit
4060c72ac1
@ -24,6 +24,8 @@ namespace TextCommandFramework.Modules
|
||||
var user = Context.User;
|
||||
if (user.IsBot) return;
|
||||
|
||||
Console.WriteLine("Joining on " + Context.Guild.Name);
|
||||
|
||||
string youtubeUrl = text;
|
||||
IVoiceChannel channel = (Context.User as IVoiceState).VoiceChannel;
|
||||
if (channel is null)
|
||||
|
@ -18,21 +18,21 @@ namespace Kasbot.Services
|
||||
Clients = new Dictionary<ulong, Connection>();
|
||||
}
|
||||
|
||||
private async Task<Connection> CreateConnection(SocketCommandContext Context)
|
||||
private async Task<Connection> CreateConnection(ulong guildId, IVoiceChannel voiceChannel)
|
||||
{
|
||||
IVoiceChannel channel = (Context.User as IVoiceState).VoiceChannel;
|
||||
var conn = new Connection();
|
||||
IAudioClient audioClient = await channel.ConnectAsync();
|
||||
IAudioClient audioClient = await voiceChannel.ConnectAsync(selfDeaf: true);
|
||||
|
||||
audioClient.Disconnected += (ex) => Stop(Context.Guild.Id);
|
||||
audioClient.StreamDestroyed += (ex) => Stop(Context.Guild.Id);
|
||||
audioClient.Disconnected += (ex) => Stop(guildId);
|
||||
audioClient.StreamDestroyed += (ex) => Stop(guildId);
|
||||
|
||||
conn.AudioClient = audioClient;
|
||||
conn.AudioChannel = voiceChannel;
|
||||
|
||||
if (Clients.ContainsKey(Context.Guild.Id))
|
||||
Clients.Remove(Context.Guild.Id);
|
||||
if (Clients.ContainsKey(guildId))
|
||||
Clients.Remove(guildId);
|
||||
|
||||
Clients.Add(Context.Guild.Id, conn);
|
||||
Clients.Add(guildId, conn);
|
||||
|
||||
return conn;
|
||||
}
|
||||
@ -52,7 +52,7 @@ namespace Kasbot.Services
|
||||
return;
|
||||
}
|
||||
|
||||
conn = await CreateConnection(Context);
|
||||
conn = await CreateConnection(Context.Guild.Id, (Context.User as IVoiceState).VoiceChannel);
|
||||
await Enqueue(Context.Guild.Id, conn, media);
|
||||
}
|
||||
|
||||
@ -115,6 +115,14 @@ namespace Kasbot.Services
|
||||
return;
|
||||
}
|
||||
|
||||
// since we can't verify if the bot was disconnected by a websocket error, we do this check
|
||||
if (Clients[guildId].AudioClient.ConnectionState == ConnectionState.Disconnected)
|
||||
{
|
||||
var voiceChannel = Clients[guildId].AudioChannel;
|
||||
Clients.Remove(guildId);
|
||||
await CreateConnection(guildId, voiceChannel);
|
||||
}
|
||||
|
||||
var mp3Stream = await YoutubeService.DownloadAudioFromYoutube(nextMedia);
|
||||
|
||||
if (mp3Stream == null)
|
||||
@ -183,7 +191,7 @@ namespace Kasbot.Services
|
||||
});
|
||||
await stdout.ContinueWith(async ac =>
|
||||
{
|
||||
if (ac.Exception!= null)
|
||||
if (ac.Exception != null)
|
||||
{
|
||||
await nextMedia.Channel.SendTemporaryMessageAsync("Error while playing: " + ac.Exception.ToString());
|
||||
}
|
||||
@ -271,6 +279,7 @@ namespace Kasbot.Services
|
||||
public class Connection
|
||||
{
|
||||
public IAudioClient AudioClient { get; set; }
|
||||
public IVoiceChannel AudioChannel { get; set; }
|
||||
public Stream? CurrentAudioStream { get; set; }
|
||||
public Queue<Media> Queue { get; set; } = new Queue<Media>();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user