Beispiel #1
0
 public DefaultReceiveCommand(byte[] data, ISocketService service, IServerMessageSubject transponder,
                              QQUser user)
     : base(data, service, transponder, user)
 {
     _packet    = new ReceiveCurrency(data, _user);
     _eventArgs = new QQEventArgs <ReceiveCurrency>(_service, _user, _packet);
 }
 /// <summary>
 ///     群分组信息查询
 /// </summary>
 public GroupCategoryCommand(byte[] data, ISocketService service, IServerMessageSubject transponder,
                             QQUser user) :
     base(data, service, transponder, user)
 {
     _packet    = new Receive_0X0195(data, _user);
     _eventArgs = new QQEventArgs <Receive_0X0195>(_service, _user, _packet);
 }
 protected DispatchPacketToCommand(byte[] data, ISocketService service, IServerMessageSubject transponder,
                                   QQUser user)
 {
     _data        = data;
     _service     = service;
     _transponder = transponder;
     _user        = user;
 }
Beispiel #4
0
        public CustomRobot(ISendMessageService service, IServerMessageSubject transponder, QQUser user)
        {
            _service     = service;
            _transponder = transponder;
            _user        = user;

            // 将机器人加入转发器的订阅列表中
            _transponder.AddCustomRoBot(this);
        }
        protected MiddleLayerBot(ISendMessageService service, IServerMessageSubject transponder, QQUser user) : base(service, transponder, user)
        {
            if (!Config.DefaultConfig.UseLocalClient)
            {
                Program.Listener.MessageEvent += (api, message) =>
                {
                    if (message is GroupMessage)
                    {
                        var groupMessage = (GroupMessage)message;
                        ReceiveGroupMessage(groupMessage.GroupId, groupMessage.Sender.UserId, groupMessage.Content.Text);
                        return;
                    }

                    if (message is PrivateMessage)
                    {
                        var privateMessage = (PrivateMessage)message;
                        ReceiveFriendMessage(privateMessage.UserId, privateMessage.Content.Text);
                    }
                };
            }
        }
 public ReceiveQQFriendMessagesCommand(byte[] data, ISocketService service, IServerMessageSubject transponder,
                                       QQUser user) : base(data, service, transponder, user)
 {
     _packet    = new Receive_0X00Ce(data, _user);
     _eventArgs = new QQEventArgs <Receive_0X00Ce>(_service, _user, _packet);
 }
Beispiel #7
0
 public LogonCollection(byte[] data, ISocketService service, IServerMessageSubject transponder, QQUser user) :
     base(data, service, transponder, user)
 {
     _packet    = new Receive_0X0839(data, _user);
     _eventArgs = new QQEventArgs <Receive_0X0839>(_service, _user, _packet);
 }
Beispiel #8
0
 public ReceiveCommand(byte[] data, ISocketService service, IServerMessageSubject transponder, QQUser user)
 {
     _service     = service;
     _transponder = transponder;
     _user        = user;
 }
Beispiel #9
0
 public OnLineStateCommand(byte[] data, ISocketService service, IServerMessageSubject transponder, QQUser user) :
     base(data, service, transponder, user)
 {
     _packet    = new Receive_0X00Ec(data, _user);
     _eventArgs = new QQEventArgs <Receive_0X00Ec>(_service, _user, _packet);
 }
Beispiel #10
0
 public Robot(ISendMessageService service, IServerMessageSubject transponder, QQUser user) : base(service, transponder, user)
 {
     this._QQUser = user;
 }
