Skip to content

Commit

Permalink
When the bot is in same audio channel as you, and you do the join com…
Browse files Browse the repository at this point in the history
…mand again, it will tell you its is already in the audio channel with you.
  • Loading branch information
Voltstro committed Dec 22, 2019
1 parent 55c407c commit 0714917
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Pootis-Bot/Modules/Audio/Music.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ await Context.Channel.SendMessageAsync(
return;
}

await _service.JoinAudio(Context.Guild, ((IVoiceState) Context.User).VoiceChannel, Context.Channel);
await _service.JoinAudio(Context.Guild, ((IVoiceState) Context.User).VoiceChannel, Context.Channel, Context.User.Id);
}

[Command("leave", RunMode = RunMode.Async)]
Expand Down
17 changes: 12 additions & 5 deletions src/Pootis-Bot/Services/Audio/AudioService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ public class AudioService
/// <summary>
/// Joins a guild voice channel, and sends messages to a text channel on error
/// </summary>
/// <param name="guild">What guild are we in</param>
/// <param name="target">The voice channel we are attempting to join</param>
/// <param name="channel">The message channel to log errors in</param>
/// <param name="guild"></param>
/// <param name="target"></param>
/// <param name="channel"></param>
/// <param name="userId"></param>
/// <returns></returns>
public async Task JoinAudio(IGuild guild, IVoiceChannel target, IMessageChannel channel)
public async Task JoinAudio(IGuild guild, IVoiceChannel target, IMessageChannel channel, ulong userId)
{
if (target == null)
{
Expand All @@ -38,6 +39,12 @@ public async Task JoinAudio(IGuild guild, IVoiceChannel target, IMessageChannel
ServerMusicItem serverMusic = GetMusicList(guild.Id);
if (serverMusic != null)
{
if (serverMusic.AudioChannel.GetUser(userId) != null)
{
await channel.SendMessageAsync(":musical_note: I am already in the same audio channel as you!");
return;
}

await channel.SendMessageAsync(
":musical_note: Sorry, but I am already playing in a different audio channel at the moment.");

Expand Down Expand Up @@ -147,7 +154,7 @@ public async Task SendAudio(SocketGuild guild, IMessageChannel channel, IVoiceCh

if (serverList == null)
{
await JoinAudio(guild, target, channel);
await JoinAudio(guild, target, channel, user.Id);

serverList = GetMusicList(guild.Id);
}
Expand Down

0 comments on commit 0714917

Please sign in to comment.