Skip to content

Commit

Permalink
feat(tsl): add isGifted predicate and placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoodie committed Dec 7, 2019
1 parent b8c6160 commit 1b0c203
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 4 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.

5 changes: 3 additions & 2 deletions .idea/runConfigurations/runClient.xml

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

2 changes: 1 addition & 1 deletion .idea/runConfigurations/runServer.xml

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

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.daemon=false

mod_id=twitchspawn
mod_group=net.programmer.igoodie
mod_version=0.4.8
mod_version=0.4.9

minecraft_version=1.12.2
forge_version=14.23.3.2655
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void execute(ICommandSender commandSender, String[] moduleArgs) throws Co
simulatedEvent.raiderCount = nbt.getInteger("raiders");
simulatedEvent.viewerCount = nbt.getInteger("viewers");
simulatedEvent.subscriptionTier = nbt.hasKey("tier", 3) ? nbt.getInteger("tier") : -1;
simulatedEvent.isGifted = nbt.getBoolean("isGifted");
}

ConfigManager.RULESET_COLLECTION.handleEvent(simulatedEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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 isGifted

// 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 @@ -83,6 +83,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.isGifted = 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 isGifted;

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.isGifted = 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 @@ -33,6 +33,10 @@ public enum TSLPredicateProperty {
"subscriptionTier",
"tier", "subscription_tier"
),
IS_GIFTER(
"isGifted",
"is_gifted"
),
VIEWERS(
"viewerCount",
"viewers", "viewer_count"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public IsComparator(String rightHandRaw) {

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

return leftHand instanceof String
&& value.equalsIgnoreCase((String) leftHand);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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("is_gifted"))
return String.valueOf(args.isGifted);

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

Expand Down

0 comments on commit 1b0c203

Please sign in to comment.