Beispiel #11
0
 public TestRoBot(ISendMessageService service, IServerMessageSubject transponder, QQUser user) : base(service, transponder, user)
 {
 }
 public static DispatchPacketToCommand Of(byte[] data, ISocketService service, IServerMessageSubject transponder,
                                          QQUser user)
 {
     return(new DispatchPacketToCommand(data, service, transponder, user));
 }
        public LocalVtuberBot(ISendMessageService service, IServerMessageSubject transponder, QQUser user) : base(service, transponder, user)
        {
            _youtubeLiveCollection = Program.Database.GetCollection <YoutubeLiveInfo>("youtube-live-details");
            _biliLiveCollection    = Program.Database.GetCollection <BiliBiliLiveInfo>("bili-live-details");
            _tweetCollection       = Program.Database.GetCollection <TweetInfo>("tweet-details");
            CacheManager.Manager.VtuberBeginLiveEvent += (vtuber, video) =>
            {
                var info = YoutubeApi.GetYoutubeVideo(video.VideoId);
                LogHelper.Info($"Vtuber {vtuber.OriginalName} 开始了直播 {video.VideoLink}");
                foreach (var(key, value) in Config.DefaultConfig.Subscribes)
                {
                    var config = value.FirstOrDefault(v =>
                                                      string.Equals(v.VtuberName, vtuber.OriginalName, StringComparison.CurrentCultureIgnoreCase));
                    if (config?.BeginLive ?? false)
                    {
                        _service.SendToGroup(key, $"{vtuber.OriginalName} 在 {info.LiveDetails.ActualStartTime.ToUniversalTime().AddHours(8):yyyy-MM-dd HH:mm:ss} 开始直播 {video.Title}\r\n" +
                                             $"链接: {video.VideoLink}\r\n当前观众数量: {info.LiveDetails.ViewersCount}\r\n" +
                                             $"原定直播时间: {info.LiveDetails.ScheduledStartTime.ToUniversalTime().AddHours(8):yyyy-MM-dd HH:mm:ss}\r\n" +
                                             $"实际开播时间:  {info.LiveDetails.ActualStartTime.ToUniversalTime().AddHours(8):yyyy-MM-dd HH:mm:ss}");
                    }
                }

                var recorder = new LiveChatRecorder(info.LiveDetails.LiveChatId, vtuber, video.VideoId);
                recorder.StartRecord();
                recorder.LiveStoppedEvent += (id, recder) =>
                {
                    LogHelper.Info($"{vtuber.OriginalName} 已停止直播, 正在保存评论数据...");
                    info = YoutubeApi.GetYoutubeVideo(video.VideoId) ?? info;
                    var live = new YoutubeLiveInfo()
                    {
                        Title     = info.Title,
                        Channel   = info.ChannelId,
                        BeginTime = info.LiveDetails?.ActualStartTime ?? default(DateTime),
                        EndTime   = info.LiveDetails?.ActualEndTime ?? DateTime.Now,
                        VideoId   = video.VideoId
                    };
                    _youtubeLiveCollection.ReplaceOne(v => v.VideoId == live.VideoId, live,
                                                      new UpdateOptions()
                    {
                        IsUpsert = true
                    });
                    LogHelper.Info("保存完毕");
                };
            };

            CacheManager.Manager.VtuberUploadVideoEvent += (vtuber, video) =>
            {
                LogHelper.Info($"Vtuber {vtuber.OriginalName} 上传了视频 {video.Title}");
                foreach (var(key, value) in Config.DefaultConfig.Subscribes)
                {
                    var config = value.FirstOrDefault(v =>
                                                      string.Equals(v.VtuberName, vtuber.OriginalName, StringComparison.CurrentCultureIgnoreCase));
                    if (config?.UploadVideo ?? false)
                    {
                        _service.SendToGroup(key, $"{vtuber.OriginalName} 在 {video.PublishTime.ToUniversalTime().AddHours(8):yyyy-MM-dd HH:mm:ss} 上传了视频 {video.Title}\r\n" +
                                             $"链接: {video.VideoLink}");
                    }
                }
            };

            CacheManager.Manager.VtuberPublishTweetEvent += (vtuber, tweet) =>
            {
                LogHelper.Info($"Vtuber {vtuber.OriginalName} 发布了新的推特 {tweet.Content.Substring(0, 5)}....");
                foreach (var(key, value) in Config.DefaultConfig.Subscribes)
                {
                    var config = value.FirstOrDefault(v =>
                                                      string.Equals(v.VtuberName, vtuber.OriginalName, StringComparison.CurrentCultureIgnoreCase));
                    if (config?.PublishTweet ?? false)
                    {
                        _service.SendToGroup(key, $"{vtuber.OriginalName} 在 {tweet.CreateTime.ToUniversalTime().AddHours(8):yyyy-MM-dd HH:mm:ss} 发布了:\r\n" +
                                             $"{(tweet.Content.Length > 255 ? tweet.Content.Substring(0, 255) : tweet.Content)}");
                    }
                }

                try
                {
                    _tweetCollection.InsertOne(tweet);
                }
                catch (Exception ex)
                {
                    LogHelper.Error("Insert object error", true, ex);
                }
            };

            CacheManager.Manager.VtuberReplyTweetEvent += (vtuber, tweet) =>
            {
                LogHelper.Info($"Vtuber {vtuber.OriginalName} 回复了 {tweet.ReplyScreenname} 的推特 {tweet.Content.Substring(0, 5)}....");
                foreach (var(key, value) in Config.DefaultConfig.Subscribes)
                {
                    var config = value.FirstOrDefault(v =>
                                                      string.Equals(v.VtuberName, vtuber.OriginalName, StringComparison.CurrentCultureIgnoreCase));
                    if (config?.ReplyTweet ?? false)
                    {
                        _service.SendToGroup(key, $"{vtuber.OriginalName} 在 {tweet.CreateTime.ToUniversalTime().AddHours(8):yyyy-MM-dd HH:mm:ss} 回复了 {tweet.RetweetedTweet}:\r\n" +
                                             $"{(tweet.Content.Length > 255 ? tweet.Content.Substring(0, 255) : tweet.Content)}");
                    }
                }
                try
                {
                    _tweetCollection.InsertOne(tweet);
                }
                catch (Exception ex)
                {
                    LogHelper.Error("Insert object error", true, ex);
                }
            };

            CacheManager.Manager.VtuberRetweetedEvent += (vtuber, tweet) =>
            {
                LogHelper.Info($"Vtuber {vtuber.OriginalName} 转发了 {tweet.RetweetedTweet.User.Name} 的推特: {tweet.Content.Substring(0, 5)}....");
                foreach (var(key, value) in Config.DefaultConfig.Subscribes)
                {
                    var config = value.FirstOrDefault(v =>
                                                      string.Equals(v.VtuberName, vtuber.OriginalName, StringComparison.CurrentCultureIgnoreCase));
                    if (config?.Retweeted ?? false)
                    {
                        _service.SendToGroup(key, $"{vtuber.OriginalName} 在 {tweet.CreateTime.ToUniversalTime().AddHours(8):yyyy-MM-dd HH:mm:ss} 转发了 {tweet.RetweetedTweet.User.Name} 的推:\r\n" +
                                             $"{(tweet.Content.Length > 255 ? tweet.Content.Substring(0, 255) : tweet.Content)}");
                    }
                }
                try
                {
                    _tweetCollection.InsertOne(tweet);
                }
                catch (Exception ex)
                {
                    LogHelper.Error("Insert object error", true, ex);
                }
            };

            CacheManager.Manager.VtuberBeginLiveBilibiliEvent += (vtuber, bUser) =>
            {
                var beginTime = DateTime.Now;
                LogHelper.Info($"Vtuber {vtuber.OriginalName} 在B站开始了直播 {bUser.LiveUrl}");
                foreach (var(key, value) in Config.DefaultConfig.Subscribes)
                {
                    var config = value.FirstOrDefault(v =>
                                                      string.Equals(v.VtuberName, vtuber.OriginalName, StringComparison.CurrentCultureIgnoreCase));
                    if (config?.BilibiliBeginLive ?? false)
                    {
                        _service.SendToGroup(key, $"{vtuber.OriginalName} 在B站开始了直播 {bUser.LiveTitle}\r\n" +
                                             $"链接: {bUser.LiveUrl}");
                    }
                }

                var liveId   = StringTools.RandomString;
                var liveInfo = new BiliBiliLiveInfo()
                {
                    LiveId        = liveId,
                    Title         = bUser.LiveTitle,
                    BeginTime     = beginTime,
                    EndTime       = beginTime,
                    MaxPopularity = 0
                };
                var live = _biliLiveCollection.FindAsync(v => v.MaxPopularity == 0 && v.Title == bUser.LiveTitle)
                           .GetAwaiter().GetResult().FirstOrDefault();
                if (live != null)
                {
                    liveId = live.LiveId;
                }
                else
                {
                    _biliLiveCollection.InsertOne(liveInfo);
                }
                var recorder = new DanmakuRecorder(bUser.LiveRoomId, liveId, vtuber);
                recorder.StartRecord();
                recorder.LiveStoppedEvent += info =>
                {
                    LogHelper.Info($"{vtuber.OriginalName} 已停止在B站的直播.");
                    liveInfo = new BiliBiliLiveInfo()
                    {
                        LiveId        = liveId,
                        Title         = bUser.LiveTitle,
                        BeginTime     = beginTime,
                        EndTime       = DateTime.Now,
                        MaxPopularity = recorder.Client.MaxPopularity
                    };
                    _biliLiveCollection.ReplaceOne(v => v.LiveId == liveInfo.LiveId, liveInfo,
                                                   new UpdateOptions()
                    {
                        IsUpsert = true
                    });
                };
            };
        }
