예제 #1
0
        public GuildUserData GetOrCreateUserData(ulong userId)
        {
            if (Users.ContainsKey(userId))
            {
                return(Users[userId]);
            }
            GuildUserData output = new GuildUserData(userId, Id, true);

            Users.Add(userId, output);
            FlushData();
            return(output);
        }
예제 #2
0
 public static void Load()
 {
     Guilds    = new Dictionary <ulong, GuildData>();
     RootNodes = new List <KONNode>();
     if (Program.isBeta)
     {
         return;
     }
     DatabaseNode = KONParser.Default.Parse(SensitiveInformation.DecryptDataFile(File.ReadAllText($@"{Utils.localDataPath}/Database.cb")));
     RootNodes.Add(DatabaseNode);
     foreach (KONArray array in DatabaseNode.Arrays)
     {
         if (array.Name == "GUILDS")
         {
             foreach (ulong item in array.Items)
             {
                 KONNode guildNode = KONParser.Default.Parse(SensitiveInformation.DecryptDataFile(File.ReadAllText($@"{Utils.localDataPath}/Guild_{item}/Index.cb")));
                 RootNodes.Add(guildNode);
                 GuildData guild = new GuildData(item);
                 guild.GuildPrefix = (string)guildNode.Values["prefix"];
                 guild.GuildPrefix = guild.GuildPrefix.Replace(@"\", "");
                 foreach (KONArray array1 in guildNode.Arrays)
                 {
                     if (array1.Name == "USERS")
                     {
                         foreach (ulong item1 in array1.Items)
                         {
                             bool ok = Utils.TryLoadDatabaseNode($@"{Utils.localDataPath}/Guild_{item}/User_{item1}.cb", out KONNode userNode);
                             if (!ok)
                             {
                                 continue;
                             }
                             RootNodes.Add(userNode);
                             GuildUserData user = new GuildUserData(item1, guild.Id);
                             user.IsAFK = (bool)userNode.Values["isAFK"];
                             if (user.IsAFK)
                             {
                                 user.AFKMessage = (string)userNode.Values["AFKMessage"];
                                 user.AFKTime    = DateTimeOffset.FromUnixTimeMilliseconds((long)userNode.Values["AFKTime"]);
                             }
                             foreach (KONNode node in userNode.Children)
                             {
                                 if (node.Name == "WARNING")
                                 {
                                     if (node.Values.ContainsKey("message"))
                                     {
                                         user.Warnings.Add(new Tuple <string, DateTimeOffset, ulong>((string)node.Values["message"],
                                                                                                     DateTimeOffset.FromUnixTimeMilliseconds((long)node.Values["time"]),
                                                                                                     (ulong)node.Values["warnedBy"]));
                                     }
                                     else
                                     {
                                         user.Warnings.Add(new Tuple <string, DateTimeOffset, ulong>("No reason given.",
                                                                                                     DateTimeOffset.FromUnixTimeMilliseconds((long)node.Values["time"]),
                                                                                                     (ulong)node.Values["warnedBy"]));
                                     }
                                 }
                             }
                             guild.Users.Add(user.Id, user);
                             if (userNode.Name == "USER")
                             {
                                 user.FlushData();
                             }
                         }
                     }
                     if (array1.Name == "JOIN_ROLES")
                     {
                         foreach (ulong item1 in array1.Items)
                         {
                             guild.AddJoinRole(item1);
                         }
                     }
                 }
                 Guilds.Add(guild.Id, guild);
                 if (guildNode.Name == "GUILD")
                 {
                     guild.FlushData();
                 }
             }
         }
     }
 }