private void ProcessJsonDocument(PrivateMessageEventArgs e)
        {
            ResetConversation(e.Message.From);
            var doc = e.Message.Document;

            Client.SendMessageToChat(e.Message.From.ID, $"JSON: {MessageUtils.HtmlEscape(doc.Filename)} / {doc.FileSize} byte(s) / mime type {doc.MimeType}!", "HTML", true, null, e.Message.MessageID);

            try
            {
                File   file     = Client.GetFile(doc.FileID);
                var    client   = new WebClient();
                string jsonText = client.DownloadString($"{Client.FileBaseURL}/{file.FilePath}");

                JSONRequest request = Newtonsoft.Json.JsonConvert.DeserializeObject <JSONRequest>(jsonText);

                var user = e.Message.From;
                GetOrCreateRaidDescriptionForUser(user, out DbSet <RaidDescription> collection, out RaidDescription record);
                if (!String.IsNullOrWhiteSpace(request.Gym))
                {
                    record.Gym = request.Gym;
                }
                if (!String.IsNullOrWhiteSpace(request.RaidBoss))
                {
                    record.Raid = request.RaidBoss;
                }
                record.Alignment      = request.GymAlignment;
                record.RaidEndTime    = request.RaidEndTime.UtcDateTime;
                record.RaidUnlockTime = record.RaidEndTime - TimeSpan.FromMinutes(RaidDurationInMinutes);
                if (request.Latitude != 0 && !double.IsNaN(request.Latitude))
                {
                    record.Location = new Location {
                        Latitude = (float)request.Latitude, Longitude = (float)request.Longitude
                    };
                    collection.Update(record);
                    UpdateAddress(user, record.Location);
                }
                else
                {
                    collection.Update(record);
                }

                ShowMenu(e.Message.From);
            }
            catch (Exception ex)
            {
                var msg = ExceptionUtils.AsString(ex);
                Client.SendMessageToChat(e.Message.From.ID, $"<pre>{MessageUtils.HtmlEscape(msg)}</pre>", "HTML");
            }
        }
예제 #2
0
        private void GymInfo(Message message, string[] args)
        {
            string argstr = args.Length == 1 ? args[0] : "";

            Regex re = null;

            if (string.IsNullOrWhiteSpace(argstr))
            {
                Client.SendMessageToChat(message.Chat.ID, _HTML_(I18N.GetString($"Use '/gyminfo \"<regex>\"' to obtain statistics about all raids on matching gyms.")), "HTML", true, false, message.MessageID);
                return;
            }

            int sent = 0;

            try
            {
                var sb = new StringBuilder();
                sb.AppendLine(I18N.GetString($"Statistics for \"{0}\"", argstr));
                re = new Regex(argstr, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
                var raids = DB.GetCollection <Entities.RaidParticipation>().Find(x => re.IsMatch(x.Raid.Gym)).OrderBy(x => x.Raid.RaidEndTime);
                foreach (var raid in raids)
                {
                    int    total = raid.NumberOfParticipants();
                    string line  = $"\"{total}\",\"{TimeService.AsLocalShortTime(raid.Raid.RaidEndTime)}\",\"{MessageUtils.HtmlEscape(raid.Raid.Gym)}\"";
                    if (sb.ToString().Length + line.Length > 4094)
                    {
                        Client.SendMessageToChat(message.Chat.ID, sb.ToString(), "HTML", true, false, message.MessageID);
                        sb.Clear();
                        sent++;
                    }
                    if (sent >= 10) // er zijn grenzen
                    {
                        Client.SendMessageToChat(message.Chat.ID, I18N.GetString("Too many results."), "HTML", true, false, message.MessageID);
                        return;
                    }
                    sb.AppendLine(line);
                }
                Client.SendMessageToChat(message.Chat.ID, sb.ToString(), "HTML", true, false, message.MessageID);
            }
            catch (Exception ex)
            {
                string msg = I18N.GetString("An error occurred processing statistics for \"{0}\" (is that even a regular expression?): {1}", _HTML_(argstr), _HTML_(ExceptionUtils.AsString(ex)));
                Client.SendMessageToChat(message.Chat.ID, msg, "HTML", true, false, message.MessageID);
            }
        }