Skip to content

Commit

Permalink
feat(tsl): add gifted placeholder and predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoodie committed Dec 8, 2019
1 parent afaa14a commit 9cf7109
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public static int simulateModule(CommandContext<CommandSource> context, String s
simulatedEvent.raiderCount = nbt.getInt("raiders");
simulatedEvent.viewerCount = nbt.getInt("viewers");
simulatedEvent.subscriptionTier = nbt.contains("tier", 3) ? nbt.getInt("tier") : -1;
simulatedEvent.gifted = nbt.getBoolean("gifted");
}

ConfigManager.RULESET_COLLECTION.handleEvent(simulatedEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ protected void onLiveEvent(Socket socket, CredentialsConfig.Streamer streamer, O
// eventArguments.raiderCount = JSONUtils.extractNumberFrom(message, "raiders", 0).intValue(); // Raids aren't supported (?)
eventArguments.viewerCount = JSONUtils.extractNumberFrom(data, "amount ", 0).intValue();
eventArguments.subscriptionTier = extractTier(data, "tier");
// TODO: add gifted

// Pass the model to the handler
ConfigManager.RULESET_COLLECTION.handleEvent(eventArguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ protected void onLiveEvent(Socket socket, CredentialsConfig.Streamer streamer, O
eventArguments.raiderCount = JSONUtils.extractNumberFrom(message, "raiders", 0).intValue();
eventArguments.viewerCount = JSONUtils.extractNumberFrom(message, "viewers", 0).intValue();
eventArguments.subscriptionTier = extractTier(message, "sub_plan");
eventArguments.gifted = JSONUtils.extractFrom(message, "gifter_twitch_id", String.class, null) != null;

// Pass the model to the handler
ConfigManager.RULESET_COLLECTION.handleEvent(eventArguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static EventArguments createRandom(String streamerNickname) {

public int subscriptionMonths;
public int subscriptionTier = -1; // 0=Prime, 1=T1, 2=T2, 3=T3
public boolean gifted;

public int viewerCount;
public int raiderCount;
Expand Down Expand Up @@ -60,6 +61,7 @@ public void randomize(String actorNickname, String message) {
this.donationCurrency = new String[]{"USD", "TRY", "EUR"}[random.nextInt(3)];
this.subscriptionMonths = random.nextInt(100 - 1) + 1;
this.subscriptionTier = random.nextInt(3 + 1);
this.gifted = random.nextBoolean();
this.viewerCount = random.nextInt(100 - 1) + 1;
this.raiderCount = random.nextInt(100 - 1) + 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public enum TSLComparatorSymbol {

IN_RANGE(
"IN RANGE", InRangeComparator.class),
IS(
"IS", IsComparator.class),
PREFIX(
"PREFIX", PrefixComparator.class),
POSTFIX(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public enum TSLPredicateProperty {
"subscriptionTier",
"tier", "subscription_tier"
),
GIFTED(
"gifted",
"gifted"
),
VIEWERS(
"viewerCount",
"viewers", "viewer_count"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

package net.programmer.igoodie.twitchspawn.tslanguage.predicate;

public class IsComparator extends TSLComparator {

protected String value;

public IsComparator(String rightHandRaw) {
this.value = rightHandRaw;
}

@Override
public boolean compare(Object leftHand) {
if (leftHand instanceof Boolean)
return leftHand.toString().equalsIgnoreCase(value);

return leftHand instanceof String
&& value.equalsIgnoreCase((String) leftHand);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public static String fromArgs(String expression, EventArguments args) {
if (expression.equals("tier") && args.subscriptionTier != -1)
return args.subscriptionTier == 0 ? "Prime" : String.valueOf(args.subscriptionTier);

if (expression.equals("gifted"))
return String.valueOf(args.gifted);

if (expression.equals("viewers") && args.viewerCount != 0)
return String.valueOf(args.viewerCount);

Expand Down

0 comments on commit 9cf7109

Please sign in to comment.