Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Discord.WebSocket;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace KinkBot.Core.UserAccounts
- {
- public static class UserAccounts
- {
- private static List<UserAccount> accounts;
- private static string accountsFile = "Resources/accounts.json";
- static UserAccounts()
- {
- if (DataStorage.SaveExists(accountsFile))
- {
- accounts = DataStorage.LoadUserAccounts(accountsFile).ToList();
- }
- else
- {
- accounts = new List<UserAccount>();
- SaveAccounts();
- }
- }
- public static void SaveAccounts()
- {
- DataStorage.SaveUserAccounts(accounts, accountsFile);
- }
- public static UserAccount GetAccount(SocketUser user)
- {
- return GetOrCreateAccount(user.Id);
- }
- private static UserAccount GetOrCreateAccount(ulong id)
- {
- var result = from a in accounts
- where a.ID == id
- select a;
- var account = result.FirstOrDefault();
- if (account == null) account = CreateUserAccount(id);
- return account;
- }
- private static UserAccount CreateUserAccount(ulong id)
- {
- var newAccount = new UserAccount()
- {
- ID = id,
- requestedinsta = null,
- instacode = null,
- verifiedinsta = null,
- money = 0,
- bankedmoney = 0,
- totalmoney = 0,
- leaderboardposition = 0
- };
- accounts.Add(newAccount);
- SaveAccounts();
- return newAccount;
- }
- }
- }
Add Comment
Please, Sign In to add comment