Skip to content

Commit

Permalink
feat(tsl): add time-related placeholders
Browse files Browse the repository at this point in the history
- Added "resub" name on Twitch Subscription
- Added ${date}, ${date_utc}, ${time_utc} and ${unix} placeholders
- Edited mod description in mods.toml
  • Loading branch information
iGoodie committed Oct 4, 2019
1 parent 14086bd commit d451b0a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
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=1.4.1
mod_version=1.4.2

minecraft_version=1.14.4
forge_version=28.0.83
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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!
'''

Expand Down

0 comments on commit d451b0a

Please sign in to comment.