Skip to content

Commit

Permalink
Merge pull request #357 from Rottenbeer/poemap_fix
Browse files Browse the repository at this point in the history
Added support for whispers from poemap.live
  • Loading branch information
Exslims authored Jun 16, 2019
2 parents c81fdc6 + 0d8a00d commit ba5efc5
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ public class MessageParser {
private final static String poeAppPattern = "^(.*\\s)?(.+): (\\s*?wtb\\s+?(.+?)(\\s+?listed for\\s+?([\\d\\.]+?)\\s+?(.+))?\\s+?in\\s+?(.+?)\\s+?\\(stash\\s+?\"(.*?)\";\\s+?left\\s+?(\\d+?),\\s+?top\\s+(\\d+?)\\)\\s*?(.*))$";
private final static String poeAppBulkCurrenciesPattern = "^(.*\\s)?(.+): (\\s*?wtb\\s+?(.+?)(\\s+?listed for\\s+?([\\d\\.]+?)\\s+?(.+))?\\s+?in\\s+?(.+?)\\s+?\\(stash\\s+?\"(.*?)\";\\s+?left\\s+?(\\d+?),\\s+?top\\s+(\\d+?)\\)\\s*?(.*))$";
private final static String poeCurrencyPattern = "^(.*\\s)?(.+): (.+ to buy your (\\d+(\\.\\d+)?)? (.+) for my (\\d+(\\.\\d+)?)? (.+) in (.*?)\\.\\s*(.*))$";
private final static String poeMapLiveRegex = "^(.*\\s)?(.+): (I'd like to exchange my (T\\d+:\\s\\([\\s\\S,]+) for your (T\\d+:\\s\\([\\S,\\s]+) in\\s+?(.+?)\\.)";
private Pattern poeAppItemPattern;
private Pattern poeTradeStashItemPattern;
private Pattern poeTradeItemPattern;
private Pattern poeTradeCurrencyPattern;
private Pattern poeMapLivePattern;

public MessageParser() {
this.poeAppItemPattern = Pattern.compile(poeAppPattern);
this.poeTradeStashItemPattern = Pattern.compile(poeTradeStashTabPattern);
this.poeTradeItemPattern = Pattern.compile(poeTradePattern);
this.poeTradeCurrencyPattern = Pattern.compile(poeCurrencyPattern);
this.poeMapLivePattern = Pattern.compile(poeMapLiveRegex);
}

public NotificationDescriptor parse(String fullMessage) {
Expand Down Expand Up @@ -112,6 +115,20 @@ public NotificationDescriptor parse(String fullMessage) {
tradeNotification.setType(NotificationType.INC_ITEM_MESSAGE);
return tradeNotification;
}
Matcher poeTradeMapLiveMatcher = poeMapLivePattern.matcher(fullMessage);
if (poeTradeMapLiveMatcher.find()) {
ItemTradeNotificationDescriptor tradeNotification = new ItemTradeNotificationDescriptor();
tradeNotification.setWhisperNickname(poeTradeMapLiveMatcher.group(2));
tradeNotification.setSourceString(poeTradeMapLiveMatcher.group(3));
tradeNotification.setItemName(poeTradeMapLiveMatcher.group(5));
tradeNotification.setOffer(poeTradeMapLiveMatcher.group(4));
tradeNotification.setLeague(poeTradeMapLiveMatcher.group(6));
tradeNotification.setType(NotificationType.INC_ITEM_MESSAGE);
tradeNotification.setCurCount(0d);
tradeNotification.setCurrency("");
tradeNotification.setType(NotificationType.INC_ITEM_MESSAGE);
return tradeNotification;
}
return null;
}
}

0 comments on commit ba5efc5

Please sign in to comment.