public bool StartQG(QuoteGame game, DiscordSocketClient client)
        {
            var rh = new QuoteGuessHandler(game, client);

            if (ActiveQG.TryAdd(game.Channel, rh))
            {
                rh.OnVoted += Rh_onvote;
                return(true);
            }
            return(false);
        }
        public async Task EndGameInChannel(IGuild guild, IMessageChannel ChannelID)
        {
            QuoteGame game = StopQG(ChannelID.Id);

            if (game != null)
            {
                if (game.Guesses.Select(x => x.QuoteGuess == game.Answer).FirstOrDefault())
                {
                    var        winnerID = game.Guesses.OrderBy(x => x.Timestamp).First(x => x.QuoteGuess == game.Answer);
                    IGuildUser user     = await guild.GetUserAsync(winnerID.UserID);

                    await ChannelID.BlankEmbedAsync(new EmbedBuilder().WithOkColour()
                                                    .AddField(new EmbedFieldBuilder().WithName("📣 Keyword").WithValue(game.Answer))
                                                    .AddField(new EmbedFieldBuilder().WithName("🎉 Winner").WithValue(user.Username)).Build());
                }
                else
                {
                    await ChannelID.BlankEmbedAsync(new EmbedBuilder().WithErrorColour()
                                                    .AddField(new EmbedFieldBuilder().WithName("📣 Keyword").WithValue(game.Answer))
                                                    .AddField(new EmbedFieldBuilder().WithName("🎉 Winner").WithValue("Nobody. That's sad.")).Build());
                }
            }
        }
Exemplo n.º 3
0
        private async Task QuoteGuess(int timeout = 15)
        {
            //Limit
            if (timeout > 30)
            {
                timeout = 30;
            }

            var dbConVal = new ValDBConnection(_config.ValDB, _logger);

            //Got quote
            QuoteModel q = await dbConVal.GetRandomQuote();

            if (q == null)
            {
                return;
            }

            QuoteGame Game = new QuoteGame
            {
                Channel = Context.Channel.Id,
                Answer  = q.Keyword,
                Guesses = new HashSet <QGuess>()
            };

            if (_quoteGuessService.StartQG(Game, (DiscordSocketClient)Context.Client))
            {
                //Start game
                await Context.Channel.SendSuccessAsync("📣 Quote", $"{q.Quote}");

                //Wait timeout
                await Task.Delay(timeout * 1000);

                //End
                await _quoteGuessService.EndGameInChannel(Context.Guild, Context.Channel);
            }
        }
 public QuoteGuessHandler(QuoteGame game, DiscordSocketClient client)
 {
     Game    = game;
     _client = client;
     _client.MessageReceived += TryGuess;
 }