示例#1
0
        public static void StartListenRoomTask(string IdolName, int timedelay)
        {
            Task task = new Task(() => {
                if (PocketPlugins.RunProject.ContainsKey(IdolName))
                {
                    int threadId = (int)PocketPlugins.RunProject[IdolName];
                    if (Thread.CurrentThread.ManagedThreadId != threadId)
                    {
                        PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, string.Format("[{0}]任务已经存在,退出", IdolName));
                        return;
                    }
                }
                else
                {
                    PocketPlugins.RunProject.Add(IdolName, Thread.CurrentThread.ManagedThreadId);
                }

                try
                {
                    while (true)
                    {
                        if (!PocketPlugins.RunTimeCfg.ContainsKey(IdolName))
                        {
                            PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, IdolName + " 配置不存在,监听线程退出");
                            if (PocketPlugins.RunProject.ContainsKey(IdolName))
                            {
                                PocketPlugins.RunProject.Remove(IdolName);
                            }
                            return;
                        }
                        ListenRunTimeConfig config = (ListenRunTimeConfig)PocketPlugins.RunTimeCfg[IdolName];
                        string json = GetRoomMessage(config, PocketPlugins.User);
                        if (json == "")
                        {
                            PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "Token可能过期了,请及时更换,面板左下角登录一下就好,间隔自动拉大到一分钟");
                            Thread.Sleep(60000);
                            continue;
                        }
                        if (json == "http error")
                        {
                            PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "访问异常,如配置有代理请尝试更换,如果确定代理没问题,则可能是口袋抽风,过段时间还是不行,恭喜你被拉黑了!");
                            Thread.Sleep(60000);
                            continue;
                        }
                        Thread.Sleep(timedelay);
                        //PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, string.Format("[{0}]监听开始。延迟{1}ms", IdolName, timedelay));
                        ProcessRoomMessage(json, config);
                        config.UpdateTime = DateTime.Now;
                        PocketPlugins.RunTimeCfg[IdolName] = config;
                        Thread.Sleep(config.Delay);
                    }
                }
                catch (Exception ex)
                {
                    WriteLog(ex);
                }
            });

            task.Start();
        }
        private void list_listen_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (list_listen.SelectedItem == null)
            {
                return;
            }

            ListenRunTimeConfig config = (ListenRunTimeConfig)list_listen.SelectedItem;

            txt_idolname.Text  = config.IdolName;
            roomid             = config.RoomId.ToString();
            txt_roomdelay.Text = config.ShortDelay.ToString();
            txt_longdelay.Text = config.LongDelay.ToString();

            cb_audio.Checked  = config.TransmitAudio;
            cb_image.Checked  = config.TransmitImage;
            cb_fanpai.Checked = config.TransmitFanpai;
            cb_text.Checked   = config.TransmitText;
            cb_video.Checked  = config.TransmitVideo;
            cb_live.Checked   = config.TransmitLive;
            cb_flip.Checked   = config.TransmitFlip;

            if (config.QQGroups.Count == 1)
            {
                txt_qqgroups.Text = config.QQGroups[0].ToString();
            }
            else
            {
                txt_qqgroups.Text = config.QQGroups[0].ToString();
                for (int tmp = 1; tmp < config.QQGroups.Count; tmp++)
                {
                    txt_qqgroups.Text += "," + config.QQGroups[tmp].ToString();
                }
            }
        }
        private void btn_configsave_Click(object sender, EventArgs e)
        {
            JObject configFile = new JObject();

            if (PocketPlugins.User != null)
            {
                configFile["User"] = JToken.FromObject(PocketPlugins.User);
            }

            configFile["IMEI"]       = PocketSetting.IMEI;
            configFile["ShortDelay"] = PocketSetting.ShortDelay = int.Parse(txt_roomdelay.Text);
            configFile["LongDelay"]  = PocketSetting.LongDelay = int.Parse(txt_longdelay.Text);
            configFile["httpport"]   = textBox_HTTPPORT.Text;

            /*if(txt_livedelay.Text != "")
             *  configFile["LiveDelay"] = txt_livedelay.Text;*/

            if (AutoStart.Checked)
            {
                configFile["AutoStart"] = true;
            }
            else
            {
                configFile["AutoStart"] = false;
            }

            if (checkBox_http.Checked)
            {
                configFile["httpmsg"] = true;
            }
            else
            {
                configFile["httpmsg"] = false;
            }

            if (rb_air.Checked)
            {
                configFile["CoolQAir"] = true;
            }
            else
            {
                configFile["CoolQAir"] = false;
            }

            JArray arr = new JArray();

            foreach (var idol in PocketPlugins.RunTimeCfg.Keys)
            {
                ListenRunTimeConfig config = (ListenRunTimeConfig)PocketPlugins.RunTimeCfg[idol];
                arr.Add(JToken.FromObject(config));
            }
            configFile["IdolInfo"] = arr;

            File.WriteAllText("PocketConfig.json", configFile.ToString());
            MessageBox.Show("保存完毕", "成功");
        }
 public panel()
 {
     InitializeComponent();
     foreach (var key in PocketPlugins.RunTimeCfg.Keys)
     {
         ListenRunTimeConfig cfg = (ListenRunTimeConfig)PocketPlugins.RunTimeCfg[key];
         list_listen.Items.Add(cfg);
     }
     list_listen.DisplayMember = "IdolName";
 }
