Beispiel #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            [Queue("fleeteventranks"), StorageAccount("sttfleetg5618_STORAGE")] ICollector <string> msg,
            ExecutionContext context,
            ILogger log)
        {
            log.LogInformation("Fleet event ranks started");
            var configuration = new Configuration(context.FunctionAppDirectory);
            var gameApi       = new GameApi(configuration.STTApiConfiguration);
            await gameApi.Login();

            var data = await gameApi.GetFleetMemberInfo();

            var userdailies = UserDailies.Load(data);
            var squadranks  = SquadEventRank.Load(data);

            log.LogInformation("Fleet event ranks users: " + userdailies.Count);

            var queueItem = new EventRankQueueItem()
            {
                UserDailies = userdailies, SquadEventRanks = squadranks
            };

            msg.Add(JsonConvert.SerializeObject(queueItem));

            return(new OkResult());
        }
Beispiel #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ExecutionContext context,
            ILogger log)
        {
            log.LogInformation("Fleet dailies started");
            var configuration = new Configuration(context.FunctionAppDirectory);
            var gameApi       = new GameApi(configuration.STTApiConfiguration);
            await gameApi.Login();

            var data = await gameApi.GetFleetMemberInfo();

            var fleet = UserDailies.Load(data);

            log.LogInformation("Fleet dailies users: " + fleet.Count);
            StringBuilder message = new StringBuilder();

            message.AppendLine($"Dailies (UTC) {DateTime.UtcNow.ToString("dd.MM.yyyy HH:mm")}");
            var grouped = fleet.GroupBy(d => d.Squadron);

            foreach (var group in grouped)
            {
                var squadName = Regex.Replace(group?.Key ?? string.Empty, @"\<\#[^<>]*\>", string.Empty);
                message.AppendLine($"__{squadName}__");
                foreach (var member in group)
                {
                    message.AppendLine($"{member.Name}: **{member.Dailies}**");
                }
                message.AppendLine(string.Empty);
            }

            HttpClient client = new HttpClient();
            var        d1     = JsonConvert.SerializeObject(new { content = message.ToString() });
            var        result = await client.PostAsync(configuration.DiscordConfiguration.DiscordDailiesWebhookUrl, new StringContent(d1, Encoding.UTF8, "application/json"));

            result.EnsureSuccessStatusCode();

            return(new OkResult());
        }