diff --git a/API/src/main/java/io/github/jwdeveloper/tiktok/data/models/gifts/Gift.java b/API/src/main/java/io/github/jwdeveloper/tiktok/data/models/gifts/Gift.java
index dfd7a2f..6217fe9 100644
--- a/API/src/main/java/io/github/jwdeveloper/tiktok/data/models/gifts/Gift.java
+++ b/API/src/main/java/io/github/jwdeveloper/tiktok/data/models/gifts/Gift.java
@@ -7,9 +7,8 @@ import lombok.*;
import java.util.*;
@Data
-@AllArgsConstructor
public class Gift {
- public static final Gift UNDEFINED = new Gift(-1, "undefined", -1, "", null);
+ public static final Gift UNDEFINED = new Gift(-1, "undefined", -1, "");
private final int id;
@@ -21,28 +20,21 @@ public class Gift {
private final JsonObject properties;
- public Gift(int id, String name, int diamondCost, String pictureLink, JsonObject properties) {
+ public Gift(int id, String name, int diamondCost, Picture pictureLink, JsonObject properties) {
this.id = id;
this.name = name;
this.diamondCost = diamondCost;
- this.picture = new Picture(pictureLink);
+ this.picture = pictureLink;
this.properties = properties;
}
+
public Gift(int id, String name, int diamondCost, String pictureLink) {
- this.id = id;
- this.name = name;
- this.diamondCost = diamondCost;
- this.picture = new Picture(pictureLink);
- this.properties = new JsonObject();
+ this(id, name, diamondCost, new Picture(pictureLink), new JsonObject());
}
public Gift(int id, String name, int diamondCost, Picture picture) {
- this.id = id;
- this.name = name;
- this.diamondCost = diamondCost;
- this.picture = picture;
- this.properties = new JsonObject();
+ this(id, name, diamondCost, picture, new JsonObject());
}
public boolean hasDiamondCostRange(int minimalCost, int maximalCost) {
diff --git a/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLive.java b/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLive.java
index d26e1db..941a3ef 100644
--- a/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLive.java
+++ b/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLive.java
@@ -93,6 +93,8 @@ public class TikTokLive {
}
+ private static GiftsManager giftsManager;
+
/**
* Fetch gifts from endpoint and returns GiftManager
*
@@ -100,17 +102,20 @@ public class TikTokLive {
*/
public static GiftsManager gifts()
{
- return new TikTokGiftsManager(requests().fetchGiftsData().getGifts());
+ if(giftsManager != null)
+ {
+ return giftsManager;
+ }
+
+ try
+ {
+ giftsManager = new TikTokGiftsManager(requests().fetchGiftsData().getGifts());
+ return giftsManager;
+ } catch (Exception ex)
+ {
+ throw ex;
+ }
}
- /**
- * @param fetchGifts fetch gifts from internet or return empty giftManager
- * @return
- */
- public static GiftsManager gifts(boolean fetchGifts) {
- if (fetchGifts) {
- return gifts();
- }
- return new TikTokGiftsManager(List.of());
- }
+
}
\ No newline at end of file
diff --git a/Client/src/main/java/io/github/jwdeveloper/tiktok/http/mappers/GiftsDataMapper.java b/Client/src/main/java/io/github/jwdeveloper/tiktok/http/mappers/GiftsDataMapper.java
index 5518eb1..6f64425 100644
--- a/Client/src/main/java/io/github/jwdeveloper/tiktok/http/mappers/GiftsDataMapper.java
+++ b/Client/src/main/java/io/github/jwdeveloper/tiktok/http/mappers/GiftsDataMapper.java
@@ -24,6 +24,7 @@ package io.github.jwdeveloper.tiktok.http.mappers;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
+import io.github.jwdeveloper.tiktok.data.models.Picture;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
import io.github.jwdeveloper.tiktok.data.requests.GiftsData;
@@ -48,7 +49,7 @@ public class GiftsDataMapper {
var id = jsonObject.get("id").getAsInt();
var name = jsonObject.get("name").getAsString();
var diamondCost = jsonObject.get("diamondCost").getAsInt();
- var image =jsonObject.get("image").getAsString();
- return new Gift(id, name, diamondCost, image, jsonObject);
+ var image = jsonObject.get("image").getAsString();
+ return new Gift(id, name, diamondCost, new Picture(image), jsonObject);
}
}
diff --git a/Tools-ReadmeGenerator/pom.xml b/Tools-ReadmeGenerator/pom.xml
index f1ab6b8..0348b03 100644
--- a/Tools-ReadmeGenerator/pom.xml
+++ b/Tools-ReadmeGenerator/pom.xml
@@ -41,5 +41,11 @@
0.9.12
compile
+
+ io.github.jwdeveloper.tiktok
+ Client
+ 1.3.0-Release
+ compile
+
\ No newline at end of file
diff --git a/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/CodeExample.java b/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/CodeExample.java
index f81db55..9aa9ecc 100644
--- a/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/CodeExample.java
+++ b/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/CodeExample.java
@@ -41,11 +41,12 @@ public class CodeExample {
TikTokLive.newClient("bangbetmenygy")
.onGift((liveClient, event) ->
{
- String message = switch (event.getGift()) {
- case ROSE -> "ROSE!";
- case GG -> "GOOD GAME";
- case TIKTOK -> "Ye";
- case CORGI -> "Nice gift";
+ String message = switch (event.getGift().getName())
+ {
+ case "Rose" -> "ROSE!";
+ case "Good game" -> "GOOD GAME";
+ case "Ye" -> "Ye";
+ case "Nice gift" -> "Nice gift";
default -> "Thank you for " + event.getGift().getName();
};
System.out.println(event.getUser().getProfileName() + " sends " + message);
diff --git a/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/CodeExamplesGenerator.java b/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/CodeExamplesGenerator.java
index dbe6740..c598684 100644
--- a/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/CodeExamplesGenerator.java
+++ b/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/CodeExamplesGenerator.java
@@ -22,8 +22,7 @@
*/
package io.github.jwdeveloper.tiktok;
-import io.github.jwdeveloper.tiktok.utils.FilesUtility;
-import io.github.jwdeveloper.tiktok.utils.TemplateUtility;
+
import java.util.HashMap;
import java.util.regex.Pattern;
diff --git a/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/EventsInfoGenerator.java b/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/EventsInfoGenerator.java
index b171415..eb6f398 100644
--- a/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/EventsInfoGenerator.java
+++ b/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/EventsInfoGenerator.java
@@ -27,8 +27,7 @@ import io.github.jwdeveloper.tiktok.annotations.EventType;
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftEvent;
import io.github.jwdeveloper.tiktok.live.builder.EventsBuilder;
-import io.github.jwdeveloper.tiktok.utils.FilesUtility;
-import io.github.jwdeveloper.tiktok.utils.TemplateUtility;
+
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.reflections.Reflections;
diff --git a/Tools/src/main/java/io/github/jwdeveloper/tiktok/utils/FilesUtility.java b/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/FilesUtility.java
similarity index 94%
rename from Tools/src/main/java/io/github/jwdeveloper/tiktok/utils/FilesUtility.java
rename to Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/FilesUtility.java
index f41c37a..a776a74 100644
--- a/Tools/src/main/java/io/github/jwdeveloper/tiktok/utils/FilesUtility.java
+++ b/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/FilesUtility.java
@@ -1,3 +1,4 @@
+
/*
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
*
@@ -20,7 +21,7 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-package io.github.jwdeveloper.tiktok.utils;
+package io.github.jwdeveloper.tiktok;
import java.io.File;
import java.io.IOException;
@@ -37,7 +38,7 @@ public class FilesUtility
public static List getFiles(String input) {
Path path = Paths.get(input);
try (Stream paths = Files.list(path)) {
- return paths.filter(Files::isRegularFile).toList();
+ return paths.filter(Files::isRegularFile).toList();
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -96,13 +97,13 @@ public class FilesUtility
file.createNewFile();
} catch (IOException e)
{
- e.printStackTrace();
+ e.printStackTrace();
}
}
}
- public static String loadFileContent(String path) {
+ public static String loadFileContent(String path) {
ensureFile(path);
Path pathh = Paths.get(path);
try {
diff --git a/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/ReadmeGenerator.java b/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/ReadmeGenerator.java
index b5a1d29..b61d883 100644
--- a/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/ReadmeGenerator.java
+++ b/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/ReadmeGenerator.java
@@ -21,10 +21,6 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package io.github.jwdeveloper.tiktok;
-
-import io.github.jwdeveloper.tiktok.utils.FilesUtility;
-import io.github.jwdeveloper.tiktok.utils.TemplateUtility;
-
import java.util.HashMap;
public class ReadmeGenerator {
diff --git a/Tools/src/main/java/io/github/jwdeveloper/tiktok/utils/TemplateUtility.java b/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/TemplateUtility.java
similarity index 82%
rename from Tools/src/main/java/io/github/jwdeveloper/tiktok/utils/TemplateUtility.java
rename to Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/TemplateUtility.java
index 19ebea1..a8915c7 100644
--- a/Tools/src/main/java/io/github/jwdeveloper/tiktok/utils/TemplateUtility.java
+++ b/Tools-ReadmeGenerator/src/main/java/io/github/jwdeveloper/tiktok/TemplateUtility.java
@@ -1,3 +1,4 @@
+
/*
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
*
@@ -20,24 +21,21 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-package io.github.jwdeveloper.tiktok.utils;
+package io.github.jwdeveloper.tiktok;
import java.util.Map;
-public class TemplateUtility
-{
+public class TemplateUtility {
public static String generateTemplate(String template, Map values) {
- for(var entry : values.entrySet())
- {
- template = doReplacement(template,entry.getKey(), entry.getValue().toString());
+ for (var entry : values.entrySet()) {
+ template = doReplacement(template, entry.getKey(), entry.getValue().toString());
}
return template;
}
- private static String doReplacement(String template, String keyword, String value)
- {
- var key = "(\\{\\{)"+keyword+"(}})";
+ private static String doReplacement(String template, String keyword, String value) {
+ var key = "(\\{\\{)" + keyword + "(}})";
return template.replaceAll(key, value);
}
diff --git a/Tools/pom.xml b/Tools/pom.xml
deleted file mode 100644
index 08f1609..0000000
--- a/Tools/pom.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-
-
-
- TikTokLiveJava
- io.github.jwdeveloper.tiktok
- 1.3.0-Release
-
- 4.0.0
-
- Tools
-
-
- org.projectlombok
- lombok
- 1.18.22
- compile
-
-
- com.squareup
- javapoet
- 1.13.0
-
-
-
- org.reflections
- reflections
- 0.9.12
-
-
- io.github.jwdeveloper.tiktok
- API
- ${project.version}
- compile
-
-
- org.jsoup
- jsoup
- 1.13.1
-
-
- io.github.jwdeveloper.tiktok
- Client
- ${project.version}
- compile
-
-
- org.jsoup
- jsoup
- 1.14.3
-
-
-
-
- 16
- 16
- UTF-8
-
-
-
\ No newline at end of file
diff --git a/Tools/src/main/java/io/github/jwdeveloper/tiktok/EventsGeneratorRun.java b/Tools/src/main/java/io/github/jwdeveloper/tiktok/EventsGeneratorRun.java
deleted file mode 100644
index 94cfa29..0000000
--- a/Tools/src/main/java/io/github/jwdeveloper/tiktok/EventsGeneratorRun.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-package io.github.jwdeveloper.tiktok;
-
-import io.github.jwdeveloper.tiktok.events_generator.EventGeneratorSettings;
-import io.github.jwdeveloper.tiktok.events_generator.EventsGenerator;
-
-import java.io.IOException;
-
-public class EventsGeneratorRun {
-
- private static boolean lock = false;
-
- //Run objects
- public static void main(String[] args) throws IOException {
-
- if(lock)
- {
- return;
- }
- //generatesObjects()
- // generateEventsMessages();
- }
-
-
- private static void generatesEventsObjects() throws IOException {
- var settings = new EventGeneratorSettings();
- settings.setTikTokEvent(false);
- settings.setInputDictionary("C:\\Users\\ja\\RiderProjects\\TikTokLiveSharp\\TikTokLiveSharp\\Events\\Objects");
- settings.setOutputDictionary("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\API\\src\\main\\java\\io\\github\\jwdeveloper\\tiktok\\events\\objects");
- var generator = new EventsGenerator();
- generator.compile(settings);
- }
-
- private static void generateEventsMessages() throws IOException {
- var settings = new EventGeneratorSettings();
- settings.setTikTokEvent(true);
- settings.setPrefix("TikTok");
- settings.setEndFix("Event");
- settings.setInputDictionary("C:\\Users\\ja\\RiderProjects\\TikTokLiveSharp\\TikTokLiveSharp\\Events\\Messages");
- settings.setOutputDictionary("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\API\\src\\main\\java\\io\\github\\jwdeveloper\\tiktok\\events\\messages");
- var generator = new EventsGenerator();
- generator.compile(settings);
- }
-
-
-}
diff --git a/Tools/src/main/java/io/github/jwdeveloper/tiktok/EventsInterfaceGeneratorRun.java b/Tools/src/main/java/io/github/jwdeveloper/tiktok/EventsInterfaceGeneratorRun.java
deleted file mode 100644
index 3426b34..0000000
--- a/Tools/src/main/java/io/github/jwdeveloper/tiktok/EventsInterfaceGeneratorRun.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-package io.github.jwdeveloper.tiktok;
-
-import io.github.jwdeveloper.tiktok.events_generator.EventGeneratorSettings;
-import io.github.jwdeveloper.tiktok.intefacee.EventsInterfaceGenerator;
-
-import java.io.IOException;
-
-public class EventsInterfaceGeneratorRun
-{
- public static void main(String[] args) throws IOException {
- var settings = new EventGeneratorSettings();
- settings.setTikTokEvent(true);
- settings.setPrefix("TikTok");
- settings.setEndFix("Event");
- settings.setInputDictionary("C:\\Users\\ja\\RiderProjects\\TikTokLiveSharp\\TikTokLiveSharp\\Events\\Messages");
- settings.setOutputDictionary("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\API\\src\\main\\java\\io\\github\\jwdeveloper\\tiktok\\events\\messages");
- var generator = new EventsInterfaceGenerator();
- generator.compile(settings);
- }
-}
diff --git a/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/CSharpClassInfo.java b/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/CSharpClassInfo.java
deleted file mode 100644
index 1c1c888..0000000
--- a/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/CSharpClassInfo.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-package io.github.jwdeveloper.tiktok.events_generator;
-
-import lombok.Data;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Data
-public class CSharpClassInfo
-{
- private String className;
- private List fields = new ArrayList<>();
- private List constructors = new ArrayList<>();
-
- public void addField(String type, String fields)
- {
- this.fields.add(new FieldInfo(type,fields));
- }
-
- public void addConstructor(List arguments)
- {
- this.constructors.add(new ConstructorInfo(arguments));
- }
-
- public record FieldInfo(String type, String name){};
-
- public record ConstructorInfo(List arguemtns){};
-}
diff --git a/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/CSharpClassParser.java b/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/CSharpClassParser.java
deleted file mode 100644
index cae7a4e..0000000
--- a/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/CSharpClassParser.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-package io.github.jwdeveloper.tiktok.events_generator;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class CSharpClassParser {
- private CSharpClassInfo classInfo;
-
- public CSharpClassInfo parse(Path filePath) throws IOException {
- classInfo = new CSharpClassInfo();
-
- List lines = Files.readAllLines(filePath);
- String content = String.join("\n", lines);
- parseClassName(content);
- parseFields(content);
- parseConstructors(content);
- return classInfo;
- }
-
-
- private void parseClassName(String content) {
- Pattern pattern = Pattern.compile("\\b(?:sealed )?class\\s+(\\w+)");
- Matcher matcher = pattern.matcher(content);
- if (matcher.find()) {
- classInfo.setClassName(matcher.group(1));
- }
- }
-
- private void parseFields(String content) {
- Pattern pattern = Pattern.compile("\\b(public|private|protected)\\s+(readonly\\s+)?(\\w+\\.?\\w*)\\s+(\\w+);");
- Matcher matcher = pattern.matcher(content);
- while (matcher.find()) {
- var typeName = mapTypeToJava(matcher.group(3));
- var name = lowerCaseFirstLetter(matcher.group(4));
- classInfo.addField(typeName, name);
- }
- }
-
- private void parseConstructors(String content) {
- Pattern pattern = Pattern.compile("\\b(public|private|protected|internal)\\s+" + classInfo.getClassName() + "\\s*\\(([^)]*)\\)");
- Matcher matcher = pattern.matcher(content);
- while (matcher.find()) {
- List args = new ArrayList<>();
- String[] arguments = matcher.group(2).split(",");
- for (String argument : arguments) {
- if (argument.trim().length() > 0) {
- String[] parts = argument.trim().split("\\s+");
-
- if (parts.length != 2) {
- args.add(new CSharpClassInfo.FieldInfo("Object", "error"));
- continue;
- }
- var typeName = mapTypeToJava(parts[0]);
- var name = lowerCaseFirstLetter(parts[1]);
- args.add(new CSharpClassInfo.FieldInfo(typeName, name));
- }
- }
- classInfo.addConstructor(args);
- }
- }
-
-
- public String mapTypeToJava(String type) {
- if (type.equals("string")) {
- return "String";
- }
- if (type.equals("uint")) {
- return "Integer";
- }
- if (type.equals("int")) {
- return "Integer";
- }
- if (type.equals("ulong")) {
- return "Long";
- }
- if (type.equals("bool")) {
- return "Boolean";
- }
- if (type.contains("Models.Protobuf.Objects")) {
- return type.replace("Models.Protobuf.Objects", "io.github.jwdeveloper.tiktok.messages");
- }
-
- if(type.contains("Objects."))
- {
- return type.replace("Objects.","io.github.jwdeveloper.tiktok.events.objects.");
- }
- return type;
- }
-
- public static String lowerCaseFirstLetter(String str) {
- if (str == null || str.isEmpty()) {
- return str; // Return original string if it is empty or null
- }
- return Character.toLowerCase(str.charAt(0)) + str.substring(1);
- }
-
-}
diff --git a/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/EventGeneratorSettings.java b/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/EventGeneratorSettings.java
deleted file mode 100644
index 96203cb..0000000
--- a/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/EventGeneratorSettings.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-package io.github.jwdeveloper.tiktok.events_generator;
-
-import lombok.Data;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Data
-public class EventGeneratorSettings
-{
- private String inputDictionary;
-
- private String outputDictionary;
- private List ignoredFiles = new ArrayList<>();
-
- private String prefix;
-
- private String endFix;
-
- private boolean isTikTokEvent;
-
- public void addIgnoredClass(String name)
- {
- ignoredFiles.add(name);
- }
-}
diff --git a/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/EventsGenerator.java b/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/EventsGenerator.java
deleted file mode 100644
index b117220..0000000
--- a/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/EventsGenerator.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-package io.github.jwdeveloper.tiktok.events_generator;
-
-import io.github.jwdeveloper.tiktok.utils.FilesUtility;
-
-import java.io.File;
-import java.io.IOException;
-
-public class EventsGenerator
-{
-
-
- public void compile(EventGeneratorSettings settings) throws IOException {
- var files = FilesUtility.getFiles(settings.getInputDictionary());
-
- var packageName = convertToPackageName(settings.getOutputDictionary());
- for(var file : files)
- {
- var fileName = file.getFileName().toString();
- if(settings.getIgnoredFiles().contains(fileName))
- {
- continue;
- }
- if(fileName.contains("meta"))
- {
- continue;
- }
-
- var parser = new CSharpClassParser();
- var cSharpClass =parser.parse(file);
-
- var name = settings.getPrefix()+cSharpClass.getClassName()+settings.getEndFix();
- cSharpClass.setClassName(name);
- var javaClassGenerator = new JavaClassGenerator();
-
-
- var result =javaClassGenerator.generate(cSharpClass, packageName,settings);
- System.out.println(result);
-
- var path = settings.getOutputDictionary()+ File.separator+cSharpClass.getClassName()+".java";
- FilesUtility.saveFile(path, result);
- }
-
- }
-
-
- public static String convertToPackageName(String path) {
- String marker = "src\\main\\java\\";
- int index = path.indexOf(marker);
-
- if (index != -1) {
- String packagePath = path.substring(index + marker.length());
- return packagePath.replace('\\', '.');
- }
-
- return null;
- }
-}
diff --git a/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/JavaClassGenerator.java b/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/JavaClassGenerator.java
deleted file mode 100644
index 43ef17f..0000000
--- a/Tools/src/main/java/io/github/jwdeveloper/tiktok/events_generator/JavaClassGenerator.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-package io.github.jwdeveloper.tiktok.events_generator;
-
-import com.squareup.javapoet.*;
-import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
-import lombok.Getter;
-
-import javax.lang.model.element.Modifier;
-
-
-public class JavaClassGenerator {
- public String generate(CSharpClassInfo cSharpClassInfo, String packageName, EventGeneratorSettings settings) {
-
- TypeSpec.Builder classBuilder = TypeSpec.classBuilder(cSharpClassInfo.getClassName())
- .addAnnotation(Getter.class);
- if (settings.isTikTokEvent()) {
- classBuilder.superclass(TikTokEvent.class);
- }
- classBuilder.addModifiers(Modifier.PUBLIC);
-
- // Generate fields
- for (var field : cSharpClassInfo.getFields()) {
-
- FieldSpec fieldSpec = FieldSpec.builder(ClassName.bestGuess(field.type()), field.name(), Modifier.PRIVATE).build();
- classBuilder.addField(fieldSpec);
- }
-
- // Generate constructors
- for (var constructor : cSharpClassInfo.getConstructors()) {
- MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder();
-
- if(settings.isTikTokEvent())
- {
- constructorBuilder.addStatement("super(msg.getHeader());") ;
- }
-
- constructorBuilder.addModifiers(Modifier.PUBLIC);
- for (var arg : constructor.arguemtns()) {
- constructorBuilder.addParameter(ClassName.bestGuess(arg.type()), arg.name());
- }
- classBuilder.addMethod(constructorBuilder.build());
- }
-
- // Generate Java class
- TypeSpec javaClass = classBuilder.build();
- var result = JavaFile.builder(packageName, javaClass).build();
- return result.toString();
- }
-}
diff --git a/Tools/src/main/java/io/github/jwdeveloper/tiktok/gifts/GenerateGiftsEnum.java b/Tools/src/main/java/io/github/jwdeveloper/tiktok/gifts/GenerateGiftsEnum.java
deleted file mode 100644
index 6533779..0000000
--- a/Tools/src/main/java/io/github/jwdeveloper/tiktok/gifts/GenerateGiftsEnum.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-package io.github.jwdeveloper.tiktok.gifts;
-
-import com.squareup.javapoet.JavaFile;
-import com.squareup.javapoet.MethodSpec;
-import com.squareup.javapoet.TypeSpec;
-import io.github.jwdeveloper.tiktok.TikTokLive;
-import io.github.jwdeveloper.tiktok.data.models.Picture;
-import io.github.jwdeveloper.tiktok.gifts.downloader.GiftDto;
-import lombok.Getter;
-
-import javax.lang.model.element.Modifier;
-import java.io.File;
-import java.io.IOException;
-import java.time.Duration;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-
-public class GenerateGiftsEnum {
-
- public static void main(String args[]) throws IOException {
-
-
-
- TikTokLive.newClient("X")
- .configure(liveClientSettings ->
- {
- var httpSetting = liveClientSettings.getHttpSettings();
- httpSetting.setTimeout(Duration.ofSeconds(12));
- });
-
- var downloader = new GiftsDownloader();
- var gifts = downloader.getGiftsFromFile();
- for (var link : gifts) {
- System.out.println(link.getImage());
- }
- var groupedByName = gifts.stream().collect(Collectors.groupingBy(GiftDto::getName));
- System.out.println("Total gifts" + gifts.size());
- var result = generate(groupedByName);
- result.writeTo(new File("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\API\\src\\main\\java"));
- System.out.println("DONE");
- }
-
-
- public static JavaFile generate(Map> giftInfoMap) {
- var enumBuilder = TypeSpec.enumBuilder("Gift")
- .addModifiers(Modifier.PUBLIC)
- .addAnnotation(Getter.class)
- .addField(int.class, "id", Modifier.PRIVATE, Modifier.FINAL)
- .addField(String.class, "name", Modifier.PRIVATE, Modifier.FINAL)
- .addField(int.class, "diamondCost", Modifier.PRIVATE, Modifier.FINAL)
- .addField(Picture.class, "picture", Modifier.PRIVATE, Modifier.FINAL);
-
- var constructor = MethodSpec.constructorBuilder()
- .addModifiers(Modifier.PRIVATE)
- .addParameter(int.class, "id")
- .addParameter(String.class, "name")
- .addParameter(int.class, "diamondCost")
- .addParameter(String.class, "pictureLink")
- .addStatement("this.id = id")
- .addStatement("this.name = name")
- .addStatement("this.diamondCost = diamondCost")
- .addStatement("this.picture = new Picture(pictureLink)")
- .build();
-
- var inRangeMethod = MethodSpec.methodBuilder("hasDiamondCostRange")
- .addModifiers(Modifier.PUBLIC)
- .addParameter(int.class, "minimalCost")
- .addParameter(int.class, "maximalCost")
- .addStatement(" return diamondCost >= minimalCost && diamondCost <= maximalCost")
- .returns(boolean.class);
-
- var hasCostMethod = MethodSpec.methodBuilder("hasDiamondCost")
- .addModifiers(Modifier.PUBLIC)
- .addParameter(int.class, "cost")
- .addStatement(" return diamondCost == cost")
- .returns(boolean.class);
-
- enumBuilder.addMethod(inRangeMethod.build());
- enumBuilder.addMethod(hasCostMethod.build());
- enumBuilder.addMethod(constructor);
-
-
- enumBuilder.addEnumConstant("UNDEFINED", addGift(-1, "undefined", -1, ""));
- for (var giftInfo : giftInfoMap.entrySet()) {
-
-
- var name = giftInfo.getKey().replace(" ", "_")
- .replace("’", "_")
- .replace("+", "_")
- .replace("'", "_")
- .replace(".", "_")
- .replace("-", "_")
- .replace("&", "_")
- .replace("!", "_")
- .toUpperCase();
-
-
- boolean startsWithNumber = name.matches("^[0-9].*");
- if (startsWithNumber) {
- name = "_" + name;
- }
-
- if (isNumeric(name)) {
- name = "_" + name;
- }
-
- if (name.equalsIgnoreCase("")) {
- continue;
- }
- var contier = 1;
- for (var value : giftInfo.getValue()) {
- var enumName = name;
- if (contier > 1) {
- enumName += "_" + value.getId();
- }
- enumBuilder.addEnumConstant(enumName, addGift(value.getId(), value.getName(), value.getDiamondCost(), value.getImage()));
- contier++;
- }
-
-
- }
- var output = JavaFile.builder("io.github.jwdeveloper.tiktok.data.models.gifts", enumBuilder.build());
- output.addFileComment("This enum is generated");
- return output.build();
- }
-
- public static boolean isNumeric(String str) {
- try {
- Double.parseDouble(str);
- return true;
- } catch (NumberFormatException e) {
- return false;
- }
- }
-
- public static TypeSpec addGift(int id, String name, int diamond, String picture) {
- return TypeSpec.anonymousClassBuilder(
- "$L, $S, $L, $S",
- id,
- name,
- diamond,
- picture)
- .build();
- }
-
-}
diff --git a/Tools/src/main/java/io/github/jwdeveloper/tiktok/gifts/GiftsDownloader.java b/Tools/src/main/java/io/github/jwdeveloper/tiktok/gifts/GiftsDownloader.java
deleted file mode 100644
index 4b39cdd..0000000
--- a/Tools/src/main/java/io/github/jwdeveloper/tiktok/gifts/GiftsDownloader.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-package io.github.jwdeveloper.tiktok.gifts;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.reflect.TypeToken;
-import io.github.jwdeveloper.tiktok.gifts.downloader.GiftDto;
-import io.github.jwdeveloper.tiktok.gifts.downloader.GiftExtraJson;
-import io.github.jwdeveloper.tiktok.gifts.downloader.GiftOfficialJson;
-import io.github.jwdeveloper.tiktok.gifts.downloader.GiftScraperJson;
-import io.github.jwdeveloper.tiktok.utils.FilesUtility;
-
-import java.lang.reflect.Type;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-public class GiftsDownloader {
-
- public static void main(String[] run) {
- var gifts = new GiftsDownloader().getGifts();
- for(var gift : gifts)
- {
- System.out.println(gift.toString());
- }
- }
-
- public List getGiftsFromFile() {
- var version = "";
- var content = FilesUtility.loadFileContent("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\Tools\\src\\main\\resources\\gifts\\output.json");
- Type mapType = new TypeToken