Cyrus-Vance_Magic-Conch/CyrusVance.CoolQRobot/Clients/CQApiClient/Request.partial.cs
using System.Threading.Tasks;
using CyrusVance.CoolQRobot.ApiCall.Requests;
using CyrusVance.CoolQRobot.ApiCall.Requests.Base;
using CyrusVance.CoolQRobot.ApiCall.Results;
using CyrusVance.CoolQRobot.ApiCall.Results.Base;
using CyrusVance.CoolQRobot.Enums;
using CyrusVance.CoolQRobot.Messages;

namespace CyrusVance.CoolQRobot.Clients {
    /// <summary></summary>
    public partial class CQApiClient {
        /// <summary>调用相应API</summary>
        public async Task<ApiResult> SendRequestAsync (ApiRequest x) {
            var result = await caller.SendRequestAsync (x);
            Log.Info ($"进行了{x.GetType ()}请求");
            if (group_table != null) {
                if (x is GetGroupMemberInfoRequest) {
                    var r = x.response as GetGroupMemberInfoResult;
                    group_table[r.memberInfo.group_id].Add (
                        r.memberInfo.user_id, r.memberInfo
                    );
                } else if (x is GetGroupMemberListRequest) {
                    foreach (var i in (x.response as GetGroupMemberListResult).memberInfo) {
                        group_table[i.group_id][i.user_id] = i;
                    }
                }
            }
            if (message_table != null) {
                if (x.response is SendmsgResult) {
                    var i = x.response as SendmsgResult;
                    message_table.Log (i.message_id, (x as SendmsgRequest).message);
                }
            }
            return result;
        }
        /// <summary>发送消息(自行构造)</summary>
        public async Task<SendmsgResult> SendMessageAsync (
            MessageType messageType,
            long target,
            Message message
        ) => await SendRequestAsync (
            new SendmsgRequest (messageType, target, message)
        ) as SendmsgResult;

        /// <summary>发送消息(自行构造)</summary>
        public async Task<SendmsgResult> SendMessageAsync (
            (MessageType, long) target,
            Message message
        ) => await SendRequestAsync (
            new SendmsgRequest (target.Item1, target.Item2, message)
        ) as SendmsgResult;

        /// <summary>发送纯文本消息</summary>
        public async Task<SendmsgResult> SendTextAsync (
            MessageType messageType,
            long target,
            string text
        ) => await SendRequestAsync (
            new SendmsgRequest (
                messageType, target,
                new Message (new Messages.CQElements.ElementText (text))
            )
        ) as SendmsgResult;

        /// <summary>发送纯文本消息</summary>
        public async Task<SendmsgResult> SendTextAsync (
            (MessageType, long) target,
            string text
        ) => await SendRequestAsync (
            new SendmsgRequest (
                target.Item1, target.Item2,
                new Message (new Messages.CQElements.ElementText (text))
            )
        ) as SendmsgResult;
    }
}