示例#5
0
        private void btn_delete_Click(object sender, EventArgs e)
        {
            if (list_listen.SelectedItem == null)
            {
                MessageBox.Show("请先选中配置!", "错误");
                return;
            }
            ListenRunTimeConfig config = (ListenRunTimeConfig)list_listen.SelectedItem;

            PocketPlugins.RunTimeCfg.Remove(config.IdolName);
            list_listen.Items.Remove(config);
            MessageBox.Show("删除完毕", "成功");
        }
 private static bool ProcessLive(string json, ref long lasttime)
 {
     try
     {
         JObject obj = JObject.Parse(json);
         if ((int)obj["status"] == 200)
         {
             IEnumerable <JToken> datas = obj.SelectTokens("$.content.liveList[*]");
             int count = 0;
             foreach (JToken liveInfo in datas)
             {
                 if (LiveCache.ContainsKey(liveInfo["liveId"]))
                 {
                     break;
                 }
                 //懒得想算法了,直接很粗暴的按的字分割了
                 //title字段师xxx的直播间/电台,所以上面的idcache就直接看看有没有这个键,有的话直接推送了
                 string[] name = liveInfo["title"].ToString().Split(new string[] { "的" }, StringSplitOptions.RemoveEmptyEntries);
                 if (PocketPlugins.RunTimeCfg.ContainsKey(name[0]))
                 {
                     //File.AppendAllText("LiveError.log", "捕获:" + liveInfo["liveId"] + "\r\n");
                     PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "捕获到 " + name[0] + " 的直播,LiveID:" + liveInfo["liveId"]);
                     LiveCache.Add(liveInfo["liveId"], 1);
                     ListenRunTimeConfig cfg = (ListenRunTimeConfig)PocketPlugins.RunTimeCfg[name[0]];
                     foreach (long qqGourp in cfg.QQGroups)
                     {
                         PocketPlugins.Api.SendGroupMsg(qqGourp, "你的小偶像 " + name[0] + " 打开了一个直播\r\n直播连接:https://h5.48.cn/2017appshare/memberLiveShare/index.html?id=" + liveInfo["liveId"] + "\r\n使用KD For PC观看直播~也很棒哦!");
                     }
                 }
                 count++;
                 lasttime = long.Parse(liveInfo["startTime"].ToString());
             }
             if (count == 20)
             {
                 return(false);
             }
             else
             {
                 return(true);
             }
         }
         return(true);
     }
     catch (Exception ex)
     {
         WriteLog(ex);
         return(true);
     }
 }
        public static string GetRoomMessage(ListenRunTimeConfig config, UserInfo user)
        {
            HttpClientHandler handler = new HttpClientHandler();

            if (config.Proxy != null)
            {
                handler.UseProxy = config.Proxy.UseProxy;
                if (config.Proxy.UseProxy)
                {
                    handler.Proxy = new WebProxy(config.Proxy.FullIP);
                }
            }
            string repo = GetRoomMessage(handler, user.PocketToken, config.RoomId);

            return(repo);
        }
        public override int ProcessGroupMessage(int subType, int sendTime, long fromGroup, long fromQq, string fromAnonymous, string msg, int font)
        {
            if (msg.Contains("debug"))
            {
                string[] cmd = msg.Split(' ');

                if (cmd[0] != "debug")
                {
                    return(1);
                }

                if (cmd[1] == "time")
                {
                    string send = "debug info:";
                    foreach (string key in RunTimeCfg.Keys)
                    {
                        ListenRunTimeConfig cfg = (ListenRunTimeConfig)RunTimeCfg[key];
                        if (cfg.QQGroups.Contains(fromGroup))
                        {
                            send += string.Format("\r\n{0}:{1}[{2}]", cfg.IdolName, cfg.UpdateTime.ToString(), key);
                        }
                        CoolQApi.SendGroupMsg(fromGroup, send);
                    }
                }

                if (cmd[1] == "restart")
                {
                    string key = cmd[2];
                    if (RunProject.ContainsKey(key))
                    {
                        RunProject.Remove(key);
                    }

                    Common.StartListenRoomTask(key);
                    CoolQApi.SendGroupMsg(fromGroup, key + "任务重建完毕,请查看酷Q日志配合time命令查看是否恢复任务");
                }
            }
            return(base.ProcessGroupMessage(subType, sendTime, fromGroup, fromQq, fromAnonymous, msg, font));
        }
示例#9
0
        public override int ProcessGroupMessage(int subType, int sendTime, long fromGroup, long fromQq, string fromAnonymous, string msg, int font)
        {
            //File.AppendAllText("groupmsg.log", string.Format(msg));
            if (msg.Contains("debug"))
            {
                string[] cmd = msg.Split(' ');

                if (cmd[0] != "debug")
                {
                    return(1);
                }

                if (cmd[1] == "time")
                {
                    string send = "debug info:";
                    foreach (string key in RunTimeCfg.Keys)
                    {
                        ListenRunTimeConfig cfg = (ListenRunTimeConfig)RunTimeCfg[key];
                        if (cfg.QQGroups.Contains(fromGroup))
                        {
                            send += string.Format("\r\n{0}:{1}[{2}]", cfg.IdolName, cfg.UpdateTime.ToString(), key);
                        }
                        //CoolQApi.SendGroupMsg(fromGroup, send);
                    }
                }

                // if (cmd[1] == "重启")
                // {
                //string key = cmd[2];
                //if (RunProject.ContainsKey(key))
                //    RunProject.Remove(key);

                //Common.StartListenRoomTask(key);
                //PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "任务重建完毕,请查看酷Q日志配合time命令查看是否恢复任务");
                //CoolQApi.SendGroupMsg(fromGroup, key + "任务重建完毕,请查看酷Q日志配合time命令查看是否恢复任务");
                // }
            }
            return(base.ProcessGroupMessage(subType, sendTime, fromGroup, fromQq, fromAnonymous, msg, font));
        }
示例#10
0
        private void btn_idoladd_Click(object sender, EventArgs e)
        {
            if (list_listen.Items.Count >= PocketSetting.MaxListen)
            {
                MessageBox.Show(string.Format("超出了{0}人的限制!禁止添加!", PocketSetting.MaxListen), "错误");
                return;
            }

            if (int.Parse(txt_roomdelay.Text) < 5000 || int.Parse(txt_longdelay.Text) < 25000)
            {
                MessageBox.Show("短延迟不能低于5000,长延迟不能低于20000", "错误");
                return;
            }


            ListenRunTimeConfig cfg = new ListenRunTimeConfig();

            cfg.IdolName = txt_idolname.Text;
            if (roomid == "")
            {
                MessageBox.Show("无法添加这位小偶像,请确认是否已经正确查找到roomid信息");
                return;
            }
            cfg.RoomId         = int.Parse(roomid);
            cfg.TransmitText   = cb_text.Checked;
            cfg.TransmitAudio  = cb_audio.Checked;
            cfg.TransmitVideo  = cb_video.Checked;
            cfg.TransmitImage  = cb_image.Checked;
            cfg.TransmitFanpai = cb_fanpai.Checked;
            cfg.TransmitGift   = cb_flip.Checked;
            cfg.TransmitLive   = cb_live.Checked;
            cfg.TransmitFlip   = cb_flip.Checked;

            cfg.QQGroups = new List <long>();
            string[] qqGroups = txt_qqgroups.Text.Split(',');
            if (qqGroups.Length == 1)
            {
                if (qqGroups[0] != "")
                {
                    cfg.QQGroups.Add(long.Parse(qqGroups[0]));
                }
            }
            else
            {
                foreach (string qqGroup in qqGroups)
                {
                    if (qqGroup != "")
                    {
                        cfg.QQGroups.Add(long.Parse(qqGroup));
                    }
                }
            }
            if (cfg.QQGroups.Count == 0)
            {
                MessageBox.Show("请添加QQ群!", "错误");
                return;
            }

            if (rb_air.Checked)
            {
                PocketPlugins.CommonCfg.CoolQAir = true;
            }
            if (rb_pro.Checked)
            {
                PocketPlugins.CommonCfg.CoolQAir = false;
            }

            cfg.Delay      = int.Parse(txt_roomdelay.Text);
            cfg.ShortDelay = int.Parse(txt_roomdelay.Text);
            cfg.LongDelay  = int.Parse(txt_longdelay.Text);
            cfg.First      = true;

            cfg.Proxy = PocketPlugins.Proxy;

            if (PocketPlugins.RunTimeCfg.ContainsKey(cfg.IdolName))
            {
                PocketPlugins.RunTimeCfg[cfg.IdolName] = cfg;
                MessageBox.Show(cfg.IdolName + " 配置已存在,本次添加为配置替换操作", "成功");
            }
            else
            {
                list_listen.Items.Add(cfg);
                list_listen.DisplayMember = "IdolName";
                PocketPlugins.RunTimeCfg.Add(cfg.IdolName, cfg);
                MessageBox.Show(cfg.IdolName + " 信息配置成功", "成功");
            }
            roomid = "";
        }
