Exemplo n.º 1
0
        private async Task PlaySnippet(TriviaItem item)
        {
            _questions.RemoveAt(0);
            _currentItem = item;

            if (_streamCanceller != null)
            {
                _streamCanceller.Dispose();
            }

            _streamCanceller = new CancellationTokenSource();
            _streamProcess   = CreateStream("Resources/Music/" + item.filepath);
            _outputStream    = _streamProcess.StandardOutput.BaseStream;
            if (_discordStream == null)
            {
                _discordStream = _audioConnection.CreatePCMStream(AudioApplication.Music);
            }

            try
            {
                Task killTask = Task.Run(() => _streamProcess.WaitForExit(30000), _streamCanceller.Token);
                await Task.WhenAny(killTask, _outputStream.CopyToAsync(_discordStream, _streamCanceller.Token));
                await EndSnippet();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Exemplo n.º 2
0
        private async Task ShowQuestionCard(TriviaItem question)
        {
            TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

            EmbedBuilder builder = new EmbedBuilder();

            builder.WithColor(kEmbedColor);
            builder.WithTitle($"The song was: {textInfo.ToTitleCase(_currentItem.title[0])} - {textInfo.ToTitleCase(_currentItem.singer[0])}");
            var items = from pair in _mapPlayersToScores orderby pair.Value descending select pair;

            foreach (KeyValuePair <ulong, int> pair in items)
            {
                builder.AddField(_mapIdsToUsernames[pair.Key], pair.Value, false);
            }
            await(_textChannel as ISocketMessageChannel).SendMessageAsync("", false, builder.Build());
        }