mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-28 09:19:40 -05:00
Breaking changes:
'Gift': changed from class to enum, so now you can handle
incoming gifts in switch
`Events`
- new:
onGiftComboFinished
- Removed:
onGiftBrodcast
- Rename:
onGiftMessage -> onGift
onRoomPinMessage -> onRoomPin
onRoomMessage -> onRoom
onLinkMessage -> onLink
onBarrageMessage -> onBarrage
onPollMessage -> onPoll
onShopMessage -> onShop
onDetectMessage -> onDetect
`GiftManager`
added:
registerGift
findById
findByName
getGifts
removed:
getActiveGifts
This commit is contained in:
@@ -25,6 +25,7 @@ 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.events.objects.Picture;
|
||||
import io.github.jwdeveloper.tiktok.gifts.downloader.GiftDto;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -44,17 +45,6 @@ public class GenerateGiftsEnum {
|
||||
var downloader = new GiftsDownloader();
|
||||
var gifts = downloader.getGiftsFromFile();
|
||||
var groupedByName = gifts.stream().collect(Collectors.groupingBy(GiftDto::getName));
|
||||
for (var entry : groupedByName.entrySet()) {
|
||||
if (entry.getValue().size() > 1) {
|
||||
System.out.println("LOOK AT THIS SHIT: " + entry.getKey());
|
||||
for (var v : entry.getValue()) {
|
||||
System.out.println(v.toString());
|
||||
}
|
||||
|
||||
System.out.println("-------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Total gifts" + gifts.size());
|
||||
var result = generate(groupedByName);
|
||||
result.writeTo(new File("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\API\\src\\main\\java"));
|
||||
@@ -68,17 +58,19 @@ public class GenerateGiftsEnum {
|
||||
.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(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(Picture.class, "picture")
|
||||
.addStatement("this.id = id")
|
||||
.addStatement("this.name = name")
|
||||
.addStatement("this.diamondCost = diamondCost")
|
||||
.addStatement("this.picture = picture")
|
||||
.build();
|
||||
|
||||
var inRangeMethod = MethodSpec.methodBuilder("hasDiamondCostRange")
|
||||
@@ -99,7 +91,7 @@ public class GenerateGiftsEnum {
|
||||
enumBuilder.addMethod(constructor);
|
||||
|
||||
|
||||
enumBuilder.addEnumConstant("UNDEFINED", addGift(-1, "undefined", -1));
|
||||
enumBuilder.addEnumConstant("UNDEFINED", addGift(-1, "undefined", -1, new Picture("")));
|
||||
for (var giftInfo : giftInfoMap.entrySet()) {
|
||||
|
||||
|
||||
@@ -125,7 +117,7 @@ public class GenerateGiftsEnum {
|
||||
if (contier > 1) {
|
||||
enumName += "_" + value.getId();
|
||||
}
|
||||
enumBuilder.addEnumConstant(enumName, addGift(value.getId(), value.getName(), value.getDiamondCost()));
|
||||
enumBuilder.addEnumConstant(enumName, addGift(value.getId(), value.getName(), value.getDiamondCost(), new Picture(value.getImage())));
|
||||
contier++;
|
||||
}
|
||||
|
||||
@@ -149,18 +141,21 @@ public class GenerateGiftsEnum {
|
||||
}
|
||||
|
||||
public static void onEnums(TypeSpec.Builder builder) {
|
||||
builder.addEnumConstant("RUGBY_BALL", addGift(6249, "Rugby Ball", 10));
|
||||
builder.addEnumConstant("I_LOVE_YOU", addGift(5779, "I Love you", 10));
|
||||
builder.addEnumConstant("BOUQUET_FLOWER", addGift(5780, "Bouquet Flower", 30));
|
||||
// builder.addEnumConstant("RUGBY_BALL", addGift(6249, "Rugby Ball", 10));
|
||||
// builder.addEnumConstant("I_LOVE_YOU", addGift(5779, "I Love you", 10));
|
||||
// builder.addEnumConstant("BOUQUET_FLOWER", addGift(5780, "Bouquet Flower", 30));
|
||||
}
|
||||
|
||||
|
||||
public static TypeSpec addGift(int id, String name, int diamont) {
|
||||
public static TypeSpec addGift(int id, String name, int diamont, Picture picture)
|
||||
{
|
||||
var pictureValue = "new Picture(\""+picture.getLink()+"\")";
|
||||
return TypeSpec.anonymousClassBuilder(
|
||||
"$L, $S, $L",
|
||||
"$L, $S, $L, $S",
|
||||
id,
|
||||
name,
|
||||
diamont)
|
||||
diamont,
|
||||
pictureValue)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,16 +22,18 @@
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.gifts;
|
||||
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import io.github.jwdeveloper.tiktok.events.objects.Picture;
|
||||
import io.github.jwdeveloper.tiktok.gifts.downloader.GiftDto;
|
||||
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.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
@@ -65,15 +67,14 @@ public class GiftsDownloader {
|
||||
|
||||
|
||||
var outputHashMap = new TreeMap<Integer, GiftDto>();
|
||||
for (var gift : scraperGifts)
|
||||
{
|
||||
for (var gift : scraperGifts) {
|
||||
outputHashMap.put(gift.getId(), gift);
|
||||
}
|
||||
for (var gift : officialGifts)
|
||||
{
|
||||
for (var gift : officialGifts) {
|
||||
outputHashMap.put(gift.getId(), gift);
|
||||
}
|
||||
var gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
var gson = new GsonBuilder().setPrettyPrinting()
|
||||
.create();
|
||||
var json = gson.toJson(outputHashMap);
|
||||
FilesUtility.saveFile("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\Tools\\src\\main\\resources\\gifts\\output.json", json);
|
||||
System.out.println("Gifts saved to file!");
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.gifts.downloader;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.events.objects.Picture;
|
||||
import io.github.jwdeveloper.tiktok.utils.JsonIgnore;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import io.github.jwdeveloper.tiktok.Constants;
|
||||
import io.github.jwdeveloper.tiktok.events.objects.Picture;
|
||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
||||
import io.github.jwdeveloper.tiktok.http.TikTokCookieJar;
|
||||
import io.github.jwdeveloper.tiktok.http.TikTokHttpClient;
|
||||
@@ -64,6 +65,10 @@ public class GiftOfficialJson {
|
||||
.get("image").getAsJsonObject()
|
||||
.get("url_list").getAsJsonArray().get(0).getAsString();
|
||||
|
||||
if(image.endsWith(".webp"))
|
||||
{
|
||||
image = image.replace(".webp",".jpg");
|
||||
}
|
||||
var gift = new GiftDto();
|
||||
gift.setId(id);
|
||||
gift.setName(name);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
package io.github.jwdeveloper.tiktok.gifts.downloader;
|
||||
|
||||
|
||||
import io.github.jwdeveloper.tiktok.events.objects.Picture;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.utils;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface JsonIgnore {
|
||||
}
|
||||
Reference in New Issue
Block a user