示例#1
0
        public override async Task Begin(ITurnContext turnContext)
        {
            var state = turnContext.GetConversationState <ImageHuntState>();

            if (state.Status != Status.Started)
            {
                LogInfo <ImageHuntState>(turnContext, "The game had not started!");
                await turnContext.ReplyActivity("La partie n'a pas encore commencée, vous ne pouvez par l'arrêter!");

                await turnContext.End();
            }
            _logger.LogInformation($"The Hunt of GameId={state.GameId} for teamid={state.TeamId} had ended.");
            var gameActionRequest = new GameActionRequest()
            {
                Action    = (int)ImageHuntWebServiceClient.Action.EndGame,
                GameId    = state.GameId,
                TeamId    = state.TeamId,
                Latitude  = state.CurrentLatitude,
                Longitude = state.CurrentLongitude
            };

            state.Status = Status.Ended;
            await _actionWebService.LogAction(gameActionRequest);

            await turnContext.ReplyActivity(
                $"La chasse vient de prendre fin, vos actions ont été enregistrée et un orga va les valider.");

            await turnContext.End();
        }
示例#2
0
        public override async Task Begin(ITurnContext turnContext)
        {
            var state = turnContext.GetConversationState <ImageHuntState>();

            if (state.Status != Status.Initialized)
            {
                LogInfo <ImageHuntState>(turnContext, "Game not initialized");
                await turnContext.ReplyActivity("Le chat n'a pas été initialisé, impossible de commencer maintenant!");

                await turnContext.End();

                return;
            }
            LogInfo <ImageHuntState>(turnContext, "Start Game");

            var gameActionRequest = new GameActionRequest()
            {
                Action    = (int)ImageHuntWebServiceClient.Action.StartGame,
                GameId    = state.GameId,
                TeamId    = state.TeamId,
                Latitude  = state.CurrentLatitude,
                Longitude = state.CurrentLongitude
            };

            state.Status = Status.Started;
            await _actionWebService.LogAction(gameActionRequest);

            await turnContext.ReplyActivity($"La chasse commence maintenant! Bonne chance!");

            await turnContext.End();
        }
示例#3
0
        public override async Task Begin(ITurnContext turnContext)
        {
            var state = turnContext.GetConversationState <ImageHuntState>();

            if (state.Status != Status.Started)
            {
                LogInfo <ImageHuntState>(turnContext, "Game not started");
                await turnContext.End();

                return;
            }
            state.CurrentLatitude  = turnContext.Activity.Location.Latitude;
            state.CurrentLongitude = turnContext.Activity.Location.Longitude;

            _logger.LogInformation($"Received position: [lat:{state.CurrentLatitude}, lng:{state.CurrentLongitude}");
            await base.Begin(turnContext);

            var logPositionRequest = new LogPositionRequest()
            {
                GameId    = state.GameId,
                TeamId    = state.TeamId,
                Latitude  = state.CurrentLatitude,
                Longitude = state.CurrentLongitude
            };
            await _actionWebService.LogPosition(logPositionRequest);

            //await turnContext.ReplyActivity(
            //  $"J'ai enregistré votre nouvelle position {state.CurrentLatitude}, {state.CurrentLongitude}");
            await turnContext.End();
        }
示例#4
0
        public override async Task Begin(ITurnContext turnContext)
        {
            var state = turnContext.GetConversationState <ImageHuntState>();

            if (state.GameId != 0 && state.TeamId != 0)
            {
                var warningMessage = $"Le groupe {turnContext.ChatId} a déjà été initialisé!";
                await turnContext.ReplyActivity(warningMessage);

                LogInfo <ImageHuntState>(turnContext, warningMessage);
                await turnContext.End();

                return;
            }
            var regEx        = new Regex(@"(?i)\/init gameid=(\d*) teamid=(\d*)");
            var activityText = turnContext.Activity.Text;

            if (regEx.IsMatch(activityText))
            {
                var groups = regEx.Matches(activityText);
                state.GameId = Convert.ToInt32(groups[0].Groups[1].Value);
                state.TeamId = Convert.ToInt32(groups[0].Groups[2].Value);
                LogInfo <ImageHuntState>(turnContext, "Init");
                state.Game = await _gameWebService.GetGameById(state.GameId);

                state.Team = await _teamWebService.GetTeamById(state.TeamId);

                if (state.Game == null || state.Team == null)
                {
                    LogInfo <ImageHuntState>(turnContext, "Unable to find game");
                    await turnContext.ReplyActivity($"Impossible de trouver la partie pour l'Id={state.GameId} ou l'équipe pour l'Id={state.TeamId}");

                    state.GameId = state.TeamId = 0;
                    await turnContext.End();

                    return;
                }

                state.Status = Status.Initialized;
            }
            await base.Begin(turnContext);

            await turnContext.ReplyActivity(
                $"Le groupe de l'équipe {state.Team.Name} pour la chasse {state.Game.Name} qui débute le {state.Game.StartDate} est prêt, bon jeu!");

            await turnContext.End();
        }
