Пример #1
0
        /// <summary>
        /// 列出所有成员
        /// </summary>
        private async void ListMember()
        {
            //检查公会是否存在
            if (DBHelper.GuildExists() != 1)
            {
                await SourceGroup.SendGroupMessage("该群未创建公会");

                return;
            }

            //获取群成员数
            int memberCount = DBHelper.GetMemberCount(SourceGroup);

            //判断数据库错误和空公会
            switch (memberCount)
            {
            case -1:
                await BotUtils.DatabaseFailedTips(base.MessageEventArgs);

                return;

            case 0:
                await SourceGroup.SendGroupMessage("公会并没有成员");

                return;
            }

            //获取公会成员表
            List <MemberInfo> guildMembers = DBHelper.GetAllMembersInfo(SourceGroup);
            //获取公会名
            string guildName = DBHelper.GetGuildName(SourceGroup);

            //检查数据库错误
            if (guildName == null || guildMembers == null) //数据库错误
            {
                await BotUtils.DatabaseFailedTips(base.MessageEventArgs);

                return;
            }

            //构建消息文本
            StringBuilder sendMsg = new StringBuilder();

            sendMsg.Append($"公会[{guildName}]成员列表\r\n{memberCount}/30\r\n==================\r\n     UID     |   昵称");
            foreach (MemberInfo guildMember in guildMembers)
            {
                sendMsg.Append("\r\n");
                sendMsg.Append(guildMember.Uid);
                sendMsg.Append(" | ");
                sendMsg.Append(guildMember.Name);
            }

            //发送消息
            await SourceGroup.SendGroupMessage(sendMsg.ToString());
        }
Пример #2
0
        /// <summary>
        /// 权限检查/越权警告
        /// </summary>
        internal async Task <bool> AuthCheck()
        {
            if (IsAdmin)
            {
                return(true);
            }
            else
            {
                await SourceGroup.SendGroupMessage(CQCode.CQAt(Sender.Id),
                                                   " 你没有执行此指令的权限");

                ConsoleLog.Warning($"会战[群:{SourceGroup.Id}]", $"群成员{MessageEventArgs.SenderInfo.Nick}正在尝试执行指令{CommandType}");
                return(false);
            }
        }
Пример #3
0
        /// <summary>
        /// 删除公会
        /// </summary>
        private async void DeleteGuild()
        {
            //判断公会是否存在
            switch (DBHelper.GuildExists())
            {
            case 0:
                await SourceGroup.SendGroupMessage(CQCode.CQAt(Sender), "\r\n此群并未标记为公会");

                return;

            case -1:
                await SourceGroup.SendGroupMessage(CQCode.CQAt(Sender), "\r\nERROR\r\n数据库错误");

                return;
            }
            //获取当前群公会名
            string guildName = DBHelper.GetGuildName(SourceGroup);
            //删除公会
            await SourceGroup.SendGroupMessage(DBHelper.DeleteGuild(SourceGroup)
                                               ?$" 公会[{guildName}]已被删除。"
                                               : $" 公会[{guildName}]删除失败,数据库错误。");
        }
Пример #4
0
        /// <summary>
        /// 清空公会成员
        /// </summary>
        private async void QuitAll()
        {
            //检查公会是否存在
            if (DBHelper.GuildExists() != 1)
            {
                await SourceGroup.SendGroupMessage("该群未创建公会");

                return;
            }

            Log.Debug("database", $"Quit guild[{SourceGroup.Id}] all members");
            //清空成员
            switch (DBHelper.QuitAll(SourceGroup))
            {
            case 0:
                await SourceGroup.SendGroupMessage("公会成员已全部清空");

                break;

            case 1:
                await SourceGroup.SendGroupMessage("DB ERROR:公会不存在");

                Log.Error("database", $"guild {SourceGroup.Id} not found");
                break;

            case -1:
                await BotUtils.DatabaseFailedTips(MessageEventArgs);

                break;

            default:
                await SourceGroup.SendGroupMessage("发生了未知错误");

                Log.Error("Guild Mgr", "清空成员时发生了未知错误");
                break;
            }
        }