示例#11
0
        private void btn_proxyapply_Click(object sender, EventArgs e)
        {
            if (txt_proxy.Text == "")
            {
                MessageBox.Show("即将进行代理关闭操作,如果是误操作,请自行再次查找代理");
                PocketPlugins.Proxy = null;
                foreach (string key in PocketPlugins.RunTimeCfg.Keys)
                {
                    ListenRunTimeConfig cfg = (ListenRunTimeConfig)PocketPlugins.RunTimeCfg[key];
                    cfg.Proxy = null;
                }
                MessageBox.Show("更换完成,请留意监听情况和酷Q日志");
                return;
            }

            if (!txt_proxy.Text.Contains(":"))
            {
                MessageBox.Show("大兄弟,不知道用别乱折腾了,欢迎捐助!");
                return;
            }
            string      fullProxy = txt_proxy.Text;
            PocketProxy proxy     = new PocketProxy();

            proxy.FullIP = fullProxy;
            string[] info = fullProxy.Split(':');
            proxy.IP       = info[0];
            proxy.Port     = info[1];
            proxy.UseProxy = true;

            if (roomid == "")
            {
                MessageBox.Show("由于有自动化测试需要,请先随机查找一个成员后再应用", "错误");
                return;
            }
            string json = Common.GetRoomMessage(proxy, PocketPlugins.User.PocketToken, roomid);

            if (json == "")
            {
                MessageBox.Show("代理不可用,换一个吧", "错误");
            }
            try
            {
                JObject obj = JObject.Parse(json);
                if ((int)obj["status"] != 200)
                {
                    MessageBox.Show("可能有问题,建议更换");
                }
                else
                {
                    MessageBox.Show("代理可用,即将开始更换代理");
                    PocketPlugins.Proxy = proxy;
                    foreach (string key in PocketPlugins.RunTimeCfg.Keys)
                    {
                        ListenRunTimeConfig cfg = (ListenRunTimeConfig)PocketPlugins.RunTimeCfg[key];
                        cfg.Proxy = proxy;
                    }
                    MessageBox.Show("更换完成,请留意监听情况和酷Q日志");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("代理不可用,换一个吧", "错误");
            }
        }
示例#12
0
        private void btn_loadconfig_Click(object sender, EventArgs e)
        {
            if (!File.Exists("PocketConfig.json"))
            {
                MessageBox.Show("配置文件不存在!请检查文件名是否正确", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string  json    = File.ReadAllText("PocketConfig.json");
            JObject jsonObj = JObject.Parse(json);

            if (jsonObj.Property("User") != null)
            {
                PocketPlugins.User = JsonConvert.DeserializeObject <UserInfo>(jsonObj["User"].ToString());
                txt_phone.Text     = PocketPlugins.User.UserName;
                lab_token.Text     = string.Format("Token:{0}  Token更新时间:{1}", PocketPlugins.User.PocketToken, PocketPlugins.User.TokenUpdate.ToString());
            }

            if (jsonObj.Property("IMEI") != null)
            {
                PocketSetting.IMEI = jsonObj["IMEI"].ToString();
                txt_imei.Text      = PocketSetting.IMEI;
            }

            /*
             * if (jsonObj.Property("LiveDelay") != null)
             * {
             *  txt_livedelay.Text = jsonObj["LiveDelay"].ToString();
             *  PocketPlugins.CommonCfg.LiveDelay = int.Parse(jsonObj["LiveDelay"].ToString());
             * }*/


            if (jsonObj.Property("CoolQAir") != null)
            {
                bool Air = bool.Parse(jsonObj["CoolQAir"].ToString());
                if (Air)
                {
                    rb_air.Checked = true;
                    PocketPlugins.CommonCfg.CoolQAir = true;
                }
                else
                {
                    rb_pro.Checked = true;
                    PocketPlugins.CommonCfg.CoolQAir = false;
                }
            }

            if (jsonObj.Property("IdolInfo") != null)
            {
                foreach (JObject idol in jsonObj["IdolInfo"])
                {
                    ListenRunTimeConfig config = JsonConvert.DeserializeObject <ListenRunTimeConfig>(idol.ToString());
                    if (PocketPlugins.RunTimeCfg.ContainsKey(config.IdolName))
                    {
                        continue;
                    }
                    config.First = true;
                    PocketPlugins.RunTimeCfg.Add(config.IdolName, config);
                    list_listen.Items.Add(config);
                }
                list_listen.DisplayMember = "IdolName";
            }
            MessageBox.Show("加载完成", "成功");
        }
        private static void ProcessRoomMessage(string json, ListenRunTimeConfig config)
        {
            try
            {
                JObject obj = JObject.Parse(json);
                if ((int)obj["status"] == 200)
                {
                    IEnumerable <JToken> datas = obj.SelectTokens("$.content.data[*]");
                    long     tmpTime           = 0;
                    DateTime msgTime           = new DateTime(1996, 9, 10);

                    foreach (JToken msgs in datas)
                    {
                        //本次消息时间
                        if ((long)msgs["msgTime"] >= tmpTime)
                        {
                            tmpTime = (long)msgs["msgTime"];
                            msgTime = DateTime.Parse(msgs["msgTimeStr"].ToString());
                        }
                        JObject msg = JObject.Parse(msgs["extInfo"].ToString());

                        //长短时切换~
                        DateTime now      = DateTime.Now;
                        TimeSpan interval = now - msgTime;
                        config.Delay = interval.TotalSeconds > PocketSetting.Interval ? config.LongDelay : config.ShortDelay;
                        //首次运行,直接退出循环
                        if (config.First)
                        {
                            break;
                        }

                        //时间戳相等说明已经发过了,直接退出
                        if ((long)msgs["msgTime"] <= config.LastTime)
                        {
                            continue;
                        }

                        //消息分发
                        switch (msg["messageObject"].ToString())
                        {
                        case "deleteMessage":
                            //CQ.SendGroupMessage(qqGroup,"你的小偶像删除了一条口袋房间的消息");
                            break;

                        case "text":
                            if (config.TransmitText)
                            {
                                foreach (long qqGroup in config.QQGroups)
                                {
                                    PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), msg["text"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString()));
                                }
                            }
                            break;

                        case "image":
                            JObject img         = JObject.Parse(msgs["bodys"].ToString());
                            string  imgFilename = GetImage(img["url"].ToString());
                            if (imgFilename == "")
                            {
                                continue;
                            }
                            if (config.TransmitImage)
                            {
                                foreach (long qqGroup in config.QQGroups)
                                {
                                    if (PocketPlugins.CommonCfg.CoolQAir)
                                    {
                                        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n发送了图片:{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), img["url"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString()));
                                    }
                                    else
                                    {
                                        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), CoolQCode.Image(imgFilename), config.IdolName, msgs["msgTimeStr"].ToString()));
                                    }
                                }
                            }
                            break;

                        case "faipaiText":
                            if (config.TransmitFanpai)
                            {
                                foreach (long qqGroup in config.QQGroups)
                                {
                                    if (msg.Property("fanpaiName") != null)
                                    {
                                        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{4}\r\n{0} 回复:{1}\r\n来源:{5}房间 发送时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), msgs["msgTimeStr"].ToString(), "", msg["faipaiContent"].ToString(), config.IdolName));
                                    }
                                    else
                                    {
                                        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{4}\r\n{0} 回复:{1}\r\n来源:{5}房间 发送时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), msgs["msgTimeStr"].ToString(), "", msg["faipaiContent"].ToString(), config.IdolName));
                                    }
                                }
                            }
                            break;

                        case "audio":
                            JObject audio         = JObject.Parse(msgs["bodys"].ToString());
                            string  audioFilename = GetAudio(audio["url"].ToString(), audio["ext"].ToString());
                            if (audioFilename == "")
                            {
                                continue;
                            }
                            if (config.TransmitAudio)
                            {
                                foreach (long qqGroup in config.QQGroups)
                                {
                                    if (PocketPlugins.CommonCfg.CoolQAir)
                                    {
                                        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n发送了语音:{1} 来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), audio["url"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString()));
                                    }
                                    else
                                    {
                                        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}", CoolQCode.ShareRecord(audioFilename)));
                                    }
                                    //PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n{1} 来源:口袋房间", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename)));
                                }
                            }

                            break;

                        case "videoRecord":
                            JObject video = JObject.Parse(msgs["bodys"].ToString());
                            if (config.TransmitVideo)
                            {
                                foreach (long qqGroup in config.QQGroups)
                                {
                                    PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}发送了一个视频,请点击下面链接查看\r\n地址:{1}", msg["senderName"].ToString(), video["url"].ToString()));
                                }
                            }
                            break;

                        case "jujuLive":
                            if (config.TransmitGift)
                            {
                                foreach (long qqGroup in config.QQGroups)
                                {
                                    PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), msg["text"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString()));
                                }
                            }
                            break;

                        case "live":
                            if (config.TransmitLive)
                            {
                                foreach (long qqGroup in config.QQGroups)
                                {
                                    PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("滴滴滴,你的小偶像{0}开直播辣!\r\n使用口袋PC观看体验更好哦!\r\n或登录网页收看https://h5.48.cn/2017appshare/memberLiveShare/index.html?id={1}", config.IdolName, msg["referenceObjectId"].ToString()));
                                }
                            }
                            break;

                        case "diantai":
                            if (config.TransmitLive)
                            {
                                foreach (long qqGroup in config.QQGroups)
                                {
                                    PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("滴滴滴,你的小偶像{0}开电台辣!\r\n使用口袋PC观看体验更好哦!\r\n或登录网页收看https://h5.48.cn/2017appshare/memberLiveShare/index.html?id={1}", config.IdolName, msg["referenceObjectId"].ToString()));
                                }
                            }
                            break;

                        case "idolFlip":
                            if (config.TransmitFlip)
                            {
                                foreach (long qqGroup in config.QQGroups)
                                {
                                    if (int.Parse(msg["idolFlipType"].ToString()) == 3)
                                    {
                                        PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}回答了匿名聚聚的提问:\r\n{1}\r\n回答请进入房间查看", msg["senderName"].ToString(), msg["idolFlipContent"].ToString()));
                                    }
                                    else
                                    {
                                        PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}回答了{2}的提问:\r\n{1}\r\n回答请进入房间查看", msg["senderName"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString()));
                                    }
                                }
                            }
                            break;
                        }
                    }
                    if (tmpTime != 0)
                    {
                        config.LastTime = tmpTime;
                    }
                }
                if (config.First)
                {
                    config.First = false;
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex);
            }
        }
        public override int Enabled()
        {
            if (!File.Exists("PocketConfig.json"))
            {
                PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "配置文件不存在!如设置自启动不会生效,请打开面板设置之后保存启动。");
            }
            else
            {
                string  json    = File.ReadAllText("PocketConfig.json");
                JObject jsonObj = JObject.Parse(json);



                if (jsonObj.Property("IMEI") != null)
                {
                    PocketSetting.IMEI = jsonObj["IMEI"].ToString();
                }

                string username = jsonObj["User"]["UserName"].ToString();
                string password = jsonObj["User"]["PassWord"].ToString();
                string IMEI     = jsonObj["IMEI"].ToString();

                string jsontoken = Common.GetUserInfo(username, password, IMEI);
                //PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "获取TOKEN。");
                JObject obj = JObject.Parse(jsontoken);
                if ((int)obj["status"] == 200)
                {
                    jsonObj["User"]["PocketToken"] = obj["content"]["token"].ToString();
                    PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "获取TOKEN成功");
                    File.WriteAllText("PocketConfig.json", jsonObj.ToString());
                    if (jsonObj.Property("AutoStart") != null)
                    {
                        if (Convert.ToBoolean(jsonObj["AutoStart"]) == true)
                        {
                            json    = File.ReadAllText("PocketConfig.json");
                            jsonObj = JObject.Parse(json);

                            if (jsonObj.Property("User") != null)
                            {
                                PocketPlugins.User = JsonConvert.DeserializeObject <UserInfo>(jsonObj["User"].ToString());
                            }

                            if (jsonObj.Property("IMEI") != null)
                            {
                                PocketSetting.IMEI = jsonObj["IMEI"].ToString();
                            }

                            /*
                             * if (jsonObj.Property("LiveDelay") != null)
                             * {
                             *  txt_livedelay.Text = jsonObj["LiveDelay"].ToString();
                             *  PocketPlugins.CommonCfg.LiveDelay = int.Parse(jsonObj["LiveDelay"].ToString());
                             * }*/


                            if (jsonObj.Property("CoolQAir") != null)
                            {
                                bool Air = bool.Parse(jsonObj["CoolQAir"].ToString());
                                if (Air)
                                {
                                    PocketPlugins.CommonCfg.CoolQAir = true;
                                }
                                else
                                {
                                    PocketPlugins.CommonCfg.CoolQAir = false;
                                }
                            }

                            if (jsonObj.Property("IdolInfo") != null)
                            {
                                foreach (JObject idol in jsonObj["IdolInfo"])
                                {
                                    ListenRunTimeConfig config = JsonConvert.DeserializeObject <ListenRunTimeConfig>(idol.ToString());
                                    if (PocketPlugins.RunTimeCfg.ContainsKey(config.IdolName))
                                    {
                                        continue;
                                    }
                                    config.First = true;
                                    PocketPlugins.RunTimeCfg.Add(config.IdolName, config);
                                }
                            }

                            int timedelay = 0;
                            foreach (var idol in PocketPlugins.RunTimeCfg.Keys)
                            {
                                Common.StartListenRoomTask(idol.ToString(), timedelay);
                                timedelay = timedelay + 5000;
                            }
                        }
                        else
                        {
                            PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "配置为非自行启动,仅更新TOKEN");
                        }
                    }
                }
                else
                {
                    PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "获取TOKEN失败,请打开面板检查账号密码配置");
                }
            }

            return(base.Enabled());
        }
