Skip to content

Commit

Permalink
区分续费与新舰长
Browse files Browse the repository at this point in the history
  • Loading branch information
GD-Slime committed May 27, 2024
1 parent 8bdc79b commit c1a96f6
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 32 deletions.
27 changes: 20 additions & 7 deletions src/BiliLite.UWP/Models/Common/Live/DanmuMsgModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,23 @@ public class DanmuMsgModel
/// </summary>
public string UserName { get; set; }

private string _userNameColor;
/// <summary>
/// 用户名颜色, 默认灰色
/// </summary>
public string UserNameColor { get; set; } = "#FF808080";
public string UserNameColor
{
get => _userNameColor ??
UserCaptain switch
{
3 => "#FF23709E",
2 => "#FF7B166F",
1 => "#FFC01039",
_ => "#FF808080"
};

set => _userNameColor = value;
}

/// <summary>
/// 用户名字重, 默认Normal
Expand Down Expand Up @@ -83,17 +96,17 @@ public class DanmuMsgModel
/// <summary>
/// 勋章等级
/// </summary>
public string MedalLevel { get; set; }
public int MedalLevel { get; set; }

/// <summary>
/// 勋章颜色
/// </summary>
public string MedalColor { get; set; }

/// <summary>
/// 用户上的舰的名称
/// 用户舰队等级
/// </summary>
public string UserCaptain { get; set; }
public int UserCaptain { get; set; }

/// <summary>
/// 用户上的舰的图片
Expand All @@ -102,9 +115,9 @@ public string UserCaptainImage
{
get => UserCaptain switch
{
"舰长" => "ms-appx:///Assets/Live/ic_live_guard_3.png",
"提督" => "ms-appx:///Assets/Live/ic_live_guard_2.png",
"总督" => "ms-appx:///Assets/Live/ic_live_guard_1.png",
3 => "ms-appx:///Assets/Live/ic_live_guard_3.png", //舰长
2 => "ms-appx:///Assets/Live/ic_live_guard_2.png", //提督
1 => "ms-appx:///Assets/Live/ic_live_guard_1.png", //总督
_ => null,
};
}
Expand Down
10 changes: 10 additions & 0 deletions src/BiliLite.UWP/Models/Common/Live/GuardBuyMsgModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,15 @@ public Color CardColor
/// 礼物名称
/// </summary>
public string GiftName { get; set; }

/// <summary>
/// 购买的时间单位, 如"月"
/// </summary>
public string Unit { get; set;}

/// <summary>
/// 庆祝消息正文
/// </summary>
public string Message { get; set; }
}
}
35 changes: 33 additions & 2 deletions src/BiliLite.UWP/Models/Common/Live/LiveMessageHandleActionsMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public LiveMessageHandleActionsMap()
{ MessageType.AnchorLotteryStart, AnchorLotteryStart },
{ MessageType.AnchorLotteryAward, AnchorLotteryAward },
{ MessageType.GuardBuy, GuardBuy },
{ MessageType.GuardBuyNew, GuardBuyNew},
{ MessageType.RoomChange, RoomChange },
{ MessageType.RoomBlock, RoomBlock },
{ MessageType.WaringOrCutOff, WaringOrCutOff },
Expand All @@ -37,7 +38,7 @@ public LiveMessageHandleActionsMap()
{ MessageType.RedPocketLotteryWinner, RedPocketLotteryWinner },
{ MessageType.OnlineRankChange, OnlineRankChange },
{ MessageType.StopLive, StopLive },
{ MessageType.RoomSlient, RoomSlient },
{ MessageType.ChatLevelMute, ChatLevelMute },
};
}

Expand Down Expand Up @@ -203,6 +204,36 @@ private void GuardBuy(LiveRoomViewModel viewModel, object message)
viewModel.ReloadGuardList().RunWithoutAwait();
}

private void GuardBuyNew(LiveRoomViewModel viewModel, object message)
{
var info = message as GuardBuyMsgModel;

var isNewGuard = info.Message.Contains("开通");

int accompanyDays = -1;
var match = Regex.Match(info.Message, @"今天是TA陪伴主播的第(\d+)天");
if (match.Success) accompanyDays = match.Groups[1].Value.ToInt32();

var text = info.UserName +
(isNewGuard ? "\n新开通了" : "\n续费了") +
$"主播的{info.GiftName}" +
(info.Num > 1 ? ${info.Num}{info.Unit}" : "") +
"🎉" +
((match.Success && accompanyDays > 1) ? $"\nTA已陪伴主播{accompanyDays}天💖" : "");

var msg = new DanmuMsgModel
{
ShowUserName = Visibility.Collapsed,
ShowUserFace = Visibility.Collapsed,
RichText = text.ToRichTextBlock(null, fontWeight: "SemiBold", fontColor: info.FontColor, textAlignment: "Center"),
CardColor = new SolidColorBrush(info.CardColor),
CardHorizontalAlignment = HorizontalAlignment.Center,
};

viewModel.Messages.Add(msg);
if (isNewGuard) viewModel.ReloadGuardList().RunWithoutAwait();
}

private void RoomChange(LiveRoomViewModel viewModel, object message)
{
var info = message as RoomChangeMsgModel;
Expand Down Expand Up @@ -291,7 +322,7 @@ private void StopLive(LiveRoomViewModel viewModel, object message)
});
}

private void RoomSlient(LiveRoomViewModel viewModel, object level)
private void ChatLevelMute(LiveRoomViewModel viewModel, object level)
{
viewModel.Messages.Add(new DanmuMsgModel()
{
Expand Down
50 changes: 27 additions & 23 deletions src/BiliLite.UWP/Modules/Live/LiveMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,32 +261,17 @@ private MessageDelayType ParseMessage(string jsonMessage)
}

// 是否为舰长
if (obj["info"][3] != null && obj["info"][3].ToArray().Length != 0 &&
obj["info"][3][10] != null && Convert.ToInt32(obj["info"][3][10].ToString()) != 0)
if (obj["info"][7] != null && obj["info"][7].ToString().Length != 0)
{
switch (Convert.ToInt32(obj["info"][3][10].ToString()))
{
case 3:
msg.UserCaptain = "舰长";
msg.UserNameColor = "#FF23709E";
break;
case 2:
msg.UserCaptain = "提督";
msg.UserNameColor = "#FF7B166F";
break;
case 1:
msg.UserCaptain = "总督";
msg.UserNameColor = "#FFC01039";
break;
}
msg.UserCaptain = obj["info"][7].ToInt32();
msg.ShowCaptain = Visibility.Visible;
}

// 粉丝牌
if (obj["info"][3] != null && obj["info"][3].ToArray().Length != 0)
{
msg.MedalName = obj["info"][3][1].ToString();
msg.MedalLevel = obj["info"][3][0].ToString();
msg.MedalLevel = obj["info"][3][0].ToInt32();
msg.MedalColor = obj["info"][3][4].ToString();
msg.ShowMedal = Visibility.Visible;
}
Expand Down Expand Up @@ -350,7 +335,7 @@ private MessageDelayType ParseMessage(string jsonMessage)
if (obj["data"]["fans_medal"]["medal_level"].ToInt32() != 0)
{
w.MedalName = obj["data"]["fans_medal"]["medal_name"].ToString();
w.MedalLevel = obj["data"]["fans_medal"]["medal_level"].ToString();
w.MedalLevel = obj["data"]["fans_medal"]["medal_level"].ToInt32();
w.MedalColor = obj["data"]["fans_medal"]["medal_color"].ToString();
w.ShowMedal = Visibility.Visible;
}
Expand Down Expand Up @@ -432,19 +417,38 @@ private MessageDelayType ParseMessage(string jsonMessage)
}
return MessageDelayType.SystemMessage;
}
else if (cmd == "GUARD_BUY")
//else if (cmd == "GUARD_BUY")
//{
// if (obj["data"] != null)
// {
// NewMessage?.Invoke(MessageType.GuardBuy, new GuardBuyMsgModel()
// {
// GiftId = obj["data"]["gift_id"].ToInt32(),
// GiftName = obj["data"]["gift_name"].ToString(),
// Num = obj["data"]["num"].ToInt32(),
// Price = obj["data"]["price"].ToInt32(),
// UserName = obj["data"]["username"].ToString(),
// UserID = obj["data"]["uid"].ToString(),
// GuardLevel = obj["data"]["guard_level"].ToInt32(),
// });
// }
// return MessageDelayType.SystemMessage;
//}
else if (cmd == "USER_TOAST_MSG")
{
if (obj["data"] != null)
{
NewMessage?.Invoke(MessageType.GuardBuy, new GuardBuyMsgModel()
NewMessage?.Invoke(MessageType.GuardBuyNew, new GuardBuyMsgModel()
{
GiftId = obj["data"]["gift_id"].ToInt32(),
GiftName = obj["data"]["gift_name"].ToString(),
GiftName = obj["data"]["role_name"].ToString(),
Num = obj["data"]["num"].ToInt32(),
Price = obj["data"]["price"].ToInt32(),
UserName = obj["data"]["username"].ToString(),
UserID = obj["data"]["uid"].ToString(),
GuardLevel = obj["data"]["guard_level"].ToInt32(),
Unit = obj["data"]["unit"].ToString(),
Message = obj["data"]["toast_msg"].ToString(),
});
}
return MessageDelayType.SystemMessage;
Expand Down Expand Up @@ -513,7 +517,7 @@ private MessageDelayType ParseMessage(string jsonMessage)
{
if (obj["data"] != null)
{
NewMessage?.Invoke(MessageType.RoomSlient, obj["data"]["level"].ToInt32());
NewMessage?.Invoke(MessageType.ChatLevelMute, obj["data"]["level"].ToInt32());
}
return MessageDelayType.SystemMessage;
}
Expand Down

0 comments on commit c1a96f6

Please sign in to comment.