コード例 #1
0
 public BanTracking(DiscordGuilds g, BanDataStructure savedDS)
 {
     _guilds       = g;
     statsdb       = new StatsDB();
     BanTreeAccess = new SemaphoreSlim(1, 1);
     bds           = savedDS;
     Console.WriteLine($"Loaded {bds.BanDict.Count} ban dict elements from the last backup");
 }
コード例 #2
0
 public BanTracking(DiscordGuilds g)
 {
     Console.WriteLine("Creating bantracking without any previous data.");
     _guilds       = g;
     statsdb       = new StatsDB();
     BanTreeAccess = new SemaphoreSlim(1, 1);
     bds           = new BanDataStructure();
 }
コード例 #3
0
        public async void UpdateStructure(object _)
        {
            // Requests and releases the lock for us.
            List <Tuple <ulong, string> > newlyBannedReports = new List <Tuple <ulong, string> >();
            BanDataStructure localBds = DuplicateData();

            foreach ((string uplayId, BanData data) in localBds.BanDict)
            {
                if (!data.Banned)
                {
                    (bool newban, int newreason) = QueryBanTracker(uplayId);
                    if (newban)
                    {
                        await BanTreeAccess.WaitAsync();

                        // This is almost always not necessary, but it can happen that a user is deleted from the database
                        // between the duplication and this update step.
                        if (bds.BanDict.ContainsKey(uplayId))
                        {
                            bds.BanDict[uplayId].Banned  = true;
                            bds.BanDict[uplayId].BanType = newreason;

                            // Create a ban report.
                            newlyBannedReports.Add(new Tuple <ulong, string>(bds.BanDict[uplayId].GuildWhereAsked, BuildBanReport(bds.BanDict[uplayId])));
                        }
                        BanTreeAccess.Release();
                    }
                }
            }

            if (newlyBannedReports.Count >= 1)
            {
                foreach ((ulong guildID, string report) in newlyBannedReports)
                {
                    // A transitional correction.
                    if (guildID == 0)
                    {
                        _guilds.byID[Settings.ControlGuild].AddReport(report);
                    }
                    else
                    {
                        if (!_guilds.byID.ContainsKey(guildID))
                        {
                            throw new GuildListException($"The guild with ID {guildID} is not currently being serviced.");
                        }
                        _guilds.byID[guildID].AddReport(report);
                    }
                }
            }

            // Post the reports.
            foreach (DiscordGuild dg in _guilds.byID.Values)
            {
                await dg.PublishReports();
            }
            Console.WriteLine($"Performed {NumberOfQueries} queries from the last update structure task to the present.");
            NumberOfQueries = 0;
        }
コード例 #4
0
        public BanDataStructure DuplicateData()
        {
            BanTreeAccess.Wait();
            BanDataStructure ret = new BanDataStructure();

            ret.BanDict         = new Dictionary <string, BanData>(bds.BanDict);
            ret.OrigNickToUplay = new Dictionary <string, string>(bds.OrigNickToUplay);
            BanTreeAccess.Release();
            return(ret);
        }