Beispiel #14
0
 public GRPCRobot(ISendMessageService service, IServerMessageSubject transponder, QQUser user, QQBotClient botclient) : base(service, transponder, user)
 {
     this._botclient = botclient;
 }
Beispiel #15
0
 public GetTgtgtCommand(byte[] data, ISocketService service, IServerMessageSubject transponder, QQUser user) :
     base(data, service, transponder, user)
 {
     _packet    = new Receive_0X0836(data, _user);
     _eventArgs = new QQEventArgs <Receive_0X0836>(_service, _user, _packet);
 }
Beispiel #16
0
 public MessageManage(ISocketService service, QQUser user, IServerMessageSubject transponder)
 {
     _service     = service;
     _user        = user;
     _transponder = transponder;
 }
Beispiel #17
0
 public SendingGroupSystemMessagesCommand(byte[] data, ISocketService service, IServerMessageSubject transponder,
                                          QQUser user) : base(data, service, transponder, user)
 {
     _packet    = new Receive_0X0002(data, _user);
     _eventArgs = new QQEventArgs <Receive_0X0002>(_service, _user, _packet);
 }
Beispiel #18
0
 /// <summary>
 ///     收到群/系统消息
 /// </summary>
 public ReceiveGroupSystemMessagesCommand(byte[] data, ISocketService service, IServerMessageSubject transponder,
                                          QQUser user) : base(data, service, transponder, user)
 {
     _packet = new Receive_0X0017(data, _user);
     if (_user.GroupMessages.Where(c => c.Sequence == _packet.Sequence).Any())
     {
         var messageSend = _user.GroupMessages.Where(c => c.Sequence == _packet.Sequence).FirstOrDefault();
         if (messageSend != null)
         {
             messageSend.MessageId    = _packet.MessageId;
             messageSend.MessageIndex = _packet.MessageIndex;
         }
     }
     _eventArgs = new QQEventArgs <Receive_0X0017>(_service, _user, _packet);
 }