Esempio n. 1
0
        public void ProcessGroupMessage(GroupMessageReceivedContext context)
        {
            //throw new NotImplementedException();

            //复读计数器计数,连续两个消息内容相同,计数器+1并将发言的群成员加入复读机成员名单,反之重置计数器和名单
            if (Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.msg == context.Message)
            {
                Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.repeatTime++;
                Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.repeaterList.Add(context.FromQq);
            }
            else
            {
                Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.msg = context.Message;
                Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.repeaterList.Clear();
                Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.repeatTime = 0;
            }

            //复读事件触发,根据执行模式进行禁言操作
            if (Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.repeatTime == Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.repeatExecuate)
            {
                //正常禁言:禁言最后一个发言的复读机
                if (Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.execuateMode == 0)
                {
                    _mahuaApi.BanGroupMember(context.FromGroup, context.FromQq, TimeSpan.FromMinutes(Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.execuateTime));
                }

                //随机禁言:从复读机名单中随机选择一个禁言
                if (Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.execuateMode == 1)
                {
                    Random ran     = new Random();
                    int    RandKey = ran.Next(0, Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.repeaterList.Count() - 1);
                    _mahuaApi.BanGroupMember(context.FromGroup, Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.repeaterList[RandKey], TimeSpan.FromMinutes(Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.execuateTime));
                }

                //强力禁言:禁言在复读机名单中的额所有人
                if (Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.execuateMode == 2)
                {
                    for (int k = 0; k <= Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.repeaterList.Count; k++)
                    {
                        _mahuaApi.BanGroupMember(context.FromGroup, Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.repeaterList[k], TimeSpan.FromMinutes(Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.execuateTime));
                    }
                }

                //重置计数器和复读机名单
                Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.repeatTime = 0;
                Newbe.Mahua.Plugins.RepeaterBreaker.MahuaEvents.Common.repeaterList.Clear();
            }

            // 不要忘记在MahuaModule中注册
        }
