Esempio n. 1
0
        public void ChangeDbUnban(
            int AdminID,
            int UserID,
            string Reason,
            int ChannelMessageID = 0
            )
        {
            Temp.bannedUsers.Remove(UserID);
            BanHistory banHistory = new BanHistory
            {
                UserID           = UserID,
                Ban              = 1,
                Level            = 1,
                ChannelMessageID = ChannelMessageID,
                ReasonMessageID  = 0,
                AdminID          = AdminID,
                BanTime          = GetTime.GetUnixTime(),
                Reason           = Reason,
                Expires          = 0
            };

            using (var db = new BlacklistDatabaseContext())
            {
                db.BanHistorys.Add(banHistory);
                var bannedUser = db.BanUsers
                                 .Single(users => users.UserID == UserID);
                db.Remove(bannedUser);
                db.SaveChanges();
            }

            new UnBanCaller().UnBanCallerThread(UserID);
        }
Esempio n. 2
0
 public void checkdb()
 {
     using (var db = new BlacklistDatabaseContext())
     {
         db.Database.EnsureCreated();
     }
 }
Esempio n. 3
0
        public void ChangeDbBan(
            int AdminID,
            int UserID,
            int Level,
            long Expires,
            string Reason,
            int ChannelMessageID = 0,
            int ReasonMessageID  = 0
            )
        {
            BanUser baninfo = new BanUser
            {
                UserID           = UserID,
                Ban              = 0,
                Level            = Level,
                Reason           = Reason,
                HistoryID        = 0,
                ChannelMessageID = ChannelMessageID,
                ReasonMessageID  = ReasonMessageID,
                Expires          = Expires
            };

            Temp.bannedUsers[UserID] = baninfo;
            BanHistory banHistory = new BanHistory
            {
                UserID           = UserID,
                Ban              = 0,
                Level            = Level,
                ChannelMessageID = ChannelMessageID,
                ReasonMessageID  = ReasonMessageID,
                AdminID          = AdminID,
                BanTime          = GetTime.GetUnixTime(),
                Reason           = Reason,
                Expires          = Expires
            };

            using (var db = new BlacklistDatabaseContext())
            {
                db.BanHistorys.Add(banHistory);
                try
                {
                    db.BanUsers.Add(baninfo);
                    db.SaveChanges();
                }
                catch (SqliteException)
                {
                    db.BanUsers.Update(baninfo);
                    db.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    db.BanUsers.Update(baninfo);
                    db.SaveChanges();
                }
            }

            new SubscribeBanListCaller().CallGroupsInThread(baninfo);
        }
Esempio n. 4
0
        public BanUser GetUserBanStatus(int uid)
        {
            BanUser banuser = null;

            banuser = Temp.bannedUsers.GetValueOrDefault(uid, null);
            if (banuser != null)
            {
                if (GetTime.GetIsExpired(banuser.Expires))
                {
                    banuser.Ban           = 1;
                    Temp.bannedUsers[uid] = banuser;
                }

                return(banuser);
            }

            using (var db = new BlacklistDatabaseContext())
            {
                BanUser bannedUser;
                try
                {
                    bannedUser = db.BanUsers
                                 .Single(users => users.UserID == uid);
                    Temp.bannedUsers.TryAdd(uid, bannedUser);
                }
                catch (InvalidOperationException)
                {
                    bannedUser = new BanUser {
                        Ban = 1
                    };
                    Temp.bannedUsers.TryAdd(uid, bannedUser);
                    return(bannedUser);
                }

                if (GetTime.GetIsExpired(bannedUser.Expires))
                {
                    bannedUser.Ban = 1;
                    db.BanUsers.Update(bannedUser);
                }

                return(bannedUser);
            }
        }
