实现提供了完整的弹幕功能,包括多行显示、不同颜色、头像支持、防重叠、椭圆形边框、透明度渐变、点击事件、字体样式设置、暂停/继续功能、过滤功能等。还包含了批处理队列处理逻辑、速率限制、错误处理和性能监控等功能。

This commit is contained in:
yangwx01
2025-03-29 17:19:12 +08:00
parent d347357448
commit 4e178cb724
119 changed files with 2578 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using YwxAppWpfDanMu.Models;
namespace YwxAppWpfDanMu.Controls
{
public static class DanMuFilter
{
private static readonly List<string> _blockedKeywords = new List<string>();
private static readonly List<Regex> _blockedPatterns = new List<Regex>();
public static void AddBlockedKeyword(string keyword)
{
if (!string.IsNullOrWhiteSpace(keyword) && !_blockedKeywords.Contains(keyword))
{
_blockedKeywords.Add(keyword);
}
}
public static void AddBlockedPattern(string pattern)
{
if (!string.IsNullOrWhiteSpace(pattern))
{
_blockedPatterns.Add(new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase));
}
}
public static bool ShouldFilter(DanMuMessage message)
{
if (message == null || string.IsNullOrWhiteSpace(message.Content))
return true;
// 检查关键词
foreach (var keyword in _blockedKeywords)
{
if (message.Content.Contains(keyword))
return true;
}
// 检查正则表达式
foreach (var pattern in _blockedPatterns)
{
if (pattern.IsMatch(message.Content))
return true;
}
return false;
}
}
}