Example #1
0
 public BigoMessageContext(IBigoMessage message, BigoMessageMetadata metadata, IMessageMethods methods)
 {
     Message  = message;
     Metadata = metadata;
     Methods  = methods;
 }
Example #2
0
        private async void MessageProvider_Received(object sender, IInternalMessage e)
        {
            var internalMessage = e;

            switch (internalMessage)
            {
            case Login _:
            {
                //以下のようなメッセージを送信する
                //1304{"seqId":"1609173325654","roomId":"6825840935873906928","reserver":"0","clientVersion":"0","clientType":"3","version":"0","deviceid":"e6cb67b748c649069bdc88b701154f10","secretKey":"0","other":[]}
                var time   = Tools.GetCurrentUnixTimeMillseconds();
                var roomId = _internalStudioInfo.RoomId;
                var a      = Tools.GetMessagePrefix("5|24");
                var b      = $"{a}{{\"seqId\":\"{time}\",\"roomId\":\"{roomId}\",\"reserver\":\"0\",\"clientVersion\":\"0\",\"clientType\":\"3\",\"version\":\"0\",\"deviceid\":\"{_webSocketLink.DeviceId}\",\"secretKey\":\"0\",\"other\":[]}}";
                await messageProvider.SendAsync(b);
            }
            break;

            case EnterRoomSuccess _:
            {
                //以下のようなメッセージを送信する
                //10776{"uid":"423865522","seqId":"1609173325748","roomid":"6825840935873906928","contribution":"0","enterTimestamp":"0","number":"0","ident":"0","userGrade":"0","version":"0","lastUserBeanGrade":"0","lastUserId":"0","others":[]}
                var time   = Tools.GetCurrentUnixTimeMillseconds();
                var roomId = _internalStudioInfo.RoomId;
                var uid    = _webSocketLink.UserId;
                var a      = Tools.GetMessagePrefix("42|24");
                var b      = $"{a}{{\"uid\":\"{uid}\",\"seqId\":\"{time}\",\"roomid\":\"{roomId}\",\"contribution\":\"0\",\"enterTimestamp\":\"0\",\"number\":\"0\",\"ident\":\"0\",\"userGrade\":\"0\",\"version\":\"0\",\"lastUserBeanGrade\":\"0\",\"lastUserId\":\"0\",\"others\":[]}}";
                await messageProvider.SendAsync(b);
            }
            break;

            case NormalText normalText:
            {
                var m = new BigoComment
                {
                    Id       = "",
                    Message  = normalText.Message,
                    Name     = normalText.Name,
                    PostedAt = DateTime.Now,
                    UserId   = null,
                };
                var metadata = new BigoMessageMetadata(m, _options, _siteOptions, null, this, false);
                var context  = new BigoMessageContext(m, metadata, new BigoMessageMethods());
                MessageReceived?.Invoke(this, context);
            }
            break;

            case LightMyHeartText heartText:
            {
                if (!_giftDict.TryGetValue(heartText.ItemId, out var heart))
                {
                    break;
                }
                var m = new BigoGift
                {
                    Username   = heartText.Username,
                    GiftName   = heart.Name,
                    GiftCount  = 1,
                    GiftImgUrl = heart.ImgUrl,
                };
                var metadata = new BigoMessageMetadata(m, _options, _siteOptions, null, this, false);
                var context  = new BigoMessageContext(m, metadata, new BigoMessageMethods());
                MessageReceived?.Invoke(this, context);
            }
            break;

            case NormalGiftText giftText:
            {
                if (!_giftDict.TryGetValue(giftText.M, out var gift))
                {
                    break;
                }
                Debug.WriteLine($"item={gift.Name} × {giftText.C} by {giftText.N}");
                var m = new BigoGift
                {
                    Username   = giftText.N,
                    GiftName   = gift.Name,
                    GiftCount  = int.Parse(giftText.C),
                    GiftImgUrl = gift.ImgUrl,
                };
                var metadata = new BigoMessageMetadata(m, _options, _siteOptions, null, this, false);
                var context  = new BigoMessageContext(m, metadata, new BigoMessageMethods());
                MessageReceived?.Invoke(this, context);
            }
            break;
            }
        }