Skip to content

Commit

Permalink
Merge pull request #100 from Vivelin/feature/additions
Browse files Browse the repository at this point in the history
Tracker additions and fixes
  • Loading branch information
Vivelin authored Mar 27, 2022
2 parents 1fdca4b + 76b2568 commit 1b23fd9
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 34 deletions.
2 changes: 1 addition & 1 deletion setup/randomizer.app.iss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "CodeDependencies.iss"

#define MyAppName "SMZ3 Cas' Randomizer"
#define MyAppVersion "4.1.1"
#define MyAppVersion "4.2.0"
#define MyAppPublisher "Vivelin"
#define MyAppURL "https://github.com/Vivelin/SMZ3Randomizer"
#define MyAppExeName "Randomizer.App.exe"
Expand Down
2 changes: 1 addition & 1 deletion src/Randomizer.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected static void ConfigureServices(IServiceCollection services)
services.AddScoped<TrackerLocationSyncer>();

// Chat
services.AddSingleton<IChatClient, TwitchChatClient>();
services.AddScoped<IChatClient, TwitchChatClient>();
services.AddSingleton<IChatAuthenticationService, TwitchAuthenticationService>();

// WPF
Expand Down
2 changes: 1 addition & 1 deletion src/Randomizer.App/Randomizer.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<ApplicationIcon>chozo20.ico</ApplicationIcon>
<Version>4.1.1</Version>
<Version>4.2.0</Version>
<Title>SMZ3 Cas' Randomizer</Title>
<AssemblyTitle>SMZ3 Cas' Randomizer</AssemblyTitle>
<Authors>Vivelin</Authors>
Expand Down
5 changes: 4 additions & 1 deletion src/Randomizer.SMZ3.ChatIntegration/ChatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ namespace Randomizer.SMZ3.ChatIntegration
{
public abstract class ChatMessage
{
protected ChatMessage(string sender, string text)
protected ChatMessage(string sender, string userName, string text)
{
Sender = sender ?? throw new ArgumentNullException(nameof(sender));
SenderUserName = userName ?? throw new ArgumentNullException(nameof(userName));
Text = text ?? throw new ArgumentNullException(nameof(text));
}

public virtual string Sender { get; protected init; }

public virtual string SenderUserName { get; protected init; }

public virtual string Text { get; protected init; }
}
}
19 changes: 14 additions & 5 deletions src/Randomizer.SMZ3.Tracking/Configuration/ChatConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class ChatConfig
= new("Hello chat.");

/// <summary>
/// Gets the phrases to respond with when greeting by someone in chat.
/// Gets the phrases to respond with when greeted by someone in chat.
/// </summary>
/// <remarks>
/// <c>{0}</c> is a placeholder for the user name of the person in chat
/// to respond to.
/// <c>{0}</c> is a placeholder for the display name of the person in
/// chat to respond to.
/// </remarks>
public SchrodingersString GreetingResponses { get; init; }
= new("Hey {0}");
Expand All @@ -36,11 +36,20 @@ public class ChatConfig
/// second time in chat.
/// </summary>
/// <remarks>
/// <c>{0}</c> is a placeholder for the user name of the person in chat
/// to respond to.
/// <c>{0}</c> is a placeholder for the display name of the person in
/// chat to respond to.
/// </remarks>
public SchrodingersString? GreetedTwice { get; init; }

/// <summary>
/// Gets the phrases to respond with when greeted by the broadcaster.
/// </summary>
/// <remarks>
/// <c>{0}</c> is a placeholder for the display name of the person in
/// chat to respond to.
/// </remarks>
public SchrodingersString? GreetedChannel { get; init; }

/// <summary>
/// Gets a dictionary that contains usernames and their replacement for
/// text-to-speech pronunciation purposes.
Expand Down
9 changes: 5 additions & 4 deletions src/Randomizer.SMZ3.Tracking/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,10 @@ public static string CorrectPronunciation(string name)
/// </returns>
public string CorrectUserNamePronunciation(string userName)
{
if (Responses.Chat.UserNamePronunciation.TryGetValue(userName, out var correctedUserName))
return correctedUserName;
return userName;
var correctedUserName = Responses.Chat.UserNamePronunciation
.SingleOrDefault(x => x.Key.Equals(userName, StringComparison.OrdinalIgnoreCase));

return correctedUserName.Value ?? userName;
}

/// <summary>
Expand Down Expand Up @@ -2158,7 +2159,7 @@ private void GiveLocationComment(ItemData item, Location location, bool isTracki
return dungeon;
}

private void RestartIdleTimers()
internal void RestartIdleTimers()
{
foreach (var item in _idleTimers)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ private void ChatClient_MessageReceived(object sender, MessageReceivedEventArgs
var stopwatch = Stopwatch.StartNew();
try
{
var userName = Tracker.CorrectUserNamePronunciation(e.Message.Sender);
var senderName = Tracker.CorrectUserNamePronunciation(e.Message.SenderUserName);

if (ShouldRespondToGreetings)
TryRespondToGreetings(e.Message, userName);
TryRespondToGreetings(e.Message, senderName);
}
catch (Exception ex)
{
Expand All @@ -89,23 +89,32 @@ private void ChatClient_MessageReceived(object sender, MessageReceivedEventArgs
&& (Tracker.Options.ChatGreetingTimeLimit == 0
|| Tracker.TotalElapsedTime.TotalMinutes <= Tracker.Options.ChatGreetingTimeLimit);

private void TryRespondToGreetings(ChatMessage message, string userName)
private void TryRespondToGreetings(ChatMessage message, string senderName)
{
foreach (var recognizedGreeting in Tracker.Responses.Chat.RecognizedGreetings)
{
if (Regex.IsMatch(message.Text, recognizedGreeting, RegexOptions.IgnoreCase | RegexOptions.Singleline))
{
// Sass if it was the broadcaster
if (message.SenderUserName.Equals(Tracker.Options.UserName)
&& Tracker.Responses.Chat.GreetedChannel != null)
{
Tracker.Say(x => x.Chat.GreetedChannel, senderName);
break;
}

// Otherwise, keep track of the number of times someone said hi
if (_usersGreetedTimes.TryGetValue(message.Sender, out var greeted))
{
if (greeted >= 2)
break;

Tracker.Say(x => x.Chat.GreetedTwice, userName);
Tracker.Say(x => x.Chat.GreetedTwice, senderName);
_usersGreetedTimes[message.Sender]++;
}
else
{
Tracker.Say(x => x.Chat.GreetingResponses, userName);
Tracker.Say(x => x.Chat.GreetingResponses, senderName);
_usersGreetedTimes.Add(message.Sender, 1);
}
break;
Expand Down
4 changes: 3 additions & 1 deletion src/Randomizer.SMZ3.Tracking/VoiceCommands/SpoilerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,9 @@ private GrammarBuilder GetItemSpoilerRule()

return new GrammarBuilder()
.Append("Hey tracker, ")
.OneOf("where is", "where's", "where are", "where can I find")
.OneOf("where is", "where's", "where are", "where can I find",
"where the fuck is", "where the hell is",
"where the heck is")
.Optional("the", "a", "an")
.Append(ItemNameKey, items);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Randomizer.SMZ3.Tracking/VoiceCommands/TrackerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ protected void AddCommand(string ruleName, GrammarBuilder grammarBuilder,
{
Logger.LogInformation("Recognized \"{text}\" with {confidence:P2} confidence.",
e.Result.Text, e.Result.Confidence);
Tracker.RestartIdleTimers();

if (Tracker.SpeechQueueCount >= 1)
Tracker.HandleInterruption();
Expand All @@ -293,6 +294,7 @@ protected void AddCommand(string ruleName, GrammarBuilder grammarBuilder,
// executed, but high enough to be recognized,
// let Tracker say something
Tracker.Say(Tracker.Responses.Misheard);
Tracker.RestartIdleTimers();
}
}
}
Expand Down
Loading

0 comments on commit 1b23fd9

Please sign in to comment.