示例#1
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);
            }
        }
示例#2
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);
            }
        }