Exemplo n.º 1
0
        private async Task ExecuteGameInputAsync(IMessagesGame game, IUserMessage message)
        {
            var gameMessage = await game.GetMessage();

            log.Verbose(
                $"Input {message.Content} by {message.Author.FullName()} in {message.Channel.FullName()}",
                game.GameName);

            game.Input(message.Content, message.Author.Id);
            if (game is MultiplayerGame mGame)
            {
                while (mGame.BotTurn)
                {
                    mGame.BotInput();
                }
            }
            if (game.State != GameState.Active)
            {
                games.Remove(game);
            }

            if (gameMessage != null && await message.Channel.BotCanAsync(ChannelPermission.ManageMessages))
            {
                game.CancelRequests();
                try { await gameMessage.ModifyAsync(game.GetMessageUpdate(), game.GetRequestOptions()); }
                catch (OperationCanceledException) { }

                await message.DeleteAsync(PmBot.DefaultOptions);
            }
            else
            {
                game.CancelRequests();
                try
                {
                    var newMsg = await message.Channel.SendMessageAsync(game.GetContent(), false, game.GetEmbed()?.Build(), game.GetRequestOptions());

                    game.MessageId = newMsg.Id;
                }
                catch (OperationCanceledException) { }

                if (gameMessage != null)
                {
                    await gameMessage.DeleteAsync(PmBot.DefaultOptions);
                }
            }
        }
Exemplo n.º 2
0
        private async Task ExecuteGameInputAsync(IMessagesGame game, IUserMessage message)
        {
            var gameMessage = await game.GetMessage();

            await logger.Log(LogSeverity.Verbose, game.Name,
                             $"Input {message.Content} by {message.Author.FullName()} in {message.Channel.FullName()}");

            game.Input(message.Content, message.Author.Id);
            if (game is MultiplayerGame mGame)
            {
                while (mGame.BotTurn)
                {
                    mGame.BotInput();
                }
            }
            if (game.State != State.Active)
            {
                storage.DeleteGame(game);
            }

            game.CancelRequests();
            var requestOptions = game.RequestOptions;

            if (gameMessage != null && message.Channel.BotCan(ChannelPermission.ManageMessages))
            {
                await gameMessage.ModifyAsync(game.UpdateMessage, requestOptions);

                await message.DeleteAsync(Bot.DefaultOptions);
            }
            else
            {
                var newMsg = await message.Channel.SendMessageAsync(game.GetContent(), false, game.GetEmbed()?.Build(), requestOptions);

                game.MessageId = newMsg.Id;
                if (gameMessage != null)
                {
                    await gameMessage.DeleteAsync(Bot.DefaultOptions);
                }
            }
        }