Skip to content

Commit

Permalink
Merge pull request #35 from C1rdec/us/24
Browse files Browse the repository at this point in the history
Us/24
  • Loading branch information
C1rdec authored Jan 10, 2020
2 parents 6263531 + 1415af3 commit 304745f
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/Lurker.UI/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<appSettings>
<add key="BusyMessage" value="I'm busy at the moment, I'll invite you shortly."/>
<add key="SoldMessage" value="I'm sorry, that item has already been sold."/>
<add key="BusyMessage" value=""/>
<add key="SoldMessage" value=""/>
<add key="StillInterestedMessage" value=""/>
<add key="ThanksMessage" value=""/>
</appSettings>
<startup>
Expand Down
11 changes: 10 additions & 1 deletion src/Lurker.UI/Helpers/MessageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ public static class MessageHelper
{
#region Fields

private static readonly string DefaultStillInterestedMessage = $"Are you still interested in my {TokenHelper.ItemName} listed for {TokenHelper.Price}";
private static readonly string DefaultSoldMessage = $"I'm sorry, my {TokenHelper.ItemName} has already been sold.";

private static readonly Lazy<string> BusyMessageLazy = new Lazy<string>(() => GetSettingValue("BusyMessage", "I'm busy right now I'll send you a party invite."));
private static readonly Lazy<string> SoldMessageLazy = new Lazy<string>(() => GetSettingValue("SoldMessage", "I'm sorry, that item has already been sold."));
private static readonly Lazy<string> SoldMessageLazy = new Lazy<string>(() => GetSettingValue("SoldMessage", DefaultSoldMessage));
private static readonly Lazy<string> StillInterestedMessageLazy = new Lazy<string>(() => GetSettingValue("StillInterestedMessage", DefaultStillInterestedMessage));
private static readonly Lazy<string> ThanksMessageLazy = new Lazy<string>(() => GetSettingValue("ThanksMessage", string.Empty));

#endregion
Expand All @@ -39,6 +43,11 @@ public static class MessageHelper
/// </summary>
public static string ThanksMessage => ThanksMessageLazy.Value;

/// <summary>
/// Gets the still interested message.
/// </summary>
public static string StillInterestedMessage => StillInterestedMessageLazy.Value;

#endregion

#region Methods
Expand Down
40 changes: 40 additions & 0 deletions src/Lurker.UI/Helpers/TokenHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//-----------------------------------------------------------------------
// <copyright file="TokenHelper.cs" company="Wohs">
// Missing Copyright information from a valid stylecop.json file.
// </copyright>
//-----------------------------------------------------------------------

namespace Lurker.UI.Helpers
{
using Lurker.UI.ViewModels;
using System.Text.RegularExpressions;

public static class TokenHelper
{
#region Fields

public static readonly string ItemName = "{ItemName}";
public static readonly string BuyerName = "{BuyerName}";
public static readonly string Price = "{Price}";

#endregion

#region Methods

/// <summary>
/// Replaces the token.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="offer">The offer.</param>
/// <returns>The string with token replaced</returns>
public static string ReplaceToken(string message, OfferViewModel offer)
{
message = Regex.Replace(message, ItemName, offer.ItemName, RegexOptions.IgnoreCase);
message = Regex.Replace(message, BuyerName, offer.PlayerName, RegexOptions.IgnoreCase);
message = Regex.Replace(message, Price, offer.Price.ToString(), RegexOptions.IgnoreCase);
return message;
}

#endregion
}
}
1 change: 1 addition & 0 deletions src/Lurker.UI/Lurker.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<Compile Include="Helpers\KeyboardHelper.cs" />
<Compile Include="Helpers\MessageHelper.cs" />
<Compile Include="Helpers\PoeKeyboardHelper.cs" />
<Compile Include="Helpers\TokenHelper.cs" />
<Compile Include="Models\TradebarContext.cs" />
<Compile Include="Native.cs" />
<Compile Include="Svg.cs">
Expand Down
4 changes: 2 additions & 2 deletions src/Lurker.UI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]
33 changes: 30 additions & 3 deletions src/Lurker.UI/ViewModels/OfferViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public OfferViewModel(TradeEvent tradeEvent, PoeKeyboardHelper keyboardHelper, T
/// </summary>
public CurrencyType CurrencyType => this._tradeEvent.Price.CurrencyType;

/// <summary>
/// Gets the price.
/// </summary>
public Price Price => this._tradeEvent.Price;

/// <summary>
/// Gets or sets a value indicating whether this instance is invite sended.
/// </summary>
Expand Down Expand Up @@ -158,15 +163,14 @@ public void Wait()
{
this._skipMainAction = true;
this.Waiting = true;
this._keyboardHelper.Whisper(this.PlayerName, MessageHelper.BusyMessage);
this.Whisper(MessageHelper.BusyMessage);
}

/// <summary>
/// Answers this instance.
/// </summary>
public void MainAction()
{
// Alt cannot be use since we send Enter to the Keyboard
if (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))
{
this._tradebarContext.SetActiveOffer(this);
Expand All @@ -181,6 +185,12 @@ public void MainAction()

if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
{
this.StillInterested();
return;
}

this.Sold();
return;
}
Expand All @@ -202,10 +212,18 @@ public void MainAction()
/// </summary>
private void Sold()
{
this._keyboardHelper.Whisper(this.PlayerName, MessageHelper.SoldMessage);
this.Whisper(MessageHelper.SoldMessage);
this.RemoveFromTradebar();
}

/// <summary>
/// Stills the interested.
/// </summary>
private void StillInterested()
{
this.Whisper(MessageHelper.StillInterestedMessage);
}

/// <summary>
/// Invites the buyer.
/// </summary>
Expand Down Expand Up @@ -233,6 +251,15 @@ private void RemoveFromTradebar()
this._tradebarContext.RemoveOffer(this);
}

/// <summary>
/// Whispers the specified message.
/// </summary>
/// <param name="message">The message.</param>
private void Whisper(string message)
{
this._keyboardHelper.Whisper(this.PlayerName, TokenHelper.ReplaceToken(message, this));
}

#endregion
}
}
11 changes: 10 additions & 1 deletion src/Lurker/Events/TradeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public TradeEvent(string logLine)

var greetingMarker = GreetingMarkers.FirstOrDefault(m => this.Message.Contains(m));
this.ItemName = this.Message.Substring(greetingMarker.Length + 1, textBeforeMarker.Length - greetingMarker.Length -2);
this.SimplifyItemName();

// Location
var locationMarkerIndex = this.Message.IndexOf(LocationMarker);
Expand Down Expand Up @@ -128,7 +129,15 @@ public static Price ParsePrice(string priceValue)
};
}

#endregion
private void SimplifyItemName()
{
var mapTierIndex = this.ItemName.IndexOf(" (T");
if (mapTierIndex != -1)
{
this.ItemName = this.ItemName.Substring(0, mapTierIndex);
}
}

#endregion
}
}

0 comments on commit 304745f

Please sign in to comment.