public BotMessage GetResponse(ResponseContext context) { var match = commandPattern.Match(context.Message.Text); using (var db = new DatabaseContext()) { var newBeef = new BeefEntry(); newBeef.ReportedOn = DateTimeOffset.UtcNow; var internalMessageUserId = context.Message.User.ID; var reportedByUserName = context.UserNameCache[internalMessageUserId]; newBeef.ReporterUserId = reportedByUserName; newBeef.ExpiresOn = DetermineExpirationDate(match); newBeef.OffendingChatUserId = match.Groups[4].Value.Parse<int>(); newBeef.Explination = match.Groups[5].Value; db.BeefEntries.Add(newBeef); db.SaveChanges(); } return new BotMessage { Text = "Saved beef entry." }; }
public override BotMessage GetResponse(ResponseContext context) { var offendingUserId = commandPattern.Match(context.Message.Text).Groups[1].Value.Parse<int>(); using (var db = new DatabaseContext()) { var dbEntriesForUser = db.BeefEntries .Where(x => x.OffendingChatUserId == offendingUserId) .Where(x => x.ExpiresOn > DateTimeOffset.UtcNow) //only get ones that are active .OrderBy(x => x.ReportedOn) .ToList(); string outputMessage = ""; if (!dbEntriesForUser.Any()) { outputMessage = "This user has no active beefs."; } else { foreach (var dbEntry in dbEntriesForUser) { outputMessage += $"Closing beef #{dbEntry.Id}.\n"; dbEntry.ExpiresOn = DateTimeOffset.UtcNow; } db.SaveChanges(); } return new BotMessage { Text = outputMessage }; } }
public override BotMessage GetResponse(ResponseContext context) { var beefIds = commandPattern.Match(context.Message.Text) .Groups[1] .Captures .OfType<Capture>() .Select(x => x.Value.Parse<int>()) .ToList(); using (var db = new DatabaseContext()) { var dbEntries = (from dbRecord in db.BeefEntries join beefId in beefIds on dbRecord.Id equals beefId select dbRecord) .OrderBy(x => x.ReportedOn) .ToList(); var outputMessage = ""; if (dbEntries.Count != beefIds.Count) { outputMessage = "*Warning, could not locate all requested entries. Ensure you have typed the Id numbers correctly.*\n\n"; } foreach (var dbEntry in dbEntries) { if (dbEntry.ExpiresOn < DateTimeOffset.UtcNow) { //the beef has already expired outputMessage += $"Beef #{dbEntry.Id} already expired on {dbEntry.ExpiresOn.ToStandardDisplayString()}.\n"; } else { outputMessage += $"Beef #{dbEntry.Id} closed.\n"; dbEntry.ExpiresOn = DateTimeOffset.UtcNow; } } db.SaveChanges(); return new BotMessage { Text = outputMessage }; } }