-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from bdach/apply-chat-filters-when-editing-ro…
…om-name Apply chat filters to room name when editing multiplayer room settings
- Loading branch information
Showing
9 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Collections.Immutable; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using osu.Server.Spectator.Database; | ||
using osu.Server.Spectator.Database.Models; | ||
|
||
namespace osu.Server.Spectator | ||
{ | ||
public class ChatFilters | ||
{ | ||
private readonly IDatabaseFactory factory; | ||
private ImmutableArray<chat_filter>? filters; | ||
|
||
public ChatFilters(IDatabaseFactory factory) | ||
{ | ||
this.factory = factory; | ||
} | ||
|
||
public async Task<string> FilterAsync(string input) | ||
{ | ||
if (filters == null) | ||
{ | ||
using var db = factory.GetInstance(); | ||
filters = (await db.GetAllChatFiltersAsync()).ToImmutableArray(); | ||
} | ||
|
||
var stringBuilder = new StringBuilder(input); | ||
|
||
foreach (var filter in filters) | ||
stringBuilder.Replace(filter.match, filter.replacement); | ||
|
||
return stringBuilder.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
|
||
// ReSharper disable InconsistentNaming (matches database table) | ||
|
||
namespace osu.Server.Spectator.Database.Models | ||
{ | ||
[Serializable] | ||
public class chat_filter | ||
{ | ||
public long id { get; set; } | ||
public string match { get; set; } = string.Empty; | ||
public string replacement { get; set; } = string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters