Commit a6ee06cf authored by June's avatar June
Browse files

Fix up namespaces, add bad word filter

parent 9e2e98a5
......@@ -4,3 +4,6 @@
[submodule "MomentaryMeeting/Data"]
path = MomentaryMeeting/Data
url = ../../redpointgames/a-momentary-meeting-data.git
[submodule "MomentaryMeeting/WordFilters"]
path = MomentaryMeeting/WordFilters
url = https://github.com/LDNOOBW/List-of-Dirty-Naughty-Obscene-and-Otherwise-Bad-Words
Subproject commit 5d7e727214bcfbdaa86d8aa4650a07cf4b9b21e3
Subproject commit 576035f062482b1f0aadbf0800f173b3207c127e
using Microsoft.Extensions.Logging;
using MomentaryMeeting.Services;
using MomentaryMeeting.Models;
using System.Text;
namespace MomentaryMeeting.Game
namespace MomentaryMeeting.Game
{
using Microsoft.Extensions.Logging;
using MomentaryMeeting.Services;
using MomentaryMeeting.Models;
using System.Text;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Hosting;
using MomentaryMeeting.Game.Interactions;
......@@ -28,9 +27,10 @@ namespace MomentaryMeeting.Game
private InteractionManager _interactionManager;
private readonly IHostEnvironment _hostEnvironment;
private readonly IDistributedCache _distributedCache;
private readonly IWordFilterEngine _wordFilterEngine;
private readonly Database _database;
public CommandParser(ILogger<CommandParser> logger, IDatabaseApi databaseApi, ArrangementGenerator arrangementGenerator, InteractionManager interactionManager, IHostEnvironment hostEnvironment, IDistributedCache distributedCache)
public CommandParser(ILogger<CommandParser> logger, IDatabaseApi databaseApi, ArrangementGenerator arrangementGenerator, InteractionManager interactionManager, IHostEnvironment hostEnvironment, IDistributedCache distributedCache, IWordFilterEngine wordFilterEngine)
{
_databaseApi = databaseApi;
_database = _databaseApi.Current;
......@@ -60,6 +60,7 @@ namespace MomentaryMeeting.Game
_interactionManager = interactionManager;
_hostEnvironment = hostEnvironment;
_distributedCache = distributedCache;
_wordFilterEngine = wordFilterEngine;
}
private static bool IsCardinal(string s)
......@@ -512,17 +513,34 @@ namespace MomentaryMeeting.Game
else
{
string content = command.Substring(verb.Length + 1);
string message = "<" + _database.GlobalText.SelectFromList("other_says").Replace("__CONTENT__", content);
Meeting meeting = _interactionManager.FindMeeting(player);
foreach (UserModel other in meeting._users)
if (_wordFilterEngine.MessageContainsBadWord(content))
{
string message = "<" + _database.GlobalText.SelectFromList("other_says_blocked");
Meeting meeting = _interactionManager.FindMeeting(player);
foreach (UserModel other in meeting._users)
{
if (other.DiscordId != player.DiscordId)
{
ConnectionInfo conn = gameInstance.GetConnection(other.DiscordId);
await gameInstance.SendPromptToPlayer(conn, message);
}
}
response += ">" + _database.GlobalText.SelectFromList("you_say_blocked");
}
else
{
if (other.DiscordId != player.DiscordId)
string message = "<" + _database.GlobalText.SelectFromList("other_says").Replace("__CONTENT__", content);
Meeting meeting = _interactionManager.FindMeeting(player);
foreach (UserModel other in meeting._users)
{
ConnectionInfo conn = gameInstance.GetConnection(other.DiscordId);
await gameInstance.SendPromptToPlayer(conn, message);
if (other.DiscordId != player.DiscordId)
{
ConnectionInfo conn = gameInstance.GetConnection(other.DiscordId);
await gameInstance.SendPromptToPlayer(conn, message);
}
}
response += ">" + _database.GlobalText.SelectFromList("you_say").Replace("__CONTENT__", content);
}
response += ">" + _database.GlobalText.SelectFromList("you_say").Replace("__CONTENT__", content);
}
}
break;
......
using Microsoft.Extensions.Logging;
using MomentaryMeeting.Services;
using MomentaryMeeting.Models;
using System;
using System.Collections.Generic;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed;
namespace MomentaryMeeting.Game
namespace MomentaryMeeting.Game
{
using Microsoft.Extensions.Logging;
using MomentaryMeeting.Services;
using MomentaryMeeting.Models;
using System;
using System.Collections.Generic;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed;
public class ConnectionInfo
{
public UserModel User { get; set; }
......
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Logging;
using MomentaryMeeting.Game.Interactions;
using MomentaryMeeting.Models;
using MomentaryMeeting.Services;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MomentaryMeeting.Game
{
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Logging;
using MomentaryMeeting.Game.Interactions;
using MomentaryMeeting.Models;
using MomentaryMeeting.Services;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MomentaryMeeting.Game
{
public interface IEndMeetings
{
Task EndMeeting(Meeting meeting, bool isTornApart);
......
using MomentaryMeeting.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MomentaryMeeting.Game.Interactions
{
using MomentaryMeeting.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MomentaryMeeting.Game.Interactions
{
public class Meeting
{
// Meetings can never be any longer than this; players will be torn
......
using System.Collections.Generic;
namespace MomentaryMeeting.Models
namespace MomentaryMeeting.Models
{
using System.Collections.Generic;
public class Arrangement : Dictionary<string, float>
{
}
......
using System.Collections.Generic;
namespace MomentaryMeeting.Models
namespace MomentaryMeeting.Models
{
using System.Collections.Generic;
public class Condition
{
public ConditionType Type { get; set; }
......
using System;
using System.Collections.Generic;
namespace MomentaryMeeting.Models
namespace MomentaryMeeting.Models
{
using System;
using System.Collections.Generic;
public class Database
{
public GlobalText GlobalText { get; set; }
......
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using YamlDotNet.Serialization;
namespace MomentaryMeeting.Models
namespace MomentaryMeeting.Models
{
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using YamlDotNet.Serialization;
public class GlobalText : Dictionary<string, List<string>>
{
public Dictionary<string, List<string>> CloneWithUsernameReplacement(string username)
......
using System.Collections.Generic;
namespace MomentaryMeeting.Models
namespace MomentaryMeeting.Models
{
using System.Collections.Generic;
public class Links
{
public List<string> Always { get; set; }
......
using System.Collections.Generic;
namespace MomentaryMeeting.Models
namespace MomentaryMeeting.Models
{
using System.Collections.Generic;
public class Location
{
// set the region name
......
using System.Collections.Generic;
namespace MomentaryMeeting.Models
namespace MomentaryMeeting.Models
{
using System.Collections.Generic;
public class Region
{
public string Description { get; set; }
......
using Microsoft.Extensions.Caching.Distributed;
using MomentaryMeeting.Services;
using System.Threading.Tasks;
namespace MomentaryMeeting.Models
{
using Microsoft.Extensions.Caching.Distributed;
using MomentaryMeeting.Services;
using System.Threading.Tasks;
public class UserModel
{
public ulong DiscordId { get; set; }
......
......@@ -12,6 +12,68 @@
<EmbeddedResource Include="Data\*.yaml" />
</ItemGroup>
<ItemGroup>
<None Remove="WordFilters\ar" />
<None Remove="WordFilters\cs" />
<None Remove="WordFilters\da" />
<None Remove="WordFilters\de" />
<None Remove="WordFilters\en" />
<None Remove="WordFilters\eo" />
<None Remove="WordFilters\es" />
<None Remove="WordFilters\fa" />
<None Remove="WordFilters\fi" />
<None Remove="WordFilters\fil" />
<None Remove="WordFilters\fr" />
<None Remove="WordFilters\fr-CA-u-sd-caqc" />
<None Remove="WordFilters\hi" />
<None Remove="WordFilters\hu" />
<None Remove="WordFilters\it" />
<None Remove="WordFilters\ja" />
<None Remove="WordFilters\kab" />
<None Remove="WordFilters\ko" />
<None Remove="WordFilters\nl" />
<None Remove="WordFilters\no" />
<None Remove="WordFilters\pl" />
<None Remove="WordFilters\pt" />
<None Remove="WordFilters\ru" />
<None Remove="WordFilters\sv" />
<None Remove="WordFilters\th" />
<None Remove="WordFilters\tlh" />
<None Remove="WordFilters\tr" />
<None Remove="WordFilters\zh" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="WordFilters\ar" />
<EmbeddedResource Include="WordFilters\cs" />
<EmbeddedResource Include="WordFilters\da" />
<EmbeddedResource Include="WordFilters\de" />
<EmbeddedResource Include="WordFilters\en" />
<EmbeddedResource Include="WordFilters\eo" />
<EmbeddedResource Include="WordFilters\es" />
<EmbeddedResource Include="WordFilters\fa" />
<EmbeddedResource Include="WordFilters\fi" />
<EmbeddedResource Include="WordFilters\fil" />
<EmbeddedResource Include="WordFilters\fr" />
<EmbeddedResource Include="WordFilters\fr-CA-u-sd-caqc" />
<EmbeddedResource Include="WordFilters\hi" />
<EmbeddedResource Include="WordFilters\hu" />
<EmbeddedResource Include="WordFilters\it" />
<EmbeddedResource Include="WordFilters\ja" />
<EmbeddedResource Include="WordFilters\kab" />
<EmbeddedResource Include="WordFilters\ko" />
<EmbeddedResource Include="WordFilters\nl" />
<EmbeddedResource Include="WordFilters\no" />
<EmbeddedResource Include="WordFilters\pl" />
<EmbeddedResource Include="WordFilters\pt" />
<EmbeddedResource Include="WordFilters\ru" />
<EmbeddedResource Include="WordFilters\sv" />
<EmbeddedResource Include="WordFilters\th" />
<EmbeddedResource Include="WordFilters\tlh" />
<EmbeddedResource Include="WordFilters\tr" />
<EmbeddedResource Include="WordFilters\zh" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Redpoint.CloudFramework\Redpoint.CloudFramework\Redpoint.CloudFramework.csproj" />
</ItemGroup>
......
namespace MomentaryMeeting.Services
{
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
public interface IWordFilterEngine
{
bool MessageContainsBadWord(string message);
}
public class WordFilterEngine : IWordFilterEngine
{
private List<string> _loadedBadWords;
public WordFilterEngine(ILogger<WordFilterEngine> logger)
{
_loadedBadWords = new List<string>();
var manifestNames = Assembly.GetExecutingAssembly().GetManifestResourceNames().Where(x => x.StartsWith("MomentaryMeeting.WordFilters.")).ToList();
foreach (var manifestName in manifestNames)
{
using (var reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestName)))
{
_loadedBadWords.AddRange(
reader.ReadToEnd().Split("\n").Select(x => x.Trim().ToLowerInvariant()).Where(x => !string.IsNullOrWhiteSpace(x)));
}
}
logger.LogInformation($"Loaded {_loadedBadWords.Count} bad words into the bad word filter.");
}
public bool MessageContainsBadWord(string message)
{
return message.Split(" ").ToList().Any(x => _loadedBadWords.Contains(x.ToLowerInvariant()));
}
}
}
......@@ -35,6 +35,7 @@ namespace MomentaryMeeting
services.AddSingleton<CommandParser, CommandParser>();
services.AddSingleton<ArrangementGenerator, ArrangementGenerator>();
services.AddSingleton<InteractionManager, InteractionManager>();
services.AddSingleton<IWordFilterEngine, WordFilterEngine>();
if (_env.IsProduction())
{
......
Subproject commit 5faf2ba42d7b1c0977169ec3611df25a3c08eb13
......@@ -15,7 +15,7 @@ html, body {
padding: 0;
font-family: 'IBM Plex Mono', monospace !important;
color: #3f3;
text-shadow: 0px 0px 6px;
text-shadow: 0px 0px 6px rgba(51, 255, 51, 0.7);
font-size: 1em;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment