Ejemplo n.º 1
0
        public async Task <IMessage> DisplayInDiscord(ISocketMessageChannel channel, Question question, DisplayMode display = DisplayMode.QCM, AudioModule am = null)
        {
            Console.WriteLine("Fonction d'affichage lancée ( Nom : DisplayInDiscord ) ");
            IUserMessage msg;

            if (display == DisplayMode.QCM)
            {
                if (question.type == QType.text)
                {
                    EmbedBuilder eb = (EmbedBuilder)question.content;
                    msg = await channel.SendMessageAsync("", false, eb);
                    await AddQcmReactions(msg);
                }
                else if (question.type == QType.image)
                {
                    Console.WriteLine("Tentative d'affichage pour type image...");
                    if (question.content.GetType() == typeof(List <EmbedBuilder>)) // si plusieurs embeds et donc plusieurs iamges
                    {
                        List <EmbedBuilder> imagesEb = (List <EmbedBuilder>)question.content;
                        // Liste d'eb donc liste d'images
                        if (question.imageQuestion == ImageQuestion.CorrespondingImageMultiple)
                        {
                            Console.WriteLine(" Type: images multiples");
                            foreach (var eb in (List <EmbedBuilder>)question.content)
                            {
                                // on envoie chaque image
                                await channel.SendMessageAsync(question.name, false, eb);
                            }
                            // Enfin, on affiche le nom de la question
                            msg = await channel.SendMessageAsync(question.name);
                            await AddQcmReactions(msg);
                        }
                        else
                        {
                            Console.WriteLine(" Type: image seule dans une Liste");
                            msg = await channel.SendMessageAsync("", false, imagesEb[SimpleID]);

                            SimpleID++;
                            await AddQcmReactions(msg);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Type: image seule");
                        // Si ce n'est pas une liste, c'est un seul élément, donc une seule image
                        EmbedBuilder eb = (EmbedBuilder)question.content;
                        msg = await channel.SendMessageAsync("DisplayInDiscord()", false, eb);
                        await AddQcmReactions(msg);
                    }
                }
                else if (question.type == QType.audio)
                {
                    Console.WriteLine(">>>Question Audio");
                    EmbedBuilder eb = ((question.content as object[])[0] as EmbedBuilder);
                    msg = await channel.SendMessageAsync("DisplayInDiscord()", false, eb);

                    try
                    {
                        // Permet d'empêcher l'audio module d'être recrée, ce qui entraînerait une exception
                        if (audioModule == null)
                        {
                            audioModule = am;
                        }
                        Thread t = new Thread(async() => await audioModule.PlayMusic("./BlindTest/" + ((question.content as object[])[1] as string)));
                        t.Start();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                    await AddQcmReactions(msg);


                    Console.WriteLine(">>>Succès");
                }
                else
                {
                    await Console.Out.WriteLineAsync("Pas de type texte ou image");

                    msg = await channel.SendMessageAsync("Questions de type : " + question.type + " pas encore gérées");
                    await AddQcmReactions(msg, true);
                }
                return(msg);
            }

            else
            {
                Console.WriteLine("A faire");
                return(null);
            }
        }