Exemplo n.º 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 DBMsgUtils.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 DBMsgUtils.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());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 清空公会成员
        /// </summary>
        private async void QuitAll()
        {
            //检查公会是否存在
            if (DBHelper.GuildExists() != 1)
            {
                await SourceGroup.SendGroupMessage("该群未创建公会");

                return;
            }
            ConsoleLog.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:公会不存在");

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

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

                break;

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

                ConsoleLog.Error("Guild Mgr", "清空成员时发生了未知错误");
                break;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 创建公会
        /// </summary>
        private async void CreateGuild()
        {
            //检查群是否已经被标记为公会
            switch (this.DBHelper.GuildExists())
            {
            case 1:
                await base.SourceGroup.SendGroupMessage(CQCode.CQAt(base.Sender),
                                                        $"此群已被标记为[{DBHelper.GetGuildInfo(base.SourceGroup).GuildName}]公会");

                return;
            }
            //公会名
            string guildName;
            //公会区服
            Server guildServer;

            //判断公会名
            switch (BotUtils.CheckForLength(this.CommandArgs, 1))
            {
            case LenType.Extra:
                if (BotUtils.CheckForLength(this.CommandArgs, 2) == LenType.Legitimate)
                {
                    guildName = CommandArgs[2];
                }
                else
                {
                    await base.SourceGroup.SendGroupMessage(CQCode.CQAt(base.Sender), "\r\n有多余参数");

                    return;
                }
                break;

            case LenType.Legitimate:
                var groupInfo = await base.SourceGroup.GetGroupInfo();

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

                    return;
                }
                guildName = groupInfo.groupInfo.GroupName;
                break;

            default:
                return;
            }
            //判断区服
            if (Enum.IsDefined(typeof(Server), CommandArgs[1]))
            {
                guildServer = (Server)Enum.Parse(typeof(Server), CommandArgs[1]);
                if (guildServer != Server.CN)
                {
                    await base.SourceGroup.SendGroupMessage("暂不支持国服以外的服务器");

                    return;
                }
            }
            else
            {
                await base.SourceGroup.SendGroupMessage(CQCode.CQAt(base.Sender),
                                                        "弟啊,你哪个服务器的");

                return;
            }

            switch (this.DBHelper.CreateGuild(guildServer, guildName, base.SourceGroup))
            {
            case -1:
                await DBMsgUtils.DatabaseFailedTips(MessageEventArgs);

                break;

            case 0:
                await base.SourceGroup.SendGroupMessage($"公会[{guildName}]已创建");

                break;

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

                break;
            }
        }