Пример #5
0
        /// <summary>
        /// 退会
        /// </summary>
        private async void QuitGuild()
        {
            //检查公会是否存在
            if (DBHelper.GuildExists() != 1)
            {
                await SourceGroup.SendGroupMessage("该群未创建公会");

                return;
            }

            //获取成员参数
            List <long> quitList = new List <long>();

            switch (BotUtils.CheckForLength(CommandArgs, 1))
            {
            case LenType.Illegal:
                quitList.Add(Sender);
                break;

            case LenType.Legitimate:     //只有单一成员时需判断uid参数
                quitList.AddRange(MessageEventArgs.Message.GetAllAtList());
                if (quitList.Count == 0)
                {
                    if (long.TryParse(CommandArgs[1], out long uid))
                    {
                        quitList.Add(uid);
                    }
                    else
                    {
                        await SourceGroup.SendGroupMessage("没有At任何成员");

                        return;
                    }
                }

                break;

            case LenType.Extra:
                quitList.AddRange(MessageEventArgs.Message.GetAllAtList());
                if (quitList.Count == 0)
                {
                    await SourceGroup.SendGroupMessage("没有At任何成员");

                    return;
                }

                break;
            }

            //检查列表中是否有机器人
            if (quitList.Any(member => member == MessageEventArgs.LoginUid))
            {
                quitList.Remove(MessageEventArgs.LoginUid);
                await SourceGroup.SendGroupMessage("不要在成员中At机器人啊kora");

                if (quitList.Count == 0)
                {
                    return;
                }
            }

            Log.Debug("Guild Mgr", $"Get quit list count={quitList.Count}");
            Dictionary <long, int> databaseRet = new Dictionary <long, int>();

            //删除退会成员
            foreach (long member in quitList)
            {
                databaseRet.Add(member,
                                DBHelper.QuitGuild(member, SourceGroup));
            }

            //构建格式化信息
            List <CQCode> responseMsg = new List <CQCode>();

            if (databaseRet.Any(ret => ret.Value == 0))
            {
                responseMsg.Add(CQCode.CQText("以下成员已退出:"));
                foreach (long member in databaseRet.Where(member => member.Value == 0)
                         .Select(member => member.Key)
                         .ToList())
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                    responseMsg.Add(CQCode.CQAt(member));
                }
            }

            if (databaseRet.Any(ret => ret.Value == 1))
            {
                if (responseMsg.Count != 0)
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                }
                responseMsg.Add(CQCode.CQText("以下成员并不在公会中:"));
                foreach (long member in databaseRet.Where(member => member.Value == 1)
                         .Select(member => member.Key)
                         .ToList())
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                    responseMsg.Add(CQCode.CQAt(member));
                }
            }

            if (databaseRet.Any(ret => ret.Value == -1))
            {
                if (responseMsg.Count != 0)
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                }
                responseMsg.Add(CQCode.CQText("以下成员在退出时发生错误:"));
                foreach (long member in databaseRet.Where(member => member.Value == -1)
                         .Select(member => member.Key)
                         .ToList())
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                    responseMsg.Add(CQCode.CQAt(member));
                }
            }

            //发送信息
            await SourceGroup.SendGroupMessage(responseMsg);
        }
Пример #6
0
        /// <summary>
        /// 加入除机器人外的所有成员
        /// 没有人数限制
        /// </summary>
        private async void JoinAll()
        {
            //检查公会是否存在
            if (DBHelper.GuildExists() != 1)
            {
                await SourceGroup.SendGroupMessage("该群未创建公会");

                return;
            }

            //获取所有成员的信息
            var(apiStatus, groupMemberList) = await SourceGroup.GetGroupMemberList();

            if (apiStatus != APIStatusType.OK)
            {
                Log.Error("API error", $"api ret code {(int) apiStatus}");
                await SourceGroup.SendGroupMessage(CQCode.CQAt(Sender), "\r\nAPI调用错误请重试");

                return;
            }

            //移除机器人的成员信息
            groupMemberList.RemoveAt(groupMemberList.FindIndex(member => member.UserId == MessageEventArgs.LoginUid));
            //添加成员到公会
            Dictionary <long, int> databaseRet = new Dictionary <long, int>();

            foreach (GroupMemberInfo member in groupMemberList)
            {
                //获取群成员名
                string memberName = groupMemberList.Any(memberInfo => memberInfo.UserId == member.UserId)
                    ? groupMemberList.Where(memberInfo => memberInfo.UserId == member.UserId)
                                    .Select(memberInfo =>
                                            string.IsNullOrEmpty(memberInfo.Card)
                                                     ? memberInfo.Nick
                                                     : memberInfo.Card)
                                    .First()
                    : "N/A";
                //添加成员
                databaseRet.Add(member.UserId,
                                DBHelper.JoinGuild(member.UserId, SourceGroup, memberName));
            }

            //构建格式化信息
            List <CQCode> responseMsg = new List <CQCode>();

            if (databaseRet.Any(ret => ret.Value == 0)) //成员成功加入
            {
                responseMsg.Add(CQCode.CQText("以下成员已加入:"));
                foreach (long member in databaseRet.Where(member => member.Value == 0)
                         .Select(member => member.Key)
                         .ToList())
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                    responseMsg.Add(CQCode.CQAt(member));
                }
            }

            if (databaseRet.Any(ret => ret.Value == 1)) //成员已存在
            {
                if (responseMsg.Count != 0)
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                }
                responseMsg.Add(CQCode.CQText("以下成员已在公会中,仅更新信息:"));
                foreach (long member in databaseRet.Where(member => member.Value == 1)
                         .Select(member => member.Key)
                         .ToList())
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                    responseMsg.Add(CQCode.CQAt(member));
                }
            }

            if (databaseRet.Any(ret => ret.Value == -1)) //数据库错误
            {
                if (responseMsg.Count != 0)
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                }
                responseMsg.Add(CQCode.CQText("以下成员在加入时发生错误:"));
                foreach (long member in databaseRet.Where(member => member.Value == -1)
                         .Select(member => member.Key)
                         .ToList())
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                    responseMsg.Add(CQCode.CQAt(member));
                }
            }

            //发送信息
            await SourceGroup.SendGroupMessage(responseMsg);
        }
