Example #1
0
 private async Task Client_MessageCreatedAsync(DSharpPlus.EventArgs.MessageCreateEventArgs e)
 {
     if (e.Message.Content.Contains(":foodReview:"))
     {
         VoiceNextExtension voiceNextClient = Program.Client.GetVoiceNext();
         VoiceNextConnection voiceNextCon = voiceNextClient.GetConnection(e.Guild);
         if (voiceNextCon == null)
         {
             foreach (DiscordVoiceState vs in e.Guild.VoiceStates)
             {
                 if (vs.User.Username.Equals(e.Author.Username))
                 {
                     voiceNextCon = await voiceNextClient.ConnectAsync(vs.Channel);
                 }
             }
         }
         if (voiceNextCon == null)
         {
             // user wasnt in a voice channel
             return;
         }
         else
         {
             // await PlayAudio(voiceNextCon, @"AudioFiles\foodReview.mp3");
             voiceNextCon.Disconnect();
         }
     }
 }
Example #2
0
        private async Task VoiceStateUpdated(DiscordClient client, VoiceStateUpdateEventArgs e)
        {
            VoiceNextConnection vnc = _voiceNextExtension.GetConnection(e.Guild);

            if (vnc == null)
            {
                return;
            }

            if (e.User.Id == client.CurrentUser.Id)
            {
                if (!e.After.IsServerDeafened)
                {
                    DiscordMember member = await e.Guild.GetMemberAsync(e.User.Id);

                    await member.ModifyAsync(member => member.Deafened = true);
                }
            }
            else
            {
                if (e.Before?.Channel != null && e.Before.Channel.Id == vnc.TargetChannel.Id && e.Before.Channel.Users.Where(u => !u.IsBot).Count() == 0)
                {
                    vnc.Disconnect();
                }
            }
        }
Example #3
0
        public async Task Leave(CommandContext ctx)
        {
            DiscordMessage tmp = await ctx.RespondAsync("DC");

            VoiceNextExtension vnext = ctx.Client.GetVoiceNext();
            await tmp.DeleteAsync();

            tmp = await ctx.RespondAsync("DC: GVNC");

            VoiceNextConnection vnc = vnext.GetConnection(ctx.Guild);
            await tmp.DeleteAsync();

            tmp = await ctx.RespondAsync("DC: CVNC");

            if (vnc == null)
            {
                throw new InvalidOperationException("Not connected in this guild.");
            }
            await tmp.DeleteAsync();

            tmp = await ctx.RespondAsync("DC: DCXC");

            vnc.Disconnect();
            await tmp.DeleteAsync();

            await ctx.RespondAsync("👌");
        }
Example #4
0
        /// <summary>
        /// Make the musicbot leave the channel
        /// </summary>
        /// <param name="duser">Args = Amount to remove</param>
        /// <returns></returns>
        public static async Task MusicLeave(DUser duser)
        {
            // check whether VNext is enabled
            var vnext = duser.BuildinVoiceNextClient;

            if (vnext == null)
            {
                // not enabled
                await DiscordUtils.SendBotMessage("VNext is not enabled or configured. Contact Botmaker for help!", duser);

                return;
            }

            // check whether we are connected
            VoiceNextConnection vnc = Program.Voice.GetConnection(duser.Guild);

            Utils.Debug("Guild, " + duser.Guild.Name);
            if (vnc == null)
            {
                // not connected
                await DiscordUtils.SendBotMessage(Messages.AudioNotConnected, duser);

                return;
            }

            // disconnect
            vnc.Disconnect();
            await DiscordUtils.SendBotMessage(Utils.Replace(Messages.AudioDisconnected, "~1", vnc.Channel.Name), duser);
        }
Example #5
0
        public Task DisconnectAsync(CommandContext ctx)
        {
            VoiceNextExtension vnext = ctx.Client.GetVoiceNext();

            if (vnext == null)
            {
                throw new CommandFailedException("VNext is not enabled or configured.");
            }

            VoiceNextConnection vnc = vnext.GetConnection(ctx.Guild);

            if (vnc == null)
            {
                throw new CommandFailedException("Not connected in this guild.");
            }

            if (MusicPlayers.ContainsKey(ctx.Guild.Id))
            {
                MusicPlayers[ctx.Guild.Id].Stop();
                MusicPlayers.TryRemove(ctx.Guild.Id, out _);
            }

            // TODO check await Task.Delay(500);
            vnc.Disconnect();

            return(this.InformAsync(ctx, StaticDiscordEmoji.Headphones, "Disconnected.", important: false));
        }
Example #6
0
        public async Task Leave(CommandContext ctx)
        {
            VoiceNextClient vnext = ctx.Client.GetVoiceNextClient();

            if (vnext == null)
            {
                // not enabled
                await ctx.RespondAsync("VNext is not enabled or configured.");

                return;
            }

            // check whether we are connected

            VoiceNextConnection vnc = vnext.GetConnection(ctx.Guild);

            if (vnc == null)
            {
                // not connected
                await ctx.RespondAsync("Not connected in this guild.");

                return;
            }

            // disconnect
            vnc.Disconnect();
            await ctx.RespondAsync("Disconnected");
        }
Example #7
0
        public async Task RunCommand(CommandContext ctx, VoiceNextConnection connection)
        {
            DiscordChannel channel = ctx.Member.VoiceState.Channel;

            if (channel == null)
            {
                Console.WriteLine("Not connected in this guild.");
            }

            await ctx.RespondAsync("Bye Bye");

            connection.Disconnect();
        }
