Esempio n. 1
0
        //implement further
        public async Task Ready(CommandContext ctx)
        {
            var interactivity = ctx.Client.GetInteractivity();

            var discordEmoji = new DiscordEmoji[1];

            discordEmoji[0] = DiscordEmoji.FromUnicode("👍🏽");

            var options = discordEmoji.Select(x => x.ToString());

            var pollEmbed = new DiscordEmbedBuilder
            {
                Title = "Are you ready to Begin?",
                //Description = string.Join("Press the check mark to signify you are ready: ", options)
            };

            var pollMessage = await ctx.Channel.SendMessageAsync(embed : pollEmbed).ConfigureAwait(false);

            foreach (var option in discordEmoji)
            {
                await pollMessage.CreateReactionAsync(option).ConfigureAwait(false);
            }
            int readyCheck = 0;

            while (readyCheck != PLAYERS)
            {
                // _ = interactivity.WaitForReactionAsync().ConfigureAwait(false);
                readyCheck++;
            }
            //displays what emojis what was used
            await ctx.Channel.SendMessageAsync($"All {readyCheck} players are ready...It's time to begin!").ConfigureAwait(false);
        }
Esempio n. 2
0
        public async Task Start(CommandContext ctx)
        {
            var interactivity = ctx.Client.GetInteractivity();

            var discordEmoji = new DiscordEmoji[1];

            discordEmoji[0] = DiscordEmoji.FromUnicode("👍🏽");

            var options = discordEmoji.Select(x => x.ToString());

            var pollEmbed = new DiscordEmbedBuilder
            {
                Title       = "Who wants to play a game?",
                Description = string.Join("", discordEmoji[0])
            };

            var pollMessage = await ctx.Channel.SendMessageAsync(embed : pollEmbed).ConfigureAwait(false);

            foreach (var option in discordEmoji)
            {
                await pollMessage.CreateReactionAsync(option).ConfigureAwait(false);
            }

            var result = await interactivity.CollectReactionsAsync(pollMessage, DURATION).ConfigureAwait(false);

            var distinctResult = result.Distinct().Count();

            PLAYERS = distinctResult;

            if (PLAYERS == 0)
            {
                await ctx.Channel.SendMessageAsync(PLAYERS + " players is playing :(").ConfigureAwait(false);
            }

            else if (PLAYERS == 1)
            {
                await ctx.Channel.SendMessageAsync(PLAYERS + " player is playing! \nType /ready to begin the game!").ConfigureAwait(false);
            }

            else
            {
                await ctx.Channel.SendMessageAsync(PLAYERS + " players are playing! \nType /ready to begin the game!").ConfigureAwait(false);
            }
        }
        public async Task Gamble(CommandContext ctx, int amount = 100)
        {
            if (ctx.Channel.Name == "casino")
            {
                DiscordEmoji   joinEmoji    = DiscordEmoji.FromName(ctx.Client, ":white_check_mark:");
                DiscordEmoji[] emojiOptions = new DiscordEmoji[] { joinEmoji };

                var interactivity = ctx.Client.GetInteractivity();
                var options       = emojiOptions.Select(x => x.ToString());
                int betAmount     = amount;
                if (betAmount < 100)
                {
                    betAmount = 100;
                }

                var gambleEmbed = new DiscordEmbedBuilder
                {
                    Title       = $"${betAmount:N} Roll Signup",
                    Description = $"Wait for users to join and roll for the amount you bet.\n" +
                                  $"Lowest roll pays highest roll the difference.\n" +
                                  $"If you did not roll the highest/lowest number,\n" +
                                  $"then you do not lose/gain any money.\n" +
                                  $"After 10 seconds the game will begin.\n" +
                                  $"$100 minimum\n\n" +
                                  $"{joinEmoji} to join the game",
                    Color = DiscordColor.Purple
                };

                gambleEmbed.AddField("Current Bet", $"${betAmount:N}");

                var gambleMessage = await ctx.Channel.SendMessageAsync(embed : gambleEmbed).ConfigureAwait(false);

                foreach (var option in emojiOptions)
                {
                    await gambleMessage.CreateReactionAsync(option).ConfigureAwait(false);
                }

                var result = await interactivity.CollectReactionsAsync(gambleMessage, TimeSpan.FromSeconds(10)).ConfigureAwait(false);

                var results = result.Select(x => x.Users);
                Dictionary <DiscordMember, int> rollResults = new Dictionary <DiscordMember, int>();

                var resultEmbed = new DiscordEmbedBuilder
                {
                    Title = $"Results",
                    Color = DiscordColor.Green
                };

                foreach (var players in results)
                {
                    foreach (var player in players)
                    {
                        int roll = random.Next(1, betAmount);
                        var u    = await ctx.Guild.GetMemberAsync(player.Id);

                        Users user = await _userService.GetUserById(u.Id.ToString()).ConfigureAwait(false);

                        if (!u.IsBot && user.CashBalance >= betAmount)
                        {
                            resultEmbed.AddField($"{u.DisplayName}", $"{roll}", true);
                            rollResults.Add(u, roll);
                        }
                    }
                }

                if (rollResults.Count < 2)
                {
                    var errorEmbed = new DiscordEmbedBuilder
                    {
                        Description = $"Either not enough players registered or not enough\n" +
                                      $"players have the cash amount required to play.",
                        Color = DiscordColor.Red
                    };

                    await ctx.Channel.SendMessageAsync(embed : errorEmbed).ConfigureAwait(false);

                    return;
                }

                var winner  = rollResults.Aggregate((l, r) => l.Value > r.Value ? l : r).Key;
                var loser   = rollResults.Aggregate((l, r) => l.Value < r.Value ? l : r).Key;
                var jackpot = rollResults[winner] - rollResults[loser];
                resultEmbed.Description = "Players do not need to worry about rolling or transferring money,\n" +
                                          "all transactions and rolls are handled by the bot";
                resultEmbed.AddField($"Congratulations to {winner.DisplayName}!", $"{loser.DisplayName} paid {winner.DisplayName} ${jackpot:N}.");

                await _userService.GiveMoney(winner.Id.ToString(), jackpot);

                await _userService.TakeMoney(loser.Id.ToString(), jackpot);

                await ctx.Channel.SendMessageAsync(embed : resultEmbed).ConfigureAwait(false);
            }
            else
            {
                await WrongChannelAlert(ctx).ConfigureAwait(false);
            }
        }