示例#15
0
        private static void ProcessRoomMessage(string json, ListenRunTimeConfig config)
        {
            try
            {
                JObject obj = JObject.Parse(json);
                if ((int)obj["status"] == 200)
                {
                    IEnumerable <JToken> datas = obj.SelectTokens("$.content.data[*]");
                    long     tmpTime           = 0;
                    DateTime msgTime           = new DateTime(1996, 9, 10);
                    string   totalTempMsg      = "";
                    string   templeMsgTime     = "";
                    int      sort = 1;
                    foreach (JToken msgs in datas)
                    {
                        msgTime = DateTime.Parse(msgs["msgTimeStr"].ToString());
                        //★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
                        JObject  msg           = JObject.Parse(msgs["extInfo"].ToString());
                        string[] realtime      = msgs["msgTimeStr"].ToString().Split(' ');
                        string[] idolnamewords = msg["senderName"].ToString().Split('-');
                        string   idolname      = idolnamewords[idolnamewords.Length - 1];
                        string   roomrecentmsg = "";
                        DateTime dt            = new DateTime(1970, 1, 1, 8, 0, 0).AddMilliseconds(((Convert.ToDouble(config.LastTime))));
                        if (sort == 1)                             //处理第一条消息的逻辑
                        {
                            tmpTime       = (long)msgs["msgTime"]; //最后一次的第一条时间
                            templeMsgTime = realtime[1];
                            //首次消息日志开始
                            if (PocketPlugins.CommonCfg.msglog == true)
                            {
                                //PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "true");
                                try
                                {
                                    switch (msg["messageObject"].ToString())
                                    {
                                    case "deleteMessage":
                                        roomrecentmsg = "你的小偶像删除了一条消息";
                                        break;

                                    case "text":
                                        if (config.TransmitText)
                                        {
                                            roomrecentmsg = String.Format("{0}:{1}", idolname, msg["text"].ToString());
                                        }
                                        break;

                                    case "image":
                                        JObject img = JObject.Parse(msgs["bodys"].ToString());
                                        if (config.TransmitImage)
                                        {
                                            roomrecentmsg = String.Format("{0}:\r\n发送图片:{1}", idolname, img["url"].ToString());
                                        }
                                        break;

                                    case "faipaiText":
                                        if (config.TransmitFanpai)
                                        {
                                            if (msg.Property("fanpaiName") != null)
                                            {
                                                roomrecentmsg = String.Format("{2} : {3}\r\n{0} 回复 : {1}", idolname, msg["messageText"].ToString(), msg["fanpaiName"].ToString(), msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg;
                                            }
                                            else
                                            {
                                                JObject Name = JObject.Parse(GetUserName(msg["faipaiUserId"].ToString()));
                                                roomrecentmsg = String.Format("{2} : {3}\r\n{0} 回复 : {1}", idolname, msg["messageText"].ToString(), Name["nickName"].ToString(), msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg;
                                            }
                                        }
                                        break;

                                    case "audio":
                                        JObject audio         = JObject.Parse(msgs["bodys"].ToString());
                                        string  audioFilename = GetAudio(audio["url"].ToString(), audio["ext"].ToString());
                                        if (audioFilename == "")
                                        {
                                            continue;
                                        }
                                        if (config.TransmitAudio)
                                        {
                                            roomrecentmsg = String.Format("{0}:\r\n发送语音:{1}", idolname, audio["url"].ToString());
                                        }
                                        break;

                                    case "videoRecord":
                                        JObject video = JObject.Parse(msgs["bodys"].ToString());
                                        if (config.TransmitVideo)
                                        {
                                            roomrecentmsg = string.Format("{0}发送视频。\r\n地址:{1}\r\n", idolname, video["url"].ToString());
                                        }
                                        break;

                                    case "jujuLive":
                                        if (config.TransmitGift)
                                        {
                                            roomrecentmsg = string.Format("{0}{1}", idolname, msg["text"].ToString());
                                        }
                                        break;

                                    case "live":
                                        roomrecentmsg = string.Format("直播提醒:你的小心肝{0}的直播:{1}!\r\n请打开口袋48观看哟!设置关注词(直播提醒)不错过直播哦!", idolname, msg["referenceContent"].ToString());
                                        break;

                                    case "diantai":
                                        if (config.TransmitLive)
                                        {
                                            roomrecentmsg = string.Format("直播提醒:你的小心肝{0}突然开了个电台:{1}!\r\n快打开口袋48观看哟!设置关注词(直播提醒)不错过直播哦!", idolname, msg["referenceContent"].ToString());
                                        }
                                        break;

                                    case "idolFlip":
                                        if (config.TransmitFlip)
                                        {
                                            //}
                                            if (int.Parse(msg["idolFlipType"].ToString()) == 3)
                                            {
                                                roomrecentmsg = string.Format("{0} {1}:\r\n{2}", idolname, msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString());
                                            }
                                            else
                                            {
                                                roomrecentmsg = string.Format("{0} 回答 {3} 的提问:\r\n{2}", idolname, msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString());
                                            }
                                        }
                                        break;

                                    default:
                                        File.AppendAllText("unknowmsg.log", msgs.ToString() + "\r\n");
                                        roomrecentmsg = "未知类型消息,请检查unknowmsg.log";
                                        break;
                                    }
                                    PocketPlugins.Api.AddLog(10, CoolQLogLevel.Debug, config.LastTime.ToString() + " " + msgs["msgTime"].ToString());
                                    roomrecentmsg = "上次最晚时间:" + dt.ToString() + " 本次最新时间:" + msgs["msgTimeStr"].ToString() + "\r\n" + config.IdolName + "房间:(调试信息,勾选取消可去除本消息。仅供调试测试查看\r\n" + roomrecentmsg;
                                    PocketPlugins.Api.AddLog(10, CoolQLogLevel.Debug, roomrecentmsg);
                                    //panel.textBox_recentmsg.Text = roomrecentmsg;
                                }
                                catch (Exception ex)
                                {
                                    PocketPlugins.Api.AddLog(10, CoolQLogLevel.Debug, ex.ToString());
                                }
                            }
//                            else
//                                PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "false");

                            //else
                            //PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "false");

                            //首次消息日志结束
                        }
                        sort++;
                        //长短时切换~
                        DateTime now      = DateTime.Now;
                        TimeSpan interval = now - msgTime;
                        config.Delay = interval.TotalSeconds > PocketSetting.Interval ? config.LongDelay : config.ShortDelay;
                        //首次运行,直接退出循环
                        if (config.First)
                        {
                            //PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, string.Format("[{0}]任务启动", IdolName));
                            config.LastTime = tmpTime;
                            dt = new DateTime(1970, 1, 1, 8, 0, 0).AddMilliseconds(((Convert.ToDouble(config.LastTime))));
                            PocketPlugins.Api.AddLog(10, CoolQLogLevel.Debug, config.IdolName + " 初始化结束,最新一条消息时间为:" + config.LastTime.ToString() + " " + dt.ToString());
                            break;
                        }


                        //时间戳相等说明已经发过了,直接退出
                        if ((long)msgs["msgTime"] <= config.LastTime)
                        {
                            //continue;
                            config.LastTime = tmpTime;
                            break;//一旦小于时间直接终止遍历,赋值最后一次时间。
                        }

                        //消息分发
                        switch (msg["messageObject"].ToString())
                        {
                        case "deleteMessage":
                            totalTempMsg = "你的小偶像删除了一条消息" + "\r\n" + totalTempMsg;
                            //CQ.SendGroupMessage(qqGroup,"你的小偶像删除了一条口袋房间的消息");
                            break;

                        case "text":
                            if (config.TransmitText)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //   PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), msg["text"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString()));
                                //}
                                if (config.IdolName != msg["senderName"].ToString())
                                {
                                    //totalTempMsg = String.Format("{0}:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["text"].ToString(), realtime[1]) + "\r\n" + totalTempMsg;
                                    totalTempMsg = String.Format("{0}:{1}", idolname, msg["text"].ToString()) + "\r\n" + totalTempMsg;
                                }
                                else
                                {
                                    //totalTempMsg = String.Format("{0}:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["text"].ToString(), realtime[1]) + "\r\n" + totalTempMsg;
                                    totalTempMsg = String.Format("{0}:{1}", idolname, msg["text"].ToString()) + "\r\n" + totalTempMsg;
                                }
                            }
                            break;

                        case "image":
                            JObject img         = JObject.Parse(msgs["bodys"].ToString());
                            string  imgFilename = GetImage(img["url"].ToString());
                            if (imgFilename == "")
                            {
                                continue;
                            }
                            if (config.TransmitImage)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //    if (PocketPlugins.CommonCfg.CoolQAir)
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n发送了图片:{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), img["url"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString()));
                                //    else
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), CoolQCode.Image(imgFilename), config.IdolName, msgs["msgTimeStr"].ToString()));
                                //}
                                if (PocketPlugins.CommonCfg.CoolQAir)
                                {
                                    //totalTempMsg = String.Format("{0}:\r\n发送图片:{1}\r\n时间:{2}", msg["senderName"].ToString(), img["url"].ToString(), realtime[1]) + "\r\n" + totalTempMsg;
                                    totalTempMsg = String.Format("{0}:\r\n发送图片:{1}", idolname, img["url"].ToString()) + "\r\n" + totalTempMsg;
                                }
                                else
                                {
                                    //totalTempMsg = String.Format("{0}:\r\n{1}\r\n时间:{2}", msg["senderName"].ToString(), CoolQCode.Image(imgFilename), realtime[1]) + "\r\n" + totalTempMsg;
                                    totalTempMsg = String.Format("{0}:\r\n{1}", idolname, CoolQCode.Image(imgFilename)) + "\r\n" + totalTempMsg;
                                }
                            }
                            break;

                        case "faipaiText":
                            if (config.TransmitFanpai)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //    if(msg.Property("fanpaiName") != null)
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{4}\r\n{0} 回复:{1}\r\n来源:{5}房间 发送时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), msgs["msgTimeStr"].ToString(), "", msg["faipaiContent"].ToString(), config.IdolName));
                                //    else
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{4}\r\n{0} 回复:{1}\r\n来源:{5}房间 发送时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), msgs["msgTimeStr"].ToString(), "", msg["faipaiContent"].ToString(), config.IdolName));
                                // }
                                JObject Name = JObject.Parse(GetUserName(msg["faipaiUserId"].ToString()));
