예제 #1
0
        public void AddAutoMessageToGroupMangerConfig(string groupQQ, string message)
        {
            mangerConfig = GraceGroupMangerConfig.Instance;
            int index = QQinMangerConfig(groupQQ, mangerConfig);

            if (index < 0)
            {
                GraceGroupConfig cfg = new GraceGroupConfig();
                cfg.GroupQQ = groupQQ;
                message     = message.Trim();
                string[] strs = Regex.Split(message, "==");
                if (2 == strs.Count())
                {
                    strs[0] = strs[0].Trim();
                    strs[1] = strs[1].Trim();
                    message = strs[0] + "==" + strs[1];
                    cfg.AutoMessage.Add(message);
                    mangerConfig.groupConfigs.Add(cfg);
                    mangerConfig.ToJsonString().SaveToFile(GraceGroupMangerConfig.SavePath);
                    Messenger.SendGroup(groupQQ, "添加成功");
                }
                else
                {
                    mangerConfig.groupConfigs.Add(cfg);
                    mangerConfig.ToJsonString().SaveToFile(GraceGroupMangerConfig.SavePath);
                    Messenger.SendGroup(groupQQ, "指令格式有误,请参照示例:[自定义回复 hello==world]");
                }
            }
            else
            {
                message = message.Trim();
                string[] strs = Regex.Split(message, "==");
                if (2 == strs.Count())
                {
                    strs[0] = strs[0].Trim();
                    foreach (var str in mangerConfig.groupConfigs[index].AutoMessage)
                    {
                        if (strs[0] == Regex.Split(str, "==")[0])
                        {
                            Messenger.SendGroup(groupQQ, "自定义回复已存在");
                            return;
                        }
                    }
                    strs[1] = strs[1].Trim();
                    message = strs[0] + "==" + strs[1];
                    mangerConfig.groupConfigs[index].AutoMessage.Add(message);
                    mangerConfig.ToJsonString().SaveToFile(GraceGroupMangerConfig.SavePath);
                    Messenger.SendGroup(groupQQ, "添加成功");
                }
                else
                {
                    Messenger.SendGroup(groupQQ, "指令格式有误,请参照示例:[自定义回复 hello==world]");
                }
            }
        }
예제 #2
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}] ,权限不足,抽个鸡儿");
            }
        }
예제 #3
0
        private void SetOperationToGroupMangerConfig(string groupQQ, bool status, OperationConfig enumCfg)
        {
            mangerConfig = GraceGroupMangerConfig.Instance;
            int index = QQinMangerConfig(groupQQ, mangerConfig);

            if (index < 0)
            {
                GraceGroupConfig cfg = new GraceGroupConfig();
                cfg.GroupQQ = groupQQ;
                switch (enumCfg)
                {
                case OperationConfig.Alert:
                    cfg.Alert = status; break;

                case OperationConfig.IsBanPostLotto:
                    cfg.IsBanPostLotto = status; break;

                case OperationConfig.JoinRequestMember:
                    cfg.JoinRequestMember = status; break;

                default:
                    return;
                }
                mangerConfig.groupConfigs.Add(cfg);
            }
            else
            {
                switch (enumCfg)
                {
                case OperationConfig.Alert:
                    mangerConfig.groupConfigs[index].Alert = status; break;

                case OperationConfig.IsBanPostLotto:
                    mangerConfig.groupConfigs[index].IsBanPostLotto = status; break;

                case OperationConfig.JoinRequestMember:
                    mangerConfig.groupConfigs[index].JoinRequestMember = status; break;

                default:
                    return;
                }
            }
            mangerConfig.ToJsonString().SaveToFile(GraceGroupMangerConfig.SavePath);
            return;
        }