Guest User

Untitled

a guest
Jul 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. using Discord.WebSocket;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace KinkBot.Core.UserAccounts
  9. {
  10. public static class UserAccounts
  11. {
  12. private static List<UserAccount> accounts;
  13.  
  14. private static string accountsFile = "Resources/accounts.json";
  15.  
  16. static UserAccounts()
  17. {
  18. if (DataStorage.SaveExists(accountsFile))
  19. {
  20. accounts = DataStorage.LoadUserAccounts(accountsFile).ToList();
  21. }
  22. else
  23. {
  24. accounts = new List<UserAccount>();
  25. SaveAccounts();
  26. }
  27. }
  28.  
  29. public static void SaveAccounts()
  30. {
  31. DataStorage.SaveUserAccounts(accounts, accountsFile);
  32. }
  33.  
  34. public static UserAccount GetAccount(SocketUser user)
  35. {
  36. return GetOrCreateAccount(user.Id);
  37. }
  38.  
  39. private static UserAccount GetOrCreateAccount(ulong id)
  40. {
  41. var result = from a in accounts
  42. where a.ID == id
  43. select a;
  44.  
  45. var account = result.FirstOrDefault();
  46. if (account == null) account = CreateUserAccount(id);
  47. return account;
  48. }
  49.  
  50. private static UserAccount CreateUserAccount(ulong id)
  51. {
  52. var newAccount = new UserAccount()
  53. {
  54. ID = id,
  55. requestedinsta = null,
  56. instacode = null,
  57. verifiedinsta = null,
  58. money = 0,
  59. bankedmoney = 0,
  60. totalmoney = 0,
  61. leaderboardposition = 0
  62. };
  63.  
  64. accounts.Add(newAccount);
  65. SaveAccounts();
  66. return newAccount;
  67. }
  68. }
  69. }
Add Comment
Please, Sign In to add comment