mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 08:49:40 -05:00
Update gifts manager
This commit is contained in:
@@ -41,5 +41,11 @@
|
||||
<version>0.9.12</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>1.3.0-Release</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
|
||||
/*
|
||||
* 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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class FilesUtility
|
||||
{
|
||||
public static List<Path> getFiles(String input) {
|
||||
Path path = Paths.get(input);
|
||||
try (Stream<Path> paths = Files.list(path)) {
|
||||
return paths.filter(Files::isRegularFile).toList();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public static String getFileFromResource(Class clazz, String path)
|
||||
{
|
||||
try {
|
||||
var stream =clazz.getClassLoader().getResourceAsStream(path);
|
||||
var bytes= stream.readAllBytes();
|
||||
stream.close();
|
||||
return new String(bytes);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public static List<Path> getFileContent(String input) {
|
||||
Path path = Paths.get(input);
|
||||
try (Stream<Path> paths = Files.list(path)) {
|
||||
return paths.filter(Files::isRegularFile).toList();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveFile(String path, String content)
|
||||
{
|
||||
Path filePath = Paths.get(path);
|
||||
try {
|
||||
// Write the content to the file
|
||||
Files.write(filePath, content.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean pathExists(String path) {
|
||||
var directory = new File(path);
|
||||
return directory.exists();
|
||||
}
|
||||
|
||||
public static File ensurePath(String path) {
|
||||
var directory = new File(path);
|
||||
if (directory.exists()) {
|
||||
return directory;
|
||||
}
|
||||
directory.mkdirs();
|
||||
return directory;
|
||||
}
|
||||
|
||||
public static void ensureFile(String paths) {
|
||||
var file = new File(paths);
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String loadFileContent(String path) {
|
||||
ensureFile(path);
|
||||
Path pathh = Paths.get(path);
|
||||
try {
|
||||
return new String(Files.readAllBytes(pathh));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
/*
|
||||
* 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 java.util.Map;
|
||||
|
||||
public class TemplateUtility {
|
||||
public static String generateTemplate(String template, Map<String, Object> values) {
|
||||
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 + "(}})";
|
||||
return template.replaceAll(key, value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user