Пример #7
0
        /// <summary>
        /// 加入公会
        /// </summary>
        private async void JoinGuild()
        {
            //检查公会是否存在
            if (DBHelper.GuildExists() != 1)
            {
                await SourceGroup.SendGroupMessage("该群未创建公会");

                return;
            }

            //处理需要加入的成员列表
            List <long> joinList = new List <long>();

            switch (BotUtils.CheckForLength(CommandArgs, 1))
            {
            case LenType.Illegal:
                joinList.Add(Sender);
                break;

            case LenType.Extra:
            case LenType.Legitimate:
                joinList.AddRange(MessageEventArgs.Message.GetAllAtList());
                if (joinList.Count == 0)
                {
                    await SourceGroup.SendGroupMessage("没有At任何成员");

                    return;
                }

                break;
            }

            //检查列表中是否有机器人
            if (joinList.Any(member => member == MessageEventArgs.LoginUid))
            {
                joinList.Remove(MessageEventArgs.LoginUid);
                await SourceGroup.SendGroupMessage("不要在成员中At机器人啊kora");

                if (joinList.Count == 0)
                {
                    return;
                }
            }

            Log.Debug("Guild Mgr", $"Get join list count={joinList.Count}");
            //从API获取成员信息
            Log.Debug("Guild Mgr", "Get group member infos");
            var(apiStatus, groupMemberList) = await SourceGroup.GetGroupMemberList();

            if (apiStatus != APIStatusType.OK)
            {
                Log.Error("API error", $"api ret code {(int) apiStatus}");
                await SourceGroup.SendGroupMessage(CQCode.CQAt(Sender), "\r\nAPI调用错误请重试");

                return;
            }

            //加入待加入的成员
            Dictionary <long, int> databaseRet = new Dictionary <long, int>();

            foreach (long member in joinList)
            {
                //获取群成员名
                string memberName = groupMemberList.Any(memberInfo => memberInfo.UserId == member)
                    ? groupMemberList.Where(memberInfo => memberInfo.UserId == member)
                                    .Select(memberInfo =>
                                            string.IsNullOrEmpty(memberInfo.Card)
                                                     ? memberInfo.Nick
                                                     : memberInfo.Card)
                                    .First()
                    : "N/A";
                //添加成员
                databaseRet.Add(member,
                                DBHelper.JoinGuild(member, SourceGroup, memberName));
            }

            //构建格式化信息
            List <CQCode> responseMsg = new List <CQCode>();

            if (databaseRet.Any(ret => ret.Value == 0)) //成员成功加入
            {
                responseMsg.Add(CQCode.CQText("以下成员已加入:"));
                foreach (long member in databaseRet.Where(member => member.Value == 0)
                         .Select(member => member.Key)
                         .ToList())
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                    responseMsg.Add(CQCode.CQAt(member));
                }
            }

            if (databaseRet.Any(ret => ret.Value == 1)) //成员已存在
            {
                if (responseMsg.Count != 0)
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                }
                responseMsg.Add(CQCode.CQText("以下成员已在公会中,仅更新信息:"));
                foreach (long member in databaseRet.Where(member => member.Value == 1)
                         .Select(member => member.Key)
                         .ToList())
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                    responseMsg.Add(CQCode.CQAt(member));
                }
            }

            if (databaseRet.Any(ret => ret.Value == -1)) //数据库错误
            {
                if (responseMsg.Count != 0)
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                }
                responseMsg.Add(CQCode.CQText("以下成员在加入时发生错误:"));
                foreach (long member in databaseRet.Where(member => member.Value == -1)
                         .Select(member => member.Key)
                         .ToList())
                {
                    responseMsg.Add(CQCode.CQText("\r\n"));
                    responseMsg.Add(CQCode.CQAt(member));
                }
            }

            //发送信息
            await SourceGroup.SendGroupMessage(responseMsg);
        }