Esempio n. 1
0
        /// <summary>
        /// 私聊消息处理事件
        /// </summary>
        private static void FriendMessageHandler(string fn)
        {
            Task task = new Task(() =>
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                ReceiveMessage PrivateMessage = JsonConvert.DeserializeObject <ReceiveMessage>(fn);
                string message = ProgressMessage.Start(PrivateMessage);
                var b          = Encoding.UTF8.GetBytes(message);
                message        = GB18030.GetString(Encoding.Convert(Encoding.UTF8, GB18030, b));
                int msgID      = PrivateMessage.CurrentPacket.Data.MsgSeq;

                ReceiveMessage.Data data = PrivateMessage.CurrentPacket.Data;
                if (PrivateMessage.CurrentPacket.Data.FromUin == Save.curentQQ && !Save.ReceiveSelfMsg)
                {
                    Dll.AddMsgToSave(new Deserizition.Message(msgID, data.MsgRandom, data.MsgSeq, data.FromUin, data.FromGroupId, data.MsgTime, message, data.TempUin));
                    return;
                }
                int logid = LogHelper.WriteLog(LogLevel.InfoReceive, "OPQBot框架", "[↓]收到好友消息", $"QQ:{data.FromUin} {message}", "处理中...");
                var c     = new Deserizition.Message(msgID, data.MsgRandom, data.MsgSeq, data.FromUin, data.FromGroupId, data.MsgTime, message, data.TempUin);
                Dll.AddMsgToSave(c);
                int pluginid = pluginManagment.CallFunction(FunctionEnums.Functions.PrivateMsg, 11, msgID, data.FromUin, Marshal.StringToHGlobalAnsi(message), 0);
                stopwatch.Stop();
                string updatemsg = $"√ {stopwatch.ElapsedMilliseconds / (double)1000:f2} s";
                if (pluginid > 0)
                {
                    updatemsg += $"(由 {pluginManagment.Plugins[pluginid - 1].appinfo.Name} 结束消息处理)";
                }
                LogHelper.UpdateLogStatus(logid, updatemsg);
            }); task.Start();
        }
Esempio n. 2
0
        /// <summary>
        /// 群消息处理事件
        /// </summary>
        private static void GroupMessageHandler(string fn)
        {
            Task task = new Task(() =>
            {
                string msg          = fn;
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                ReceiveMessage groupMessage = JsonConvert.DeserializeObject <ReceiveMessage>(msg);
                ReceiveMessage.Data data    = groupMessage.CurrentPacket.Data;
                //群文件事件
                if (groupMessage.CurrentPacket.Data.MsgType == "GroupFileMsg")
                {
                    JObject fileupload        = JObject.Parse(data.Content);
                    MemoryStream stream       = new MemoryStream();
                    BinaryWriter binaryWriter = new BinaryWriter(stream);
                    BinaryWriterExpand.Write_Ex(binaryWriter, fileupload["FileID"].ToString());
                    BinaryWriterExpand.Write_Ex(binaryWriter, fileupload["FileName"].ToString());
                    BinaryWriterExpand.Write_Ex(binaryWriter, Convert.ToInt64(fileupload["FileSize"].ToString()));
                    BinaryWriterExpand.Write_Ex(binaryWriter, 0);
                    pluginManagment.CallFunction(FunctionEnums.Functions.Upload, 1, GetTimeStamp(), data.FromGroupId,
                                                 data.FromUserId, Convert.ToBase64String(stream.ToArray()));
                    stopwatch.Stop();
                    LogHelper.WriteLog(LogLevel.InfoReceive, "OPQBot框架", "文件上传", $"来源群:{data.FromGroupId}({data.FromGroupName}) 来源QQ:{data.FromUserId}({data.FromNickName}) " +
                                       $"文件名:{fileupload["FileName"]} 大小:{Convert.ToDouble(fileupload["FileSize"]) / 1000}KB FileID:{fileupload["FileID"]}", $"√ {stopwatch.ElapsedMilliseconds / (double)1000:f2} s");
                    return;
                }
                string message = ProgressMessage.Start(groupMessage);
                var b          = Encoding.UTF8.GetBytes(message);
                message        = GB18030.GetString(Encoding.Convert(Encoding.UTF8, GB18030, b));

                //表示自己发送出去的消息, 写入消息列表
                int msgID = groupMessage.CurrentPacket.Data.MsgSeq;
                if (groupMessage.CurrentPacket.Data.FromUserId == Save.curentQQ && !Save.ReceiveSelfMsg)
                {
                    Dll.AddMsgToSave(new Deserizition.Message(msgID, data.MsgRandom, data.MsgSeq, data.FromUin, data.FromGroupId, data.MsgTime, message, data.TempUin));
                    return;
                }
                int logid = LogHelper.WriteLog(LogLevel.InfoReceive, "OPQBot框架", "[↓]收到消息", $"群:{data.FromGroupId}({data.FromGroupName}) QQ:{data.FromUserId}({data.FromNickName}) {message}", "处理中...");
                var c     = new Deserizition.Message(msgID, data.MsgRandom, data.MsgSeq, data.FromUin, data.FromGroupId, data.MsgTime, message, data.TempUin);
                Dll.AddMsgToSave(c);//保存消息到消息列表
                byte[] messageBytes = GB18030.GetBytes(message + "\0");
                var messageIntptr   = Marshal.AllocHGlobal(messageBytes.Length);
                Marshal.Copy(messageBytes, 0, messageIntptr, messageBytes.Length);
                //调用插件功能
                int pluginid = pluginManagment.CallFunction(FunctionEnums.Functions.GroupMsg, 2, msgID, data.FromGroupId, data.FromUserId,
                                                            "", messageIntptr, 0);
                Marshal.FreeHGlobal(messageIntptr);
                GC.Collect();
                stopwatch.Stop();
                string updatemsg = $"√ {stopwatch.ElapsedMilliseconds / (double)1000:f2} s";
                if (pluginid > 0)
                {
                    updatemsg += $"(由 {pluginManagment.Plugins[pluginid - 1].appinfo.Name} 结束消息处理)";
                }
                LogHelper.UpdateLogStatus(logid, updatemsg);
            }); task.Start();
        }