Exemplo n.º 1
0
        public async Task Next()
        {
            if (_permissionHandler.HasBingoManagementPermissions(Context) == false)
            {
                return;
            }

            var message = Context.Message;

            var next = _bingoService.NextItem();

            if (next.Result)
            {
                var reply = "And the next one is " + next.Info;
                if (_bingoService.Verbose)
                {
                    await ReplyAsync(reply);
                }
                else
                {
                    await Context.User.SendMessageAsync(reply);
                }
            }
            else
            {
                await Context.User.SendMessageAsync("Can't call a new item: " + next.Info);
            }

            await message.DeleteAsync();
        }
        public async Task Start()
        {
            if (_permissionHandler.HasBingoManagementPermissions(Context) == false)
            {
                return;
            }

            var message = Context.Message;

            var result = _bingoService.Start();

            if (result.Result)
            {
                await ReplyAsync("Bingo game started by " + Context.User.Mention);

                var joinCommand = _commandService.Commands.First(c => c.Name == "join");
                await ReplyAsync("You can join the game by typing " + _configuration["DiscordBotPrefix"] + joinCommand.Name);
            }
            else
            {
                await Context.User.SendMessageAsync("Can't start a bingo game: " + result.Info);
            }

            await message.DeleteAsync();
        }
        private async Task ExecuteNewRound(bool verbose = true)
        {
            if (_permissionHandler.HasBingoManagementPermissions(Context) == false)
            {
                return;
            }

            var message = Context.Message;

            var result = _bingoService.StartRound(verbose);

            if (result.Result)
            {
                await ReplyAsync("A new round is starting with " + result.Info.NumberOfWinConditions + " win conditions");
                await ReplyAsync("Handing out new cards");

                foreach (var player in _bingoService.Players)
                {
                    var playerSocket = Context.Guild.Users.FirstOrDefault(u => u.Mention == player.Name);
                    if (playerSocket == null)
                    {
                        await _logger.Warn("Player " + player.Name + " no longer exists");

                        continue;
                    }

                    var stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("Your new card: " + player.Grid.GridId + "\n");

                    stringBuilder.AppendLine("```=".PadRight(150, '=') + "\n");
                    for (var index = 0; index < player.Grid.Rows.Length; index++)
                    {
                        //stringBuilder.AppendLine(string.Join(" | ", player.Grid.Rows[index].Items.Select(w => w.PadRight(25))));
                        const int pad = -20;

                        stringBuilder.AppendLine(
                            $"{player.Grid.Rows[index].Items[0],pad}\t\t\t{player.Grid.Rows[index].Items[1],pad}\t\t\t{player.Grid.Rows[index].Items[2],pad}\t\t\t{player.Grid.Rows[index].Items[3],pad}\t\t\t{player.Grid.Rows[index].Items[4],pad}\n");
                    }
                    stringBuilder.AppendLine("=".PadRight(150, '=') + "```\n");

                    await playerSocket.SendMessageAsync(stringBuilder.ToString());
                }

                await ReplyAsync("A new round has been started");
                await ReplyAsync("The first win condition is: " + result.Info.FirstWinCondition);
            }
            else
            {
                await Context.User.SendMessageAsync("Can't start a new round: " + result.Info);
            }

            await message.DeleteAsync();
        }
Exemplo n.º 4
0
        public async Task Stop()
        {
            if (_permissionHandler.HasBingoManagementPermissions(Context) == false)
            {
                return;
            }

            var message = Context.Message;

            var result = _bingoService.Stop();

            if (result.Result)
            {
                await ReplyAsync("Bingo game stopped by " + Context.User.Mention);
            }
            else
            {
                await Context.User.SendMessageAsync("Can't stop the bingo game: " + result.Info);
            }

            await message.DeleteAsync();
        }
        private async Task ExecuteNewRound(bool verbose = true)
        {
            const char gridSeperator = '*';

            if (_permissionHandler.HasBingoManagementPermissions(Context) == false)
            {
                return;
            }

            var message = Context.Message;

            var result = _bingoService.StartRound(verbose);

            if (result.Result)
            {
                await ReplyAsync("A new round is starting with " + result.Info.NumberOfWinConditions + " win conditions");
                await ReplyAsync("Handing out new cards");

                foreach (var player in _bingoService.Players)
                {
                    var playerSocket = Context.Guild.Users.FirstOrDefault(u => u.Mention == player.Name);
                    if (playerSocket == null)
                    {
                        await _logger.Warn("Player " + player.Name + " no longer exists");

                        continue;
                    }

                    var stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("Your new card: " + player.Grid.GridId);
                    stringBuilder.AppendLine();

                    var longestWordLength = player.Grid.Rows.SelectMany(r => r.Items).Max(i => i.Length);
                    var cellWidth         = longestWordLength + 2;
                    var gridWith          = cellWidth * player.Grid.Rows.Length + player.Grid.Rows.Length;
                    stringBuilder.AppendLine("```" + "".PadRight(gridWith + 1, gridSeperator));
                    for (var index = 0; index < player.Grid.Rows.Length; index++)
                    {
                        //stringBuilder.AppendLine(string.Join(" | ", player.Grid.Rows[index].Items.Select(w => w.PadRight(25))));
                        stringBuilder.Append(gridSeperator);
                        foreach (var item in player.Grid.Rows[index].Items)
                        {
                            var leftPad = (cellWidth - item.Length) / 2;
                            stringBuilder.Append("".PadRight(leftPad, ' ') + item +
                                                 "".PadRight(cellWidth - item.Length - leftPad, ' ') + gridSeperator);
                        }
                        stringBuilder.AppendLine();
                        stringBuilder.AppendLine("".PadRight(gridWith + 1, gridSeperator));
                    }
                    stringBuilder.Append("```");

                    await playerSocket.SendMessageAsync(stringBuilder.ToString());
                }

                await ReplyAsync("A new round has been started");
                await ReplyAsync("The first win condition is: " + result.Info.FirstWinCondition);
            }
            else
            {
                await Context.User.SendMessageAsync("Can't start a new round: " + result.Info);
            }

            await message.DeleteAsync();
        }