public User CreateNewUser(string SlackID, string Player, string RealName, string Location, string Email) { var client = new MaevenClient <AccountsAdd>(_secrets.PokerURL(), _secrets.Password()); Dictionary <string, string> dict = new Dictionary <string, string>(); dict.Add("Command", "AccountsAdd"); dict.Add("Player", Player); dict.Add("RealName", RealName); dict.Add("PW", "password"); dict.Add("Location", Location); dict.Add("Email", Email); var response = client.Post(dict); User u = new User(); u.EmailAddress = Email; u.RealName = RealName; u.SlackID = SlackID; u.UserName = Player; _pokerContext.User.Add(u); _pokerContext.SaveChanges(); return(u); }
public async Task GetGraphics(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { if (!Directory.Exists(_secrets.AvatarDir())) { Directory.CreateDirectory(_secrets.AvatarDir()); } var users = _pokerDB.User.OrderBy(u => u.ID).ToList(); var size = new MagickGeometry(32, 32); size.IgnoreAspectRatio = true; //did something change? int counter = 0; foreach (var user in users) { counter++; string uid = user.SlackID; string uri = "https://slack.com/api/users.profile.get?token=" + _secrets.UserToken() + "&user="******".png")) { MagickImage i = new MagickImage(await client.GetStreamAsync(u.Profile.Image48)); i.Resize(size); if (File.Exists(_secrets.AvatarDir() + user.SlackID + ".png")) { File.Delete(_secrets.AvatarDir() + user.SlackID + ".png"); } Console.WriteLine(_secrets.AvatarDir() + user.SlackID + ".png"); i.Write(_secrets.AvatarDir() + user.SlackID + ".png"); user.AvatarHash = u.Profile.AvatarHash; } if (!u.Profile.DisplayName.Equals(user.SlackUserName)) { user.SlackUserName = u.Profile.DisplayName; } user.AvatarIndex = counter; } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); } _pokerRepo.SetAvatarPath(user.UserName, _secrets.AvatarDir() + user.SlackID + ".png"); await Task.Delay(20000, cancellationToken); } _pokerDB.SaveChanges(); } await Task.Delay(9000000, cancellationToken); //very long time }
public IActionResult RequestPayment(IFormCollection Form) { string userID = Form["user_id"]; User u = _pokerContext.User.Where(u => u.SlackID.Equals(userID)).FirstOrDefault(); if (!u.RealName.Equals("Fred")) { throw new Exception("You aren't Fred."); } //payment. string text = Form["Text"]; string[] parameters = text.Split(' '); string payeeID = ""; string payeeName = ""; string payerID = ""; string payerName = ""; string chips = ""; int chipint; for (int i = 0; i < parameters.Length; i++) { if (i == 0) { try { payerID = parameters[i].Trim('<').Trim('>').Trim('@').Split('|')[0]; payerName = parameters[i].Trim('<').Trim('>').Trim('@').Split('|')[1]; } catch { _slackClient.PostAPIMessage("Unable to determine the payer.", null, userID); return(new EmptyResult()); } } if (i == 1) { try { payeeID = parameters[i].Trim('<').Trim('>').Trim('@').Split('|')[0]; payeeName = parameters[i].Trim('<').Trim('>').Trim('@').Split('|')[1]; } catch { _slackClient.PostAPIMessage("Unable to determine the payee.", null, userID); return(new EmptyResult()); } } if (i == 2) { chips = parameters[i]; } } if (String.IsNullOrEmpty(payeeID) || String.IsNullOrEmpty(payerID)) { throw new Exception("Payee or Payer missing."); } if (String.IsNullOrEmpty(chips)) { chipint = 10000; } else { try { chipint = Int32.Parse(chips); } catch { throw new Exception("Unable to determine the chip amount."); } } User Payer = _pokerContext.User.Where(u => u.SlackID.Equals(payerID)).FirstOrDefault(); User Payee = _pokerContext.User.Where(u => u.SlackID.Equals(payeeID)).FirstOrDefault(); string prevBalance = _pokerContext.UserBalance.Where(b => b.UserID == Payer.ID).Select(b => b.Balance).FirstOrDefault(); Payment payment = new Payment(); payment.Chips = chipint; payment.DateRequested = DateTime.Now; payment.Payee = Payee; payment.Payer = Payer; _pokerContext.Payment.Add(payment); _pokerContext.SaveChanges(); string curBalance = _pokerContext.UserBalance.Where(b => b.UserID == Payer.ID).Select(b => b.Balance).FirstOrDefault(); string chipsMoney = "$" + string.Format("{0:#.00}", Convert.ToDecimal(chipint) / 100); //slack to payer string payerMsg = $"Please pay <@{Payee.SlackID}> {chipsMoney}. When the payment is sent do: ```/paid <@{Payee.SlackID}> [method of payment]```"; _slackClient.PostAPIMessage(payerMsg, null, payerID); payerMsg = "Previous balance: " + prevBalance + ". Current Balance: " + curBalance; _slackClient.PostAPIMessage(payerMsg, null, payerID); //slack to payee string payeeMsg = $"<@{Payer.SlackID}> has been requested to pay you {chipsMoney}. You will be notified when the payment is sent."; _slackClient.PostAPIMessage(payeeMsg, null, payeeID); return(new EmptyResult()); }