示例#5
0
        public override async Task Begin(ITurnContext turnContext)
        {
            var activity = new Activity()
            {
            };
            await turnContext.ReplyActivity(activity);

            await turnContext.End();
        }
示例#6
0
        public override async Task Begin(ITurnContext turnContext)
        {
            LogInfo <ImageHuntState>(turnContext, "Reset Game");
            await turnContext.ResetConversationStates <ImageHuntState>();

            await turnContext.ReplyActivity($"Le groupe {turnContext.ChatId} vient d'être ré-initialisé");

            await turnContext.End();
        }
示例#7
0
        public override async Task Begin(ITurnContext turnContext)
        {
            LogInfo <ImageHuntState>(turnContext, "Begin HelpDialog");
            await turnContext.ReplyActivity(@"Pour jouer à la chasse au trésor, vous devez d'abord envoyer votre position. 
Le plus simples est de faire un partage en continu le temps que dure la chasse.
Ensuite, vous pouvez envoyer les images que vous aurez deviné, je les enregistrerai et un validateur vous attribuera les points si elle correspond à une des photo mystère!
Bon jeu!");

            await turnContext.End();
        }
示例#8
0
        public override async Task Begin(ITurnContext turnContext)
        {
            //_logger.LogInformation();
            try
            {
                var regEx  = new Regex(@"\/broadcastLocation\s*(gameid\=(?'gameid'\d*)|teamid\=(?'teamid'\d*))\s*Lat=(?'Lat'[\d,\.]*)\s*Lng=(?'Lng'[\d,\.]*)");
                var states = await turnContext.GetAllConversationState <ImageHuntState>();

                var gameIdAsString       = regEx.Matches(turnContext.Activity.Text)[0].Groups["gameid"].Value;
                var teamIdAsString       = regEx.Matches(turnContext.Activity.Text)[0].Groups["teamid"].Value;
                var latitudeToBroadcast  = regEx.Matches(turnContext.Activity.Text)[0].Groups["Lat"].Value;
                var latitude             = Convert.ToDouble(latitudeToBroadcast, CultureInfo.InvariantCulture);
                var longitudeToBroadcast = regEx.Matches(turnContext.Activity.Text)[0].Groups["Lng"].Value;
                var longitude            = Convert.ToDouble(longitudeToBroadcast, CultureInfo.InvariantCulture);
                IEnumerable <ImageHuntState> statesToBroadcast = null;
                if (!string.IsNullOrEmpty(gameIdAsString))
                {
                    var gameId = Convert.ToInt32(gameIdAsString);
                    statesToBroadcast = states.Where(s => s.GameId == gameId);
                }
                else if (!string.IsNullOrEmpty(teamIdAsString))
                {
                    var teamId = Convert.ToInt32(teamIdAsString);
                    statesToBroadcast = states.Where(s => s.TeamId == teamId);
                }

                foreach (var imageHuntState in statesToBroadcast)
                {
                    var activity = new Activity()
                    {
                        ChatId = imageHuntState.ChatId, Location = new Location()
                        {
                            Latitude = (float)latitude, Longitude = (float)longitude
                        },
                        ActivityType = ActivityType.Message
                    };
                    await turnContext.SendActivity(activity);
                }
            }
            finally
            {
                await turnContext.End();
            }
        }
示例#9
0
        public override async Task Begin(ITurnContext turnContext)
        {
            //_logger.LogInformation();
            try
            {
                var regEx  = new Regex(@"\/broadcast\s*(gameid\=(?'gameid'\d*)|teamid\=(?'teamid'\d*)) (?'text'.*)");
                var states = await turnContext.GetAllConversationState <ImageHuntState>();

                var gameIdAsString  = regEx.Matches(turnContext.Activity.Text)[0].Groups["gameid"].Value;
                var teamIdAsString  = regEx.Matches(turnContext.Activity.Text)[0].Groups["teamid"].Value;
                var textToBroadcast = regEx.Matches(turnContext.Activity.Text)[0].Groups["text"].Value;
                IEnumerable <ImageHuntState> statesToBroadcast = null;
                if (!string.IsNullOrEmpty(gameIdAsString))
                {
                    var gameId = Convert.ToInt32(gameIdAsString);
                    statesToBroadcast = states.Where(s => s.GameId == gameId);
                }
                else if (!string.IsNullOrEmpty(teamIdAsString))
                {
                    var teamId = Convert.ToInt32(teamIdAsString);
                    statesToBroadcast = states.Where(s => s.TeamId == teamId);
                }

                foreach (var imageHuntState in statesToBroadcast)
                {
                    var activity = new Activity()
                    {
                        ChatId = imageHuntState.ChatId, Text = textToBroadcast, ActivityType = ActivityType.Message
                    };
                    await turnContext.SendActivity(activity);
                }
            }
            finally
            {
                await turnContext.End();
            }
        }
示例#10
0
 public override async Task Continue(ITurnContext turnContext)
 {
     await turnContext.End();
 }
示例#11
0
        public override async Task Begin(ITurnContext turnContext)
        {
            var state = turnContext.GetConversationState <ImageHuntState>();

            if (state.Status != Status.Started)
            {
                LogInfo <ImageHuntState>(turnContext, "Attempt to record image before start!");
                await turnContext.ReplyActivity($"Vous ne pouvez m'envoyer de images qu'après le début de la chasse!");

                await turnContext.End();

                return;
            }

            if (state.GameId == 0 ||
                state.TeamId == 0)
            {
                LogInfo <ImageHuntState>(turnContext, "Game not initialized!");

                await turnContext.ReplyActivity(
                    $"La chasse n'a pas été correctement initalisée, veuillez demander de l'assistance à l'orga");

                await turnContext.End();

                return;
            }

            if (turnContext.Activity.Document == null)
            {
                LogInfo <ImageHuntState>(turnContext, "No document received!");

                await turnContext.ReplyActivity(
                    $"Aucun document ne m'est envoyé, veuillez recommencer");

                await turnContext.End();

                return;
            }

            var document = turnContext.Activity.Document;

            if (document.MimeType != "image/jpeg")
            {
                LogInfo <ImageHuntState>(turnContext, "Document is not image");

                await turnContext.ReplyActivity(
                    $"Vous ne m'avez pas envoyé une image, je ne peux accepter d'autres documents");

                await turnContext.End();

                return;
            }
            byte[] imageBytes = null;

            using (var stream = new MemoryStream())
            {
                await _telegramBotClient.GetInfoAndDownloadFileAsync(document.FileId, stream);

                if (stream.Length == 0)
                {
                    LogInfo <ImageHuntState>(turnContext, "Problem while downloading image from Telegram");

                    await turnContext.ReplyActivity(
                        $"Un problème est apparu dans l'image que vous m'avez envoyé.");

                    await turnContext.End();

                    return;
                }
                imageBytes = new byte[stream.Length];
                stream.Read(imageBytes, 0, (int)stream.Length);
                var uploadRequest = new UploadImageRequest()
                {
                    GameId    = state.GameId,
                    TeamId    = state.TeamId,
                    Latitude  = state.CurrentLatitude,
                    Longitude = state.CurrentLongitude,
                    ImageName = turnContext.Activity.Text
                };
                uploadRequest.FormFile = new FormFile(stream, 0, stream.Length, "formFile", document.FileName);
                await _teamWebService.UploadImage(uploadRequest);
            }

            await base.Begin(turnContext);

            var activity = new Activity()
            {
                ActivityType = ActivityType.Message,
                ChatId       = turnContext.ChatId,
                Text         = "Votre image a bien été téléchargée, un validateur l'examinera pour vous attribuer les points"
            };

            LogInfo <ImageHuntState>(turnContext, "Image uploaded");

            await turnContext.ReplyActivity(activity);

            await turnContext.End();
        }
示例#12
0
        public override async Task Begin(ITurnContext turnContext)
        {
            var state = turnContext.GetConversationState <ImageHuntState>();

            if (state.Status != Status.Started)
            {
                LogInfo <ImageHuntState>(turnContext, "Attempt to record image before start!");
                await turnContext.ReplyActivity($"Vous ne pouvez m'envoyer de images qu'après le début de la chasse!");

                await turnContext.End();

                return;
            }
            if (state.GameId == 0 ||
                state.TeamId == 0 ||
                state.CurrentLatitude == 0.0 ||
                state.CurrentLongitude == 0.0)
            {
                LogInfo <ImageHuntState>(turnContext, "Game not initialized!");
                var errorMessage = $"La chasse n'a pas été correctement initalisée ou je ne sais pas où vous êtes, veuillez demander de l'assistance à l'orga";
                await turnContext.ReplyActivity(errorMessage);

                _logger.LogWarning(errorMessage);
                await turnContext.End();

                return;
            }
            byte[] imageBytes   = null;
            var    photoSizes   = turnContext.Activity.Pictures;
            var    biggestPhoto = photoSizes.OrderByDescending(p => p.FileSize).First();

            using (Stream stream = new MemoryStream())
            {
                var fileInfo = await _telegramBotClient.GetInfoAndDownloadFileAsync(biggestPhoto.FileId, stream);

                imageBytes = new byte[stream.Length];
                stream.Read(imageBytes, 0, (int)stream.Length);


                var uploadRequest = new UploadImageRequest()
                {
                    GameId    = state.GameId,
                    TeamId    = state.TeamId,
                    Latitude  = state.CurrentLatitude,
                    Longitude = state.CurrentLongitude,
                    ImageName = turnContext.Activity.Text
                };
                uploadRequest.FormFile = new FormFile(stream, 0, stream.Length, "formFile", "image.jpg");
                await _teamWebService.UploadImage(uploadRequest);

                _logger.LogInformation($"Image {turnContext.Activity.Pictures.First().FileId} had been uploaded");
            }

            await base.Begin(turnContext);

            var activity = new Activity()
            {
                ActivityType = ActivityType.Message, ChatId = turnContext.ChatId, Text = "Votre image a bien été téléchargée, un validateur l'examinera pour vous attribuer les points"
            };

            LogInfo <ImageHuntState>(turnContext, "Image uploaded");

            await turnContext.ReplyActivity(activity);

            await turnContext.End();
        }