Example #8
0
        public async Task Remover(CommandContext ctx, VoiceNextConnection vnc)
        {
            if (Fila.Count == 0)
            {
                await vnc.SendSpeakingAsync(false);

                vnc?.Disconnect();
                StatusDaFila = EnumeradorDeStatusDaFila.Parada;
            }
            else
            {
                var proximaExecucao = Fila.Dequeue();
                await AoExecutarMusica?.Invoke(proximaExecucao);
            }
        }
Example #9
0
        private async void AudioPlayingThread()
        {
            while (true)
            {
                try
                {
                    PlayQueueElement elementToPlay = playQueue.Take();
                    Program.Client.DebugLogger.Info($"Took [{elementToPlay.Filepath}] off the queue");

                    // Connect if not already
                    VoiceNextExtension  voiceNextClient = Program.Client.GetVoiceNext();
                    VoiceNextConnection voiceNextCon    = voiceNextClient.GetConnection(elementToPlay.GuildToJoin);
                    if (voiceNextCon == null)
                    {
                        Program.Client.DebugLogger.Info($"Not currently connected");
                        Task <VoiceNextConnection> voiceNextConTask = voiceNextClient.ConnectAsync(elementToPlay.ChannelToJoin);
                        voiceNextConTask.Wait(new TimeSpan(0, 0, 3));
                        if (voiceNextConTask.IsCompletedSuccessfully)
                        {
                            voiceNextCon = voiceNextConTask.Result;
                            Program.Client.DebugLogger.Info($"Joined: {voiceNextCon.Channel}");
                        }
                        else
                        {
                            Program.Client.DebugLogger.Error($"Could not join: {elementToPlay.ChannelToJoin.Name}");
                            continue;
                        }
                    }

                    await PlayAudio(voiceNextCon, elementToPlay.Filepath);

                    if (playQueue.Count == 0)
                    {
                        voiceNextCon.Disconnect();
                        Program.Client.DebugLogger.Info($"Leaving: {voiceNextCon.Channel}");
                    }
                }
                catch (Exception ex)
                {
                    Program.Client.DebugLogger.Critical($"Exception was caught in the Audio Thread: {ex}");
                }
            }
        }
Example #10
0
        public async Task Leave(CommandContext ctx)
        {
            VoiceNextConnection vnc = ctx.GetVoiceNext().GetConnection(ctx.Guild);

            if (vnc == null)
            {
                await ctx.Message.RespondAsync("I'm not in a voice channel!");
            }
            else if (ctx.Member.VoiceState.Channel == null)
            {
                await ctx.Message.RespondAsync("You are not in a voice channel!");
            }
            else if (vnc.TargetChannel.Id != ctx.Member.VoiceState.Channel.Id)
            {
                await ctx.Message.RespondAsync("I am not in your channel!");
            }
            else if (vnc != null)
            {
                vnc.Disconnect();
            }
        }
Example #11
0
        public async Task PlayAsync()
        {
            if (Connection == null)
            {
                return;
            }

            if (AudioInfos.TryDequeue(out AudioInfo audioInfo))
            {
                await PlayAsync(Connection, audioInfo);

                if (AudioInfos.Count == 0 && Connection != null)
                {
                    Connection.Disconnect();
                    Connection = null;
                }
                else
                {
                    await PlayAsync();
                }
            }
        }
        public async Task Leave(CommandContext ctx)
        {
            VoiceNextExtension vnext = ctx.Client.GetVoiceNext();

            if (vnext == null)
            {
                await ctx.RespondAsync("VNext is not enabled or configured.");

                return;
            }

            VoiceNextConnection vnc = vnext.GetConnection(ctx.Guild);

            if (vnc == null)
            {
                await ctx.RespondAsync("Not connected in this guild.");

                return;
            }

            vnc.Disconnect();
            await ctx.RespondAsync("Disconnected");
        }
Example #13
0
        public async Task Leave(CommandContext ctx, bool clearQueue = false)
        {
            VoiceNextExtension vnext = ctx.Client.GetVoiceNext();

            VoiceNextConnection vnc = vnext.GetConnection(ctx.Guild);

            if (vnc == null)
            {
                throw new OutputException("Not connected in this guild.");
            }

            if (clearQueue)
            {
                GuildQueues[ctx.Guild.Id].Clear();
            }
            GuildMusicStatuses[ctx.Guild.Id].Skip = true;
            Thread.Sleep(500);
            GuildMusicStatuses.Remove(ctx.Guild.Id);
            Directory.Delete(Path.Combine(Globals.AppPath, "Queue", ctx.Guild.Id.ToString()), true);

            vnc.Disconnect();
            await ctx.RespondAsync("Left connected channel.");
        }
Example #14
0
        public async Task Leave(CommandContext ctx)
        {
            VoiceNextExtension voice = ctx.Client.GetVoiceNext();

            if (voice == null)
            {
                await ctx.Message.RespondAsync("Voice is not activated").ConfigureAwait(false);

                return;
            }

            VoiceNextConnection vnc = await GetVNextConnection(ctx);

            if (vnc == null)
            {
                return;
            }
            if (vnc.IsPlaying)
            {
                vnc.Pause();
            }
            vnc.Disconnect();
            await ctx.RespondAsync("Disconnected");
        }
 public void Stop()
 {
     //
     vnc.Disconnect();
 }