Esempio n. 2
0
        /// <summary>
        /// 解禁某人
        /// </summary>
        /// <param name="fromqq"></param>
        /// <param name="banqq"></param>
        /// <param name="group"></param>
        /// <param name="_mahuaApi"></param>
        /// <returns></returns>
        public static string UnbanSomebody(string fromqq, string banqq, string group, IMahuaApi _mahuaApi)
        {
            int    fk  = 0;
            string fks = XmlSolve.xml_get("ban_card", fromqq);

            if (fks != "")
            {
                fk = int.Parse(fks);
            }
            if (fk > 0)
            {
                try
                {
                    TimeSpan span = new TimeSpan(0, 0, 0, 0);
                    _mahuaApi.BanGroupMember(group, banqq, span);
                    fk--;
                    XmlSolve.del("ban_card", fromqq);
                    XmlSolve.insert("ban_card", fromqq, fk.ToString());

                    return(Tools.At(fromqq) + "\r\n[CQ:emoji,id=9989]已将" + banqq + "解除禁言");
                }
                catch
                {
                    return(Tools.At(fromqq) + "\r\n执行失败。");
                }
            }
            else
            {
                return(Tools.At(fromqq) + "\r\n[CQ:emoji,id=128162]你哪儿有禁言卡?");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 禁言某人
        /// </summary>
        /// <param name="fromqq"></param>
        /// <param name="banqq"></param>
        /// <param name="group"></param>
        /// <param name="_mahuaApi"></param>
        /// <returns></returns>
        public static string BanSomebody(string fromqq, string banqq, string group, IMahuaApi _mahuaApi)
        {
            int    fk  = 0;
            string fks = XmlSolve.xml_get("ban_card", fromqq);

            if (fks != "")
            {
                fk = int.Parse(fks);
            }
            if (fk > 0)
            {
                try
                {
                    Random   ran     = new Random(System.DateTime.Now.Millisecond);
                    int      RandKey = ran.Next(0, 60 + Tools.GetXmlNumber("gift", fromqq));
                    TimeSpan span    = new TimeSpan(0, 0, RandKey, 0);
                    _mahuaApi.BanGroupMember(group, banqq, span);
                    fk--;
                    XmlSolve.del("ban_card", fromqq);
                    XmlSolve.insert("ban_card", fromqq, fk.ToString());

                    return(Tools.At(fromqq) + "\r\n[CQ:emoji,id=128683]已将" + banqq + "禁言" + RandKey + "分钟");
                }
                catch
                {
                    return(Tools.At(fromqq) + "\r\n执行失败。");
                }
            }
            else
            {
                return(Tools.At(fromqq) + "\r\n[CQ:emoji,id=128162]你哪儿有禁言卡?");
            }
        }
Esempio n. 4
0
        public void BanPostLotto(IMahuaApi _mahuaApi, string group, string qq)
        {
            mangerConfig = GraceGroupMangerConfig.Instance;
            int ret = QQinMangerConfig(group, mangerConfig);

            if (ret < 0)
            {
                GraceGroupConfig cfg = new GraceGroupConfig();
                cfg.GroupQQ = group;
                mangerConfig.groupConfigs.Add(cfg);
                mangerConfig.ToJsonString().SaveToFile(GraceGroupMangerConfig.SavePath);
            }
            else
            {
                if (!GraceGroupMangerConfig.Instance.groupConfigs[ret].IsBanPostLotto)
                {
                    Messenger.SendGroup(group, "禁言抽奖功能已被禁用,请输入[开启禁言抽奖]来启用此功能(需要管理员或群主权限)");
                    return;
                }
            }
            GroupMemberInfo      botInfo      = GetGroupMemberInfo(_mahuaApi, group, _mahuaApi.GetLoginQq());
            GroupMemberAuthority botAuthority = botInfo.Authority;

            if (GroupMemberAuthority.Unknown == botAuthority || GroupMemberAuthority.Normal == botAuthority)
            {
                Messenger.SendGroup(group, "机器人的权限不足,想要使用禁言抽奖功能,请将机器人设置为管理员!");
                return;
            }

            int    hours = 0, minutes = 0, seconds = 0;
            Random rd = new Random();

            minutes = rd.Next(1, 11);
            TimeSpan time = new TimeSpan(hours, minutes, seconds);

            GroupMemberInfo member = GetGroupMemberInfo(_mahuaApi, group, qq);

            if (member.Authority < botAuthority)
            {
                _mahuaApi.BanGroupMember(group, qq, time);
                string nick = member.InGroupName;
                if (nick == "")
                {
                    nick = qq;
                }

                Messenger.SendGroup(group, $"恭喜 {nick} 抽中{minutes}分钟套餐");
            }
            else
            {
                Messenger.SendGroup(group, $"[CQ:at,qq={qq}] ,权限不足,抽个鸡儿");
            }
        }
        public void ProcessGroupMessage(GroupMessageReceivedContext context)
        {
            //throw new NotImplementedException();

            //复读计数器计数,连续两个消息内容相同,计数器+1并将发言的群成员加入复读机成员名单,反之重置计数器和名单
            if (Common.msg == context.Message)
            {
                Common.repeatTime++;
                Common.repeaterList.Add(context.FromQq);
            }
            else
            {
                Common.msg = context.Message;
                Common.repeaterList.Clear();
                Common.repeatTime = 0;
            }

            //复读事件触发,根据执行模式进行禁言操作
            if (Common.repeatTime == Common.repeatExecuate)
            {
                //正常禁言:禁言最后一个发言的复读机
                if (Common.execuateMode == 0)
                {
                    _mahuaApi.BanGroupMember(context.FromGroup, context.FromQq, TimeSpan.FromMinutes(Common.execuateTime));
                    _mahuaApi.SendGroupMessage(context.FromGroup)
                    .Text("复读机")
                    .At(context.FromQq)
                    .Text("已被当场逮捕")
                    .Done();
                }

                //随机禁言:从复读机名单中随机选择一个禁言
                if (Common.execuateMode == 1)
                {
                    Random ran     = new Random();
                    int    RandKey = ran.Next(0, Common.repeaterList.Count() - 1);
                    _mahuaApi.BanGroupMember(context.FromGroup, Common.repeaterList[RandKey], TimeSpan.FromMinutes(Common.execuateTime));
                    _mahuaApi.SendGroupMessage(context.FromGroup)
                    .Text("复读机")
                    .At(Common.repeaterList[RandKey])
                    .Text("已被当场逮捕")
                    .Done();
                }

                //强力禁言:禁言在复读机名单中的额所有人
                if (Common.execuateMode == 2)
                {
                    for (int k = 0; k <= Common.repeaterList.Count; k++)
                    {
                        _mahuaApi.BanGroupMember(context.FromGroup, Common.repeaterList[k], TimeSpan.FromMinutes(Common.execuateTime));
                    }
                    _mahuaApi.SendGroupMessage(context.FromGroup)
                    .Text("所有复读机均已被逮捕")
                    .Newline()
                    .Text("///Powerful Mode Enabled///强力模式启用中///Powerful Mode Enabled///")
                    .Done();
                }

                //重置计数器和复读机名单
                Common.repeatTime = 0;
                Common.repeaterList.Clear();
            }
            //复读模块
            Random ran1     = new Random();
            double RandKey1 = ran1.Next(0, 100);

            if (RandKey1 <= Common.RandMax)
            {
                _mahuaApi.SendGroupMessage(context.FromGroup)
                .Text(context.Message)
                .Done();
            }
            //全随机模块
            Random ran2     = new Random();
            double RandKey2 = ran2.Next(0, 100);

            if (RandKey2 <= Common.RandMax)
            {
                _mahuaApi.BanGroupMember(context.FromGroup, context.FromQq, TimeSpan.FromMinutes(Common.execuateTime));
                _mahuaApi.SendGroupMessage(context.FromGroup)
                .At(context.FromQq)
                .Text("已被丢入小黑屋并穿上小裙子")
                .Done();
            }
            //口球抽奖模块
            if (Common.msg == "口球抽奖")
            {
                Random ran3     = new Random();
                int    RandKey3 = ran3.Next(0, 43200);
                _mahuaApi.BanGroupMember(context.FromGroup, context.FromQq, TimeSpan.FromMinutes(RandKey3));
                _mahuaApi.SendGroupMessage(context.FromGroup)
                .Text("恭喜")
                .At(context.FromQq)
                .Text("中奖!口球时间为")
                .Text(RandKey3.ToString())
                .Text("分钟")
                .Done();
            }
            //骑空士杀手

            // 不要忘记在MahuaModule中注册
        }
Esempio n. 6
0
        public void ProcessGroupMessage(GroupMessageReceivedContext context)
        {
            var managerQQ = RuntimeConfig.Config.ManagerQq.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var message   = context.Message;
            var fromQQ    = context.FromQq;
            var group     = context.FromGroup;
            var loginQQ   = _mahuaApi.GetLoginQq();

            if (managerQQ.Any(x => x == fromQQ))
            {
                var ats = CQNumberHelper.GetAtQQ(context.Message)?.ToList();
                if (!ats?.Any(x => x == loginQQ) ?? false)
                {
                    return;
                }
                //解除禁言
                if (message.IndexOf("解除禁言") > -1)
                {
                    foreach (var item in ats.Where(x => x != loginQQ))
                    {
                        _mahuaApi.RemoveBanGroupMember(group, item);
                    }
                }
                else
                {
                    var m = banRegex.Match(message);
                    //禁言
                    if (m.Success)
                    {
                        var time = Convert.ToDouble(m.Groups[1].Value);
                        foreach (var item in ats?.Where(x => x != loginQQ))
                        {
                            _mahuaApi.BanGroupMember(context.FromGroup, item, TimeSpan.FromMinutes(time));
                        }
                        return;
                    }
                    //修改复读禁言时间
                    m = repeatBanTimeChangeRegex.Match(message);
                    if (m.Success)
                    {
                        var time = Convert.ToDouble(m.Groups[1].Value);
                        if (time > 0)
                        {
                            RuntimeConfig.Config.RepeatMessageBanDuration = time;
                            RuntimeConfig.Save(AppSetting.ConfigFilePath, RuntimeConfig.Config.ToJosn());
                        }
                        return;
                    }
                    //修改复读禁言概率
                    m = repeatBanProbabilityChangeRegex.Match(message);
                    if (m.Success)
                    {
                        var time = Convert.ToDouble(m.Groups[1].Value);
                        if (time > 0)
                        {
                            RuntimeConfig.Config.RepeatMessageBanProbability = time;
                            RuntimeConfig.Save(AppSetting.ConfigFilePath, RuntimeConfig.Config.ToJosn());
                        }
                        return;
                    }
                }
            }
        }
Esempio n. 7
0
        public void ProcessGroupMessage(GroupMessageReceivedContext context)
        {
            var group   = context.FromGroup;
            var message = context.Message;
            var currentGroupMessageCache = messageCache.GetOrAdd(group, new ConcurrentQueue <string>());
            //当前缓存消息出现的次数
            var currentGroupMessageCacheCount = messageCacheCount.GetOrAdd(group, new ConcurrentDictionary <string, byte>());
            //已复读
            var currentGroupRepeatMessageCache = repeatMessageCache.GetOrAdd(group, new ConcurrentDictionary <string, bool>());

            //已禁言
            //var currentGroupBanMessageCache = banMessageCache.GetOrAdd(group, new ConcurrentDictionary<string, bool>());
            while (currentGroupMessageCache.Count >= MessageCacheCount)
            {
                lock (ClearMessageCacheLock)
                {
                    if (currentGroupMessageCache.Count >= MessageCacheCount &&
                        currentGroupMessageCache.TryDequeue(out string oldMessage))
                    {
                        //确保队列缓存被处理了
                        byte oldCount = 0;
                        while (currentGroupMessageCacheCount.TryGetValue(oldMessage, out oldCount))
                        {
                            if (currentGroupMessageCacheCount.TryUpdate(oldMessage, (byte)(oldCount - 1), oldCount))
                            {
                                break;
                            }
                        }
                        if (oldMessage != message && oldCount <= 1)
                        {
                            currentGroupMessageCacheCount.TryRemove(oldMessage, out _);
                            currentGroupRepeatMessageCache.TryRemove(oldMessage, out _);
                            break;
                        }
                    }
                }
            }


            currentGroupMessageCache.Enqueue(message);
            var messageCount = currentGroupMessageCacheCount.AddOrUpdate(message, 1, (_, count) => (byte)(count + 1));


            //3条起 20%增长, 60%封顶
            var maxProbality = (100 - (messageCount - 2 >= 3 ? 3 : messageCount - 2) * 20);
            var probability  = 0;

            lock (randLock)
            {
                probability = random.Next(1, 101);
            }
            if (messageCount > 2)
            {
                //复读
                if (RuntimeConfig.Config.IsRepeatMessage && probability > maxProbality && !currentGroupRepeatMessageCache.ContainsKey(message))
                {
                    currentGroupRepeatMessageCache.TryAdd(message, true);
                    _mahuaApi.SendGroupMessageExtension(group, message);
                }
                //禁言
                var p = 100 - RuntimeConfig.Config.RepeatMessageBanProbability;
                if (RuntimeConfig.Config.IsBanRepeatMessage && probability > p)
                {
                    _mahuaApi.BanGroupMember(group, context.FromQq, TimeSpan.FromMinutes(RuntimeConfig.Config.RepeatMessageBanDuration));
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 抽奖方法,获取抽奖结果并执行禁言
        /// </summary>
        /// <param name="qq"></param>
        /// <param name="_mahuaApi"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        public static string Lottery(string qq, IMahuaApi _mahuaApi, string group)
        {
            if (CheckCount(qq))
            {
                return(Tools.At(qq) + "[CQ:emoji,id=127539]今日抽奖次数已用完!");
            }
            string result   = "";
            int    need_add = 0;
            Random ran      = new Random(System.DateTime.Now.Millisecond);
            int    RandKey  = ran.Next(1, 22);
            int    RandKey2 = ran.Next(0, 10);

            if (RandKey > 19)
            {
                result += Tools.At(qq) + "\r\n[CQ:emoji,id=127881]恭喜你!什么也没有抽中!";
            }
            else if (RandKey == 1 && RandKey2 != 0)
            {
                if (Tools.GetXmlNumber("gift", qq) < 10)
                {
                    need_add += 10;
                    TimeSpan span = new TimeSpan(0, 10, 0, 0);
                    _mahuaApi.BanGroupMember(group, qq, span);
                    result += Tools.At(qq) + "\r\n[CQ:emoji,id=127882]恭喜你抽中了超豪华禁言套餐,并附赠10张禁言卡!奖励已发放!";
                }
                else
                {
                    result += Tools.At(qq) + "\r\n是超豪华禁言套餐呢。。。这次套餐我请客吧ww";
                }
            }
            else if (RandKey == 1 && RandKey2 == 0)
            {
                if (Tools.GetXmlNumber("gift", qq) < 10)
                {
                    need_add -= 200;
                    TimeSpan span = new TimeSpan(30, 0, 0, 0);
                    _mahuaApi.BanGroupMember(group, qq, span);
                    result += Tools.At(qq) + "\r\n[CQ:emoji,id=127882]恭喜你抽中了顶级豪华月卡禁言套餐,并扣除200张禁言卡!奖励已发放!";
                }
                else
                {
                    result += Tools.At(qq) + "\r\n是顶级豪华月卡禁言套餐呢。。。这次套餐我请客吧ww";
                }
            }
            else if (RandKey < 11 - Tools.GetXmlNumber("gift", qq) / 10)
            {
                TimeSpan span = new TimeSpan(0, RandKey, 0, 0);
                _mahuaApi.BanGroupMember(group, qq, span);
                need_add -= RandKey;
                result   += Tools.At(qq) + "\r\n[CQ:emoji,id=127882]恭喜你抽中了禁言" + RandKey + "小时,并扣除" + RandKey + "张禁言卡!奖励已发放到你的QQ~\r\n送我礼物可以提升好感度降低禁言几率哦~";
            }
            else
            {
                int lucky = ran.Next(1, Tools.GetXmlNumber("gift", qq) / 10 + 1);
                need_add += lucky;
                result   += Tools.At(qq) + "\r\n[CQ:emoji,id=127873]恭喜你抽中了" + need_add + "张禁言卡,回复“禁言卡”可以查看使用帮助。";
            }

            if (need_add != 0)
            {
                Tools.AddXmlNumber("ban_card", qq, need_add);
            }
            return(result);
        }