From d451b0a491fa240813b8fc8ab529056293cdf5f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C4=B1lcan?= Date: Fri, 4 Oct 2019 17:10:59 +0300 Subject: [PATCH] feat(tsl): add time-related placeholders - Added "resub" name on Twitch Subscription - Added ${date}, ${date_utc}, ${time_utc} and ${unix} placeholders - Edited mod description in mods.toml --- gradle.properties | 2 +- .../tslanguage/keyword/TSLEventKeyword.java | 3 ++- .../twitchspawn/util/ExpressionEvaluator.java | 23 ++++++++++++++++++- src/main/resources/META-INF/mods.toml | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 674f76e..23b6edf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ org.gradle.daemon=false mod_id=twitchspawn mod_group=net.programmer.igoodie -mod_version=1.4.1 +mod_version=1.4.2 minecraft_version=1.14.4 forge_version=28.0.83 diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLEventKeyword.java b/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLEventKeyword.java index 12db7fc..72df086 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLEventKeyword.java +++ b/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLEventKeyword.java @@ -22,7 +22,8 @@ public enum TSLEventKeyword { TWITCH_SUBSCRIPTION( "Twitch Subscription", new TSLEventPair("subscription", "twitch"), - new TSLEventPair("subscriber", "twitch") + new TSLEventPair("subscriber", "twitch"), + new TSLEventPair("resub", "twitch") ), TWITCH_HOST( "Twitch Host", diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/util/ExpressionEvaluator.java b/src/main/java/net/programmer/igoodie/twitchspawn/util/ExpressionEvaluator.java index af0f48e..b056226 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/util/ExpressionEvaluator.java +++ b/src/main/java/net/programmer/igoodie/twitchspawn/util/ExpressionEvaluator.java @@ -2,8 +2,11 @@ import net.programmer.igoodie.twitchspawn.tslanguage.EventArguments; +import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.time.Instant; import java.util.Date; +import java.util.TimeZone; import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -65,10 +68,28 @@ public static String fromArgs(String expression, EventArguments args) { if (expression.equals("raiders") && args.raiderCount != 0) return String.valueOf(args.raiderCount); + if (expression.equals("date")) + return getDateFormat("dd-MM-yyyy", TimeZone.getDefault()).format(new Date()); + + if (expression.equals("date_utc")) + return getDateFormat("dd-MM-yyyy", TimeZone.getTimeZone("UTC")).format(new Date()); + if (expression.equals("time")) - return new SimpleDateFormat("HH:mm:ss").format(new Date()); + return getDateFormat("HH:mm:ss", TimeZone.getDefault()).format(new Date()); + + if (expression.equals("time_utc")) + return getDateFormat("HH:mm:ss", TimeZone.getTimeZone("UTC")).format(new Date()); + + if (expression.equals("unix")) + return String.valueOf(Instant.now().getEpochSecond()); return null; } + private static DateFormat getDateFormat(String format, TimeZone timezone) { + DateFormat dateFormat = new SimpleDateFormat(format); + dateFormat.setTimeZone(timezone); + return dateFormat; + } + } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 1a40cee..2c7d2a6 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -9,7 +9,7 @@ displayName="TwitchSpawn" authors="iGoodie" logoFile="pack.png" description=''' - TwitchSpawn listens for live events related to your Twitch channel using Streamlabs Socket API. + TwitchSpawn listens for live events related to your Twitch channel using various Socket APIs. Then it handles those events with the rules handcrafted by you! '''