Exemplo n.º 1
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);
        }
        public GroupCfg SetGroupConfig(
            long gid,
            int AdminOnly             = 3,
            int BlackList             = 3,
            int AutoKick              = 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 (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 (Microsoft.EntityFrameworkCore.DbUpdateException)
                {
                    db.GroupConfig.Update(groupCfg);
                    db.SaveChanges();
                }
                return(groupCfg);
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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();
                }
            }
        }
Exemplo 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);
            }
        }
Exemplo 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);
         }
     }
 }