Пример #1
0
        public void OpenTwitterMonitor()
        {
            var function = new Action <TweeterMonitor, Tweet>(async delegate(TweeterMonitor sender, Tweet tweet)
            {
                var content = GetTweetContent(tweet);
                content.Insert(0, CQCode.CQText($"您监控的{sender.Mark}有新的推文了\n"));
                var sendConfig = _config.Items.Single(c => c.Mark.ToString() == sender.Mark);
                if (sendConfig.Group != null)
                {
                    foreach (var item in sendConfig.Group)
                    {
                        await _soraApi.SendGroupMessage(item, content);
                    }
                }

                if (sendConfig.Private != null)
                {
                    foreach (var item in sendConfig.Private)
                    {
                        await _soraApi.SendPrivateMessage(item, content);
                    }
                }
            });
            var     client  = new WebClient();
            Twitter twitter = new Twitter(ref client);

            foreach (var tw in _config.Items.Select(item => new TweeterMonitor(item.Mark.ToString(), twitter)
            {
                TimeInterval = 60
            }))
            {
                tw.NewTweetEvent += function;
                tw.Start();
            }
        }
Пример #2
0
 /// <summary>
 /// 没什么用的复读功能
 /// </summary>
 /// <returns>
 /// <para><see cref="ApiStatusType"/> API执行状态</para>
 /// <para><see langword="messageId"/> 发送消息的id</para>
 /// </returns>
 public async ValueTask <(ApiStatus apiStatus, int messageId)> Repeat()
 {
     return(await SoraApi.SendPrivateMessage(Sender.Id, Message.MessageBody));
 }
Пример #3
0
 /// <summary>
 /// 快速回复
 /// </summary>
 /// <param name="message">消息</param>
 /// <param name="timeout">覆盖原有超时</param>
 /// <returns>
 /// <para><see cref="ApiStatusType"/> API执行状态</para>
 /// <para><see langword="messageId"/> 发送消息的id</para>
 /// </returns>
 public async ValueTask <(ApiStatus apiStatus, int messageId)> Reply(
     MessageBody message, TimeSpan?timeout = null)
 {
     return(await SoraApi.SendPrivateMessage(Sender.Id, message, timeout));
 }
Пример #4
0
        /// <summary>
        /// 遍历动态循环
        /// </summary>
        public void Cycle(SoraApi api)
        {
            if (api == null)
            {
                return;
            }
            var    path = "config.json";
            string jsonString;

            using (System.IO.StreamReader file = System.IO.File.OpenText(path))
            {
                using (JsonTextReader reader = new JsonTextReader(file))
                {
                    JObject o = (JObject)JToken.ReadFrom(reader);
                    //遍历up
                    for (int i = 0; i < o["up"].Count(); i++)
                    {
                        var up = o["up"][i];
                        int id = 0;
                        int.TryParse(up["id"].ToString(), out id);
                        if (id > 0)
                        {
                            // 获取entity
                            var entity = moment.GetMoment(id).Result;
                            if (entity.feedList == null || entity.feedList.Length == 0)
                            {
                                continue;
                            }
                            var entity1 = entity.feedList.First();
                            //判断是否有更新
                            bool isUpdated = false;
                            try
                            {
                                isUpdated = (int.Parse(up["newmomentid"].ToString()) < int.Parse(entity1.moment.momentId));
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                            }
                            if (isUpdated)
                            {
                                long     uid = 0;
                                object[] msg = GetMessages(entity1);
                                //对每个提醒qq发送消息
                                foreach (var notifyqq in up["notifyqq"])
                                {
                                    long.TryParse(notifyqq.ToString(), out uid);
                                    if (uid > 0)
                                    {
                                        api.SendPrivateMessage(uid, msg);
                                    }
                                }
                                //对每个提醒qq群发送消息
                                foreach (var notifygroup in up["notifygroup"])
                                {
                                    long.TryParse(notifygroup.ToString(), out uid);
                                    if (uid > 0)
                                    {
                                        api.SendPrivateMessage(uid, msg);
                                    }
                                }
                                //回写entityid
                                o["up"][i]["newmomentid"] = entity1.moment.momentId;
                            }
                            //撤回消息
                            bool isCalceled = (int.Parse(up["newmomentid"].ToString()) > int.Parse(entity1.moment.momentId));
                            if (isCalceled)
                            {
                                //回写entityid
                                o["up"][i]["newmomentid"] = entity1.moment.momentId;
                            }
                        }
                    }
                    //修改后存入字符串
                    jsonString = JsonConvert.SerializeObject(o);
                }
            }
            //回写config
            using (System.IO.StreamWriter writer = new System.IO.StreamWriter(path))
            {
                writer.WriteLine(jsonString);
                writer.Flush();
            }
        }