//                                    PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, string.Format("[{0}]任务已经存在,退出", IdolName));
                                if (msg.Property("fanpaiName") != null)
                                {
                                    //totalTempMsg = String.Format("{3} : {4}\r\n{0} 回复:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), realtime[1], msg["fanpaiName"].ToString(), msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg;
                                    totalTempMsg = String.Format("{2} : {3}\r\n{0} 回复 : {1}", idolname, msg["messageText"].ToString(), msg["fanpaiName"].ToString(), msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg;
                                }
                                else
                                {
                                    //totalTempMsg = String.Format("{3} : {4}\r\n{0} 回复:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), Name["nickName"], msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg;
                                    totalTempMsg = String.Format("{2} : {3}\r\n{0} 回复 : {1}", idolname, msg["messageText"].ToString(), Name["nickName"].ToString(), msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg;
                                }
                            }
                            break;

                        case "audio":
                            JObject audio         = JObject.Parse(msgs["bodys"].ToString());
                            string  audioFilename = GetAudio(audio["url"].ToString(), audio["ext"].ToString());
                            if (audioFilename == "")
                            {
                                continue;
                            }
                            if (config.TransmitAudio)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //   if (PocketPlugins.CommonCfg.CoolQAir)
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n发送了语音:{1} 来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), audio["url"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString()));
                                //    else
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}", CoolQCode.ShareRecord(audioFilename)));
                                //        //PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n{1} 来源:口袋房间", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename)));
                                //}
                                if (PocketPlugins.CommonCfg.CoolQAir)
                                {
                                    //totalTempMsg = String.Format("{0}:\r\n发送语音:{1}\r\n时间:{2}", msg["senderName"].ToString(), audio["url"].ToString(), realtime[1]) + "\r\n" + totalTempMsg;
                                    totalTempMsg = String.Format("{0}:\r\n发送语音:{1}", idolname, audio["url"].ToString()) + "\r\n" + totalTempMsg;
                                }
                                else
                                {
                                    //totalTempMsg = String.Format("{0}:\r\n{1}", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename)) + "\r\n" + totalTempMsg;
                                    //totalTempMsg = String.Format("{0}:\r\n{1}\r\n时间:{2}", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename), realtime[1]) + "\r\n" + totalTempMsg;
                                    totalTempMsg = String.Format("{0}:\r\n{1}", idolname, CoolQCode.ShareRecord(audioFilename)) + "\r\n" + totalTempMsg;
                                }
                            }

                            break;

                        case "videoRecord":
                            JObject video = JObject.Parse(msgs["bodys"].ToString());
                            if (config.TransmitVideo)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //    PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}发送了一个视频,请点击下面链接查看\r\n地址:{1}", msg["senderName"].ToString(), video["url"].ToString()));
                                //}
                                totalTempMsg = string.Format("{0}发送视频。\r\n地址:{1}\r\n", idolname, video["url"].ToString()) + "\r\n" + totalTempMsg;
                            }
                            break;

                        case "jujuLive":
                            if (config.TransmitGift)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //    PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), msg["text"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString()));
                                //}
                                //totalTempMsg = string.Format("{0}{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["text"].ToString(), realtime[1]) + "\r\n" + totalTempMsg;
                                totalTempMsg = string.Format("{0}{1}", idolname, msg["text"].ToString()) + "\r\n" + totalTempMsg;
                            }
                            break;

                        case "live":
                            if (config.TransmitLive)
                            {
                                if (config.Atall && !PocketPlugins.CommonCfg.CoolQAir)
                                {
                                    totalTempMsg = string.Format("[CQ:at,qq=all]直播提醒:你的小心肝{0}的直播:{1}!\r\n请打开口袋48观看哟!设置关注词(直播提醒)不错过直播哦!", idolname, msg["referenceContent"].ToString()) + "\r\n" + totalTempMsg;
                                }
                                else
                                {
                                    totalTempMsg = string.Format("直播提醒:你的小心肝{0}的直播:{1}!\r\n请打开口袋48观看哟!设置关注词(直播提醒)不错过直播哦!", idolname, msg["referenceContent"].ToString()) + "\r\n" + totalTempMsg;
                                }
                            }
                            break;

                        case "diantai":
                            if (config.TransmitLive)
                            {
                                if (config.Atall && !PocketPlugins.CommonCfg.CoolQAir)
                                {
                                    totalTempMsg = string.Format("[CQ:at,qq=all]直播提醒:你的小心肝{0}的电台:{1}!\r\n快打开口袋48观看哟!设置关注词(直播提醒)不错过直播哦!", idolname, msg["referenceContent"].ToString()) + "\r\n" + totalTempMsg;
                                }
                                else
                                {
                                    totalTempMsg = string.Format("直播提醒:你的小心肝{0}的电台:{1}!\r\n快打开口袋48观看哟!设置关注词(直播提醒)不错过直播哦!", idolname, msg["referenceContent"].ToString()) + "\r\n" + totalTempMsg;
                                }
                            }
                            break;

                        case "idolFlip":
                            if (config.TransmitFlip)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //    if (int.Parse(msg["idolFlipType"].ToString()) == 3)
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}回答了匿名聚聚的提问:\r\n{1}\r\n回答请进入房间查看", msg["senderName"].ToString(), msg["idolFlipContent"].ToString()));
                                //    else
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}回答了{2}的提问:\r\n{1}\r\n回答请进入房间查看", msg["senderName"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString()));
                                //}

                                if (int.Parse(msg["idolFlipType"].ToString()) == 3)
                                {
                                    //totalTempMsg = string.Format("{0} {1}:\r\n{2}\r\n时间:{3}", msg["senderName"].ToString(), msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString(), realtime[1]) + "\r\n" + totalTempMsg;
                                    totalTempMsg = string.Format("{0} {1}:\r\n{2}", idolname, msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString()) + "\r\n" + totalTempMsg;
                                }
                                else
                                {
                                    //totalTempMsg = string.Format("{0} 回答 {3} 的提问:\r\n{2}\r\n时间:{4}", msg["senderName"].ToString(), msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString(),realtime[1]) + "\r\n" + totalTempMsg;
                                    totalTempMsg = string.Format("{0} 回答 {3} 的提问:\r\n{2}", idolname, msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString()) + "\r\n" + totalTempMsg;
                                }
                            }
                            break;

                        default:
                            File.AppendAllText("msg.log", msgs.ToString() + "\r\n");
                            break;
                        }
                    }
                    if (totalTempMsg != "")
                    {
                        totalTempMsg = templeMsgTime + "" + config.IdolName + "房间:\r\n" + totalTempMsg;
                        totalTempMsg = totalTempMsg.Substring(0, totalTempMsg.Length - 2);
                        foreach (long qqGroup in config.QQGroups)
                        {
                            Common.sendgroupmsgChose(qqGroup, totalTempMsg);
                        }

                        if (PocketPlugins.Api.GetLoginQQ() == 2893276319)
                        {
                            totalTempMsg = totalTempMsg.Replace("[CQ:at,qq=all]", "");
                            PocketPlugins.Api.SendPrivateMsg(1691686998, totalTempMsg);
                        }
                    }
                }
                if (config.First)
                {
                    config.First = false;
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex);
            }
        }