Esempio n. 5
0
        public GroupCfg GetGroupConfig(long gid)
        {
            GroupCfg config = null;

            config = Temp.groupConfig.GetValueOrDefault(gid, null);
            if (config != null)
            {
                return(config);
            }
            using (var db = new BlacklistDatabaseContext())
            {
                GroupCfg groupCfg;
                try
                {
                    groupCfg = db.GroupConfig
                               .Single(groups => groups.GroupID == gid);
                    Temp.groupConfig.TryAdd(gid, groupCfg);
                }
                catch (InvalidOperationException)
                {
                    groupCfg = new GroupCfg
                    {
                        GroupID               = gid,
                        AdminOnly             = 1,
                        BlackList             = 0,
                        AutoKick              = 0,
                        AntiBot               = 1,
                        AntiHalal             = 0,
                        AutoDeleteSpamMessage = 0,
                        AutoDeleteCommand     = 1,
                        SubscribeBanList      = 0
                    };
                    db.GroupConfig.Add(groupCfg);
                    Temp.groupConfig.TryAdd(gid, groupCfg);
                    db.SaveChanges();
                    return(groupCfg);
                }

                return(groupCfg);
            }
        }
Esempio n. 6
0
 public bool RemoveGroupCfg(long GroupID)
 {
     using (var db = new BlacklistDatabaseContext())
     {
         try
         {
             var groupCfg = db.GroupConfig
                            .Single(groups => groups.GroupID == GroupID);
             db.Remove(groupCfg);
             db.SaveChanges();
             return(true);
         }
         catch (InvalidOperationException)
         {
             return(false);
         }
         catch
         {
             return(false);
         }
     }
 }
Esempio n. 7
0
        private void ChangeBanTemp(
            int AdminID,
            int UserID,
            int Level,
            long Expires,
            string Reason)
        {
            BanUser baninfo = new BanUser
            {
                UserID           = UserID,
                Ban              = 0,
                Level            = Level,
                Reason           = Reason,
                HistoryID        = 0,
                ChannelMessageID = 0,
                ReasonMessageID  = 0,
                Expires          = Expires
            };

            using (var db = new BlacklistDatabaseContext())
            {
                try
                {
                    db.BanUsers.Add(baninfo);
                    db.SaveChanges();
                }
                catch (SqliteException)
                {
                    db.BanUsers.Update(baninfo);
                    db.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    db.BanUsers.Update(baninfo);
                    db.SaveChanges();
                }
            }
        }
Esempio n. 8
0
        public GroupCfg SetGroupConfig(
            long gid,
            int AdminOnly             = 3,
            int BlackList             = 3,
            int AutoKick              = 3,
            int AntiBot               = 3,
            int AntiHalal             = 3,
            int AutoDeleteSpamMessage = 3,
            int AutoDeleteCommand     = 3,
            int SubscribeBanList      = 3
            )
        {
            GroupCfg groupCfg = GetGroupConfig(gid);

            if (AdminOnly != 3)
            {
                groupCfg.AdminOnly = AdminOnly;
            }
            if (BlackList != 3)
            {
                groupCfg.BlackList = BlackList;
            }
            if (AutoKick != 3)
            {
                groupCfg.AutoKick = AutoKick;
            }
            if (AntiBot != 3)
            {
                groupCfg.AntiBot = AntiBot;
            }
            if (AntiHalal != 3)
            {
                groupCfg.AntiHalal = AntiHalal;
            }
            if (AutoDeleteSpamMessage != 3)
            {
                groupCfg.AutoDeleteSpamMessage = AutoDeleteSpamMessage;
            }
            if (AutoDeleteCommand != 3)
            {
                groupCfg.AutoDeleteCommand = AutoDeleteCommand;
            }
            if (SubscribeBanList != 3)
            {
                groupCfg.SubscribeBanList = SubscribeBanList;
            }
            Temp.groupConfig[gid] = groupCfg;
            using (var db = new BlacklistDatabaseContext())
            {
                try
                {
                    db.GroupConfig.Add(groupCfg);
                    db.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    db.GroupConfig.Update(groupCfg);
                    db.SaveChanges();
                }

                return(groupCfg);
            }
        }