/// <summary> /// 确定指定的对象是否等于当前对象 /// </summary> /// <param name="obj">要与当前对象进行比较的对象</param> /// <returns>如果指定的对象等于当前对象,则为 <code>true</code>,否则为 <code>false</code></returns> public override bool Equals(object obj) { CQCode code = obj as CQCode; if (code != null) { return(string.Equals(this._originalString, code._originalString)); } return(base.Equals(obj)); }
/// <summary> /// 使用 <see cref="CQApi"/> 和相关消息来初始化 <see cref="QQMessage"/> 类的新实例 /// </summary> /// <param name="api">模型使用的 <see cref="Cqp.CQApi"/></param> /// <param name="msgId">模型使用的消息Id</param> /// <param name="msg">模型使用的消息原文</param> /// <param name="isRegexMsg">指示当前实例是否是正则消息</param> public QQMessage(CQApi api, int msgId, string msg, bool isRegexMsg = false) : base(api, (isRegexMsg == true) ? msg : string.Empty) { if (object.ReferenceEquals(msg, null)) { throw new ArgumentNullException("msg"); } this.Id = msgId; this.Text = msg; this.IsRegexMessage = isRegexMsg; if (!this.IsRegexMessage) { this.CQCodes = CQCode.Parse(this.Text); } }
/// <summary> /// 接收消息中的图片 (消息含有CQ码 "image" 的消息) /// </summary> /// <param name="index">要接收的图片索引, 该索引从 0 开始</param> /// <returns>返回图片文件位于本地服务器的绝对路径</returns> public string ReceiveImage(int index) { if (!this.IsRegexMessage) { CQCode image = (from code in this.CQCodes where code.Function == CQFunction.Image select code).Skip(index).First(); return(this.CQApi.ReceiveImage(image.Items["file"])); } else { #if DEBUG throw new MethodAccessException("无法在正则事件中调用 ToSendString, 因为正则事件获取的消息无法用于发送"); #else return(null); #endif } }
/// <summary> /// 接收消息中的语音 (消息含有CQ码 "record" 的消息) /// </summary> /// <param name="format">所需的目标语音的音频格式</param> /// <returns>返回语音文件位于本地服务器的绝对路径</returns> public string ReceiveRecord(CQAudioFormat format) { if (!this.IsRegexMessage) { CQCode record = (from code in this.CQCodes where code.Function == CQFunction.Record select code).First(); return(this.CQApi.ReceiveRecord(record.Items["file"], format)); } else { #if DEBUG throw new MethodAccessException("无法在正则事件中调用 ToSendString, 因为正则事件获取的消息无法用于发送"); #else return(null); #endif } }
/// <summary> /// 判断是否是语音 <see cref="CQCode"/> /// </summary> /// <param name="code">要判断的 <see cref="CQCode"/> 实例</param> /// <returns>如果是语音 <see cref="CQCode"/> 返回 <see langword="true"/> 否则返回 <see langword="false"/></returns> public static bool EqualIsRecordCQCode(CQCode code) { return(code.Function == CQFunction.Record); }
/// <summary> /// 判断是否是图片 <see cref="CQCode"/> /// </summary> /// <param name="code">要判断的 <see cref="CQCode"/> 实例</param> /// <returns>如果是图片 <see cref="CQCode"/> 返回 <see langword="true"/> 否则返回 <see langword="false"/></returns> public static bool EqualIsImageCQCode(CQCode code) { return(code.Function == CQFunction.Image); }