Esempio n. 1
0
 /// <summary>
 /// 群消息
 /// </summary>
 /// <param name="msg"></param>
 /// <returns>0不拦截 1拦截消息</returns>
 public override int GroupMsgProcess(GroupMsg msg, long CurrentQQ)
 {
     Console.WriteLine($"GroupMsgProcess {CurrentQQ}\n" + JsonConvert.SerializeObject(msg));
     if (msg.FromGroupId != 516141713)
     {
         return(0);
     }
     if (msg.MsgType == MsgType.PicMsg)
     {
         PicContent picContent = msg.GetPic();
         Apis.SendGroupMsg(msg.FromGroupId, picContent.Content + CodeUtils.At(msg.FromUserId) + CodeUtils.Pic_Http(picContent.FriendPic.FirstOrDefault().Url));
     }
     else if (msg.MsgType == MsgType.VoiceMsg)
     {
         VoiceContent voiceContent = msg.GetVoice();
         Apis.SendGroupMsg(msg.FromGroupId, voiceContent.Content + CodeUtils.Voice_Http(voiceContent.Url));
     }
     else
     {
         Apis.SendGroupMsg(msg.FromGroupId, msg.Content + CodeUtils.At(msg.FromUserId));
     }
     Apis.RevokeMsg(new OPQSDK.Models.Api.RevokeMsgReq {
         GroupID = msg.FromGroupId, MsgRandom = msg.MsgRandom, MsgSeq = msg.MsgRandom
     });
     return(0);
 }
Esempio n. 2
0
        /// <summary>
        /// 从 TopicInfo 提取 TopicBasic
        /// </summary>
        /// <param name="topicInfo"></param>
        /// <returns></returns>
        internal static TopicBasic ToTopicBasic(this TopicInfo topicInfo)
        {
            TopicBasic topic = new TopicBasic
            {
                Id            = topicInfo.TopicId,
                Title         = topicInfo.Title,
                Icon          = topicInfo.Icon.ImageUrlFixed(100, 100),
                Owner         = UserBiz.ReadUserCacheInfo(topicInfo.UserId).ToUserBase(),
                IsRefined     = topicInfo.IsRefined,
                TopicType     = topicInfo.Reward > 0 ? TopicType.Reward : (topicInfo.IsQuestion ? TopicType.Questions : TopicType.Normal),
                RewardCount   = topicInfo.Reward,
                HasBestAnswer = topicInfo.BestAnswerId > 0,
                FavouredCount = topicInfo.FavouredCount,
                RepliedCount  = topicInfo.RepliedCount,
                PublishTime   = topicInfo.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"),
                //Voice = new VoiceContent { },
                Intro        = topicInfo.Intro,
                IsAllowReply = topicInfo.IsAllowReply
            };

            if (!string.IsNullOrEmpty(topicInfo.Voice) && topicInfo.Voice.StartsWith("<Voice "))
            {
                VoiceContent voiceContent = null;
                try
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(topicInfo.Voice.Trim());
                    XmlNode node = xmlDoc.SelectSingleNode("Voice");
                    voiceContent = node.GetVoiceContent();
                }
                catch (Exception ex)
                {
                    ex.Error();
                    voiceContent = null;
                }
                finally
                {
                    topic.Voice = voiceContent;
                }
            }

            return(topic);
        }
Esempio n. 3
0
        /// <summary>
        /// 私聊消息
        /// </summary>
        /// <param name="msg"></param>
        /// <returns>0不拦截 1拦截消息</returns>
        public override int FriendMsgProcess(FriendMsg msg, long CurrentQQ)
        {
            Console.WriteLine($"FriendMsgProcess {CurrentQQ}\n" + JsonConvert.SerializeObject(msg));
            if (msg.MsgType == MsgType.PicMsg)
            {
                PicContent picContent = msg.GetPic();
                Apis.SendFriendMsg(msg.FromUin, picContent.Content + CodeUtils.Pic_Http(picContent.FriendPic.FirstOrDefault().Url));
            }
            else if (msg.MsgType == MsgType.VoiceMsg)
            {
                VoiceContent voiceContent = msg.GetVoice();
                Apis.SendFriendMsg(msg.FromUin, voiceContent.Content + CodeUtils.Voice_Http(voiceContent.Url));
            }
            else
            {
                Apis.SendFriendMsg(msg.FromUin, msg.Content);
            }

            return(0);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取帖子内容块列表
        /// </summary>
        /// <param name="sourceTopicContent"></param>
        /// <returns></returns>
        private static List <TopicContent> GetTopicContentList(this string sourceTopicContent)
        {
            List <TopicContent> contentList = new List <TopicContent>(0);

            if (!string.IsNullOrEmpty(sourceTopicContent) && sourceTopicContent.StartsWith("<TopicContent>") && sourceTopicContent.EndsWith("</TopicContent>"))
            {
                try
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(sourceTopicContent.Trim());
                    XmlNode rootNode = xmlDoc.SelectSingleNode("TopicContent");
                    if (null != rootNode && rootNode.HasChildNodes)
                    {
                        foreach (XmlNode node in rootNode.ChildNodes)
                        {
                            if (node.NodeType == XmlNodeType.Element)
                            {
                                //ContentType ct = (ContentType)Enum.Parse(typeof(ContentType), node.Name, true);
                                ContentType ct   = GetTopicContentType(node.Name);
                                byte[]      data = null;
                                switch (ct)
                                {
                                case ContentType.Image:
                                    ImageContent imageContent = node.GetImageContent();
                                    if (null != imageContent)
                                    {
                                        data = imageContent.ProtoBufSerialize <ImageContent>();
                                    }
                                    break;

                                case ContentType.Voice:
                                    VoiceContent voiceContent = node.GetVoiceContent();
                                    if (null != voiceContent)
                                    {
                                        data = voiceContent.ProtoBufSerialize <VoiceContent>();
                                    }
                                    break;

                                case ContentType.Video:
                                    VideoContent videoContent = node.GetVideoContent();
                                    if (null != videoContent)
                                    {
                                        data = videoContent.ProtoBufSerialize <VideoContent>();
                                    }
                                    break;

                                case ContentType.Address:
                                    AddressContent addressContent = node.GetAddressContent();
                                    if (null != addressContent)
                                    {
                                        data = addressContent.ProtoBufSerialize <AddressContent>();
                                    }
                                    break;

                                case ContentType.Telphone:
                                    TelphoneContent telphoneContent = node.GetTelphoneContent();
                                    if (null != telphoneContent)
                                    {
                                        data = telphoneContent.ProtoBufSerialize <TelphoneContent>();
                                    }
                                    break;

                                case ContentType.Contact:
                                    ContactContent contactContent = node.GetContactContent();
                                    if (null != contactContent)
                                    {
                                        data = contactContent.ProtoBufSerialize <ContactContent>();
                                    }
                                    break;

                                case ContentType.Text:
                                default:
                                    TextContent textContent = node.GetTextContent();
                                    if (null != textContent)
                                    {
                                        data = textContent.ProtoBufSerialize <TextContent>();
                                    }
                                    break;
                                }

                                TopicContent content = new TopicContent {
                                    ContentType = ct, Data = data
                                };
                                contentList.Add(content);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ex.Error();
                }
            }
            return(contentList);
        }