public static PointsReceived getPointsReceived(string field, string criteria) { PointsReceived userInformation = null; var doc = findBsonDocumentByFieldCriteria(field, criteria); if (doc == null) { createNewDatePointsReceived(criteria); doc = findBsonDocumentByFieldCriteria(field, criteria); } if (doc != null) { string jsonText = "{" + doc.ToJson().Substring(doc.ToJson().IndexOf(',') + 1); userInformation = JsonConvert.DeserializeObject <PointsReceived>(jsonText); } else { Logger.Log(new LogMessage(LogSeverity.Error, $"{typeof(SupportingMethods).Name}.getUserInformation", "Could not find user!")); } return(userInformation); }
public async Task dailyPoints() { SupportingMethods.SetupMongoCollection("pointsReceived"); string currentDate = DateTime.Now.ToString("yyyyMMdd"); PointsReceived pointsReceived = SupportingMethods.getPointsReceived("date", currentDate); var user = Context.Message.Author; List <string> users = pointsReceived.Users.ToList(); if (users.Contains(user.ToString())) { SupportingMethods.SetupMongoCollection("userData"); await ReplyAsync($"{user} has already reclaimed the daily points."); } else { SupportingMethods.updateArray("date", currentDate, "users", user.ToString()); SupportingMethods.SetupMongoCollection("userData"); Random rand = new Random(); var points = rand.Next(100, 250); SupportingMethods.updateDocument(user.ToString(), "points", points); await ReplyAsync($"{user} earned {points} points!"); } }