Example #1
0
        System.Timers.Timer timer1 = new System.Timers.Timer(300000);//定义计时器,单位毫秒

        public void ProcessGroupMessage(PrivateMessageFromGroupReceivedContext context)
        {
            _mahuaApi.SendPrivateMessage(context.FromQq)
            .Text("输入解除口球来随机解除口球,解除概率为")
            .Text((100 - Common1.RandMin).ToString())
            .Text("%")
            .Done();

            if (Common1.i <= Common1.p)
            {
                if (context.Message == "解除口球")
                {
                    if (context.FromQq == Common1.a)
                    {
                        Common1.i++;
                    }
                    Common1.a = context.FromQq;
                    Random ran     = new Random();
                    int    RandKey = ran.Next(0, 100);
                    if (RandKey >= Common1.RandMin)
                    {
                        _mahuaApi.RemoveBanGroupMember("675236681", context.FromQq);
                        _mahuaApi.SendPrivateMessage(context.FromQq)
                        .Text("解除成功")
                        .Done();
                    }
                }
            }
            else
            {
                _mahuaApi.SendPrivateMessage(context.FromQq)
                .Text("本时段解禁尝试次数已达上限,请等待计数器自动回复后再试(每5分钟自动回复1点)")
                .Done();
            }
            timer1.Enabled   = true;
            timer1.Elapsed  += new System.Timers.ElapsedEventHandler(zero);
            timer1.AutoReset = true;
        }
Example #2
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;
                    }
                }
            }
        }