示例#16
0
        private static void ProcessRoomMessage(string json, ListenRunTimeConfig config)
        {
            try
            {
                JObject obj = JObject.Parse(json);
                if ((int)obj["status"] == 200)
                {
                    IEnumerable <JToken> datas = obj.SelectTokens("$.content.data[*]");
                    long     tmpTime           = 0;
                    DateTime msgTime           = new DateTime(1996, 9, 10);
                    string   totalTempMsg      = "";
                    foreach (JToken msgs in datas)
                    {
                        //本次消息时间
                        if ((long)msgs["msgTime"] >= tmpTime)
                        {
                            tmpTime = (long)msgs["msgTime"];
                            msgTime = DateTime.Parse(msgs["msgTimeStr"].ToString());
                        }
                        JObject msg = JObject.Parse(msgs["extInfo"].ToString());

                        //长短时切换~
                        DateTime now      = DateTime.Now;
                        TimeSpan interval = now - msgTime;
                        config.Delay = interval.TotalSeconds > PocketSetting.Interval ? config.LongDelay : config.ShortDelay;
                        //首次运行,直接退出循环
                        if (config.First)
                        {
                            break;
                        }

                        //时间戳相等说明已经发过了,直接退出
                        if ((long)msgs["msgTime"] <= config.LastTime)
                        {
                            continue;
                        }

                        string[] realtime = msgs["msgTimeStr"].ToString().Split(' ');
                        //消息分发
                        switch (msg["messageObject"].ToString())
                        {
                        case "deleteMessage":
                            totalTempMsg = "你的小偶像删除了一条消息" + "\r\n" + totalTempMsg;
                            //CQ.SendGroupMessage(qqGroup,"你的小偶像删除了一条口袋房间的消息");
                            break;

                        case "text":
                            if (config.TransmitText)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //   PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), msg["text"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString()));
                                //}
                                if (config.IdolName != msg["senderName"].ToString())
                                {
                                    totalTempMsg = String.Format("{0}:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["text"].ToString(), realtime[1]) + "\r\n" + totalTempMsg;
                                }
                                else
                                {
                                    totalTempMsg = String.Format("{0}:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["text"].ToString(), realtime[1]) + "\r\n" + totalTempMsg;
                                }
                            }
                            break;

                        case "image":
                            JObject img         = JObject.Parse(msgs["bodys"].ToString());
                            string  imgFilename = GetImage(img["url"].ToString());
                            if (imgFilename == "")
                            {
                                continue;
                            }
                            if (config.TransmitImage)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //    if (PocketPlugins.CommonCfg.CoolQAir)
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n发送了图片:{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), img["url"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString()));
                                //    else
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), CoolQCode.Image(imgFilename), config.IdolName, msgs["msgTimeStr"].ToString()));
                                //}
                                if (PocketPlugins.CommonCfg.CoolQAir)
                                {
                                    totalTempMsg = String.Format("{0}:\r\n发送图片:{1}\r\n时间:{2}", msg["senderName"].ToString(), img["url"].ToString(), realtime[1]) + "\r\n" + totalTempMsg;
                                }
                                else
                                {
                                    totalTempMsg = String.Format("{0}:\r\n{1}\r\n时间:{2}", msg["senderName"].ToString(), CoolQCode.Image(imgFilename), realtime[1]) + "\r\n" + totalTempMsg;
                                }
                            }
                            break;

                        case "faipaiText":
                            if (config.TransmitFanpai)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //    if(msg.Property("fanpaiName") != null)
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{4}\r\n{0} 回复:{1}\r\n来源:{5}房间 发送时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), msgs["msgTimeStr"].ToString(), "", msg["faipaiContent"].ToString(), config.IdolName));
                                //    else
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{4}\r\n{0} 回复:{1}\r\n来源:{5}房间 发送时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), msgs["msgTimeStr"].ToString(), "", msg["faipaiContent"].ToString(), config.IdolName));
                                // }
                                JObject Name = JObject.Parse(GetUserName(msg["faipaiUserId"].ToString()));
//                                    PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, string.Format("[{0}]任务已经存在,退出", IdolName));
                                if (msg.Property("fanpaiName") != null)
                                {
                                    totalTempMsg = String.Format("{3} : {4}\r\n{0} 回复:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), realtime[1], msg["fanpaiName"].ToString(), msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg;
                                }
                                else
                                {
                                    totalTempMsg = String.Format("{3} : {4}\r\n{0} 回复:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), realtime[1], Name["nickName"], msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg;
                                }
                            }
                            break;

                        case "audio":
                            JObject audio         = JObject.Parse(msgs["bodys"].ToString());
                            string  audioFilename = GetAudio(audio["url"].ToString(), audio["ext"].ToString());
                            if (audioFilename == "")
                            {
                                continue;
                            }
                            if (config.TransmitAudio)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //   if (PocketPlugins.CommonCfg.CoolQAir)
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n发送了语音:{1} 来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), audio["url"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString()));
                                //    else
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}", CoolQCode.ShareRecord(audioFilename)));
                                //        //PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n{1} 来源:口袋房间", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename)));
                                //}
                                if (PocketPlugins.CommonCfg.CoolQAir)
                                {
                                    totalTempMsg = String.Format("{0}:\r\n发送语音:{1}\r\n时间:{2}", msg["senderName"].ToString(), audio["url"].ToString(), realtime[1]) + "\r\n" + totalTempMsg;
                                }
                                else
                                {
                                    //totalTempMsg = String.Format("{0}:\r\n{1}", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename)) + "\r\n" + totalTempMsg;
                                    totalTempMsg = String.Format("{0}:\r\n{1}\r\n时间:{2}", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename), realtime[1]) + "\r\n" + totalTempMsg;
                                }
                            }

                            break;

                        case "videoRecord":
                            JObject video = JObject.Parse(msgs["bodys"].ToString());
                            if (config.TransmitVideo)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //    PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}发送了一个视频,请点击下面链接查看\r\n地址:{1}", msg["senderName"].ToString(), video["url"].ToString()));
                                //}
                                totalTempMsg = string.Format("{0}发送视频。\r\n地址:{1}\r\n", msg["senderName"].ToString(), video["url"].ToString()) + "\r\n" + totalTempMsg;
                            }
                            break;

                        case "jujuLive":
                            if (config.TransmitGift)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //    PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), msg["text"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString()));
                                //}
                                totalTempMsg = string.Format("{0}{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["text"].ToString(), realtime[1]) + "\r\n" + totalTempMsg;
                            }
                            break;

                        case "live":
                            if (config.TransmitLive)
                            {
                                foreach (long qqGroup in config.QQGroups)
                                {
                                    //PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("直播提醒:你的小心肝{0}突然开了个直播,直播哦不是电台!\r\n请打开口袋48观看哟!设置关键词关注“直播提醒”不错过直播哦!", config.IdolName, msg["referenceObjectId"].ToString()));
                                    PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("直播提醒:你的小心肝{0}突然开了个直播,直播哦不是电台!\r\n请打开口袋48观看哟!设置关键词关注“直播提醒”不错过直播哦!", config.IdolName));
                                }
                            }
                            break;

                        case "diantai":
                            if (config.TransmitLive)
                            {
                                foreach (long qqGroup in config.QQGroups)
                                {
                                    //PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("直播提醒:你的小心肝{0}突然开了个电台,电台哦不是直播!\r\n请打开口袋48观看哟!设置关键词关注“直播提醒”不错过直播哦!", config.IdolName, msg["referenceObjectId"].ToString()));
                                    PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("直播提醒:你的小心肝{0}突然开了个电台,电台哦不是直播!\r\n请打开口袋48观看哟!设置关键词关注“直播提醒”不错过直播哦!", config.IdolName));
                                }
                            }
                            break;

                        case "idolFlip":
                            if (config.TransmitFlip)
                            {
                                //foreach (long qqGroup in config.QQGroups)
                                //{
                                //    if (int.Parse(msg["idolFlipType"].ToString()) == 3)
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}回答了匿名聚聚的提问:\r\n{1}\r\n回答请进入房间查看", msg["senderName"].ToString(), msg["idolFlipContent"].ToString()));
                                //    else
                                //        PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}回答了{2}的提问:\r\n{1}\r\n回答请进入房间查看", msg["senderName"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString()));
                                //}
                            }
                            if (int.Parse(msg["idolFlipType"].ToString()) == 3)
                            {
                                totalTempMsg = string.Format("{0} {1}:\r\n{2}\r\n时间:{3}", msg["senderName"].ToString(), msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString(), realtime[1]) + "\r\n" + totalTempMsg;
                            }
                            else
                            {
                                totalTempMsg = string.Format("{0} 翻牌了 {3} 的问题:\r\n{2}\r\n时间:{4}", msg["senderName"].ToString(), msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString(), realtime[1]) + "\r\n" + totalTempMsg;
                            }
                            break;

                        default:
                            File.AppendAllText("msg.log", msgs.ToString() + "\r\n");
                            break;
                        }
                    }
                    if (totalTempMsg != "")
                    {
                        totalTempMsg = config.IdolName + "口袋房间:\r\n" + totalTempMsg;
                        totalTempMsg = totalTempMsg.Substring(0, totalTempMsg.Length - 2);
                        foreach (long qqGroup in config.QQGroups)
                        {
                            PocketPlugins.Api.SendGroupMsg(qqGroup, totalTempMsg);
                        }

                        if (PocketPlugins.Api.GetLoginQQ() == 2893276319)
                        {
                            PocketPlugins.Api.SendPrivateMsg(1691686998, totalTempMsg);
                        }
                    }
                    if (tmpTime != 0)
                    {
                        config.LastTime = tmpTime;
                    }
                }
                if (config.First)
                {
                    config.First = false;
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex);
            }
        }