mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -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,9 +25,16 @@ package io.github.jwdeveloper.tiktok.live;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LiveRoomMeta
|
||||
{
|
||||
private int status;
|
||||
public class LiveRoomMeta {
|
||||
/**
|
||||
* 0 - Unknown
|
||||
* 1 - ?
|
||||
* 2 - Online
|
||||
* 3 - ?
|
||||
* 4 - Offline
|
||||
*/
|
||||
|
||||
private boolean ageRestricted;
|
||||
private int status;
|
||||
|
||||
private boolean ageRestricted;
|
||||
}
|
||||
|
||||
@@ -7,14 +7,13 @@ import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface LiveClientBuilder extends EventBuilder<LiveClientBuilder>
|
||||
{
|
||||
|
||||
public interface LiveClientBuilder extends EventBuilder<LiveClientBuilder> {
|
||||
LiveClientBuilder configure(Consumer<ClientSettings> consumer);
|
||||
|
||||
LiveClientBuilder addListener(TikTokEventListener listener);
|
||||
|
||||
LiveClient build();
|
||||
|
||||
LiveClient buildAndConnect();
|
||||
|
||||
CompletableFuture<LiveClient> buildAndConnectAsync();
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
package io.github.jwdeveloper.tiktok;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.annotations.TikTokEventHandler;
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.TikTokCommentEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.social.TikTokLikeEvent;
|
||||
import io.github.jwdeveloper.tiktok.listener.TikTokEventListener;
|
||||
@@ -34,30 +34,33 @@ import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ListenerExample {
|
||||
/*
|
||||
Listeners are an alternative way of handling events.
|
||||
I would to suggest to use then when logic of handing event
|
||||
is more complex
|
||||
/**
|
||||
*
|
||||
* Listeners are an alternative way of handling events.
|
||||
* I would to suggest to use then when logic of handing event
|
||||
* is more complex
|
||||
*
|
||||
*/
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
CustomListener customListener = new CustomListener();
|
||||
|
||||
// set tiktok username
|
||||
var client = TikTokLive.newClient(Main.TEST_TIKTOK_USER)
|
||||
TikTokLive.newClient(Main.TEST_TIKTOK_USER)
|
||||
.addListener(customListener)
|
||||
.buildAndConnect();
|
||||
|
||||
System.in.read();
|
||||
}
|
||||
|
||||
/*
|
||||
Method in TikTokEventListener should meet 4 requirements to be detected
|
||||
- must have @TikTokEventHandler annotation
|
||||
- must have 2 parameters
|
||||
- first parameter must be LiveClient
|
||||
- second must be class that extending TikTokEvent
|
||||
/**
|
||||
*
|
||||
* Method in TikTokEventListener should meet 4 requirements to be detected
|
||||
* - must have @TikTokEventHandler annotation
|
||||
* - must have 2 parameters
|
||||
* - first parameter must be LiveClient
|
||||
* - second must be class that extending TikTokEvent
|
||||
*/
|
||||
|
||||
public static class CustomListener implements TikTokEventListener {
|
||||
|
||||
@TikTokEventHandler
|
||||
@@ -67,27 +70,32 @@ public class ListenerExample {
|
||||
|
||||
@TikTokEventHandler
|
||||
public void onError(LiveClient liveClient, TikTokErrorEvent event) {
|
||||
System.out.println(event.getException().getMessage());
|
||||
event.getException().printStackTrace();
|
||||
}
|
||||
|
||||
@TikTokEventHandler
|
||||
public void onComment(LiveClient liveClient, TikTokCommentEvent event) {
|
||||
System.out.println(event.getText());
|
||||
var userName = event.getUser().getName();
|
||||
var text = event.getText();
|
||||
liveClient.getLogger().info(userName + ": " + text);
|
||||
}
|
||||
|
||||
@TikTokEventHandler
|
||||
public void onGift(LiveClient liveClient, TikTokGiftEvent event) {
|
||||
var message = switch (event.getGift()) {
|
||||
case ROSE -> "Thanks :)";
|
||||
default -> "as";
|
||||
case APPETIZERS -> ":$";
|
||||
case APRIL -> ":D";
|
||||
case TIKTOK -> ":P";
|
||||
case CAP -> ":F";
|
||||
default -> ":I";
|
||||
};
|
||||
|
||||
|
||||
liveClient.getLogger().info(message);
|
||||
}
|
||||
|
||||
@TikTokEventHandler
|
||||
public void onAnyEvent(LiveClient liveClient, TikTokEvent event) {
|
||||
System.out.println(event.getClass().getSimpleName());
|
||||
liveClient.getLogger().info(event.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import java.time.Duration;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static String TEST_TIKTOK_USER = "ano_liwia";
|
||||
public static String TEST_TIKTOK_USER = "bangbetmenygy";
|
||||
|
||||
public static void main(String[] args) throws IOException
|
||||
{
|
||||
@@ -121,7 +121,7 @@ public class Main {
|
||||
|
||||
private static void onLike(LiveClient tikTokLive, TikTokLikeEvent e) {
|
||||
|
||||
print(e.getUser().getId(), "liked!");
|
||||
print(e.getUser().getDisplayName(), "liked!");
|
||||
}
|
||||
private static void onEmote(LiveClient tikTokLive, TikTokEmoteEvent e) {
|
||||
print(e.getUser().getId(), "sent", e.getEmotes().size());
|
||||
|
||||
@@ -38,10 +38,10 @@ public class SimpleExample {
|
||||
.onGift((liveClient, event) ->
|
||||
{
|
||||
switch (event.getGift()) {
|
||||
case ROSE ->
|
||||
print("\uD83D\uDC95", ConsoleColors.YELLOW, "x", event.getCombo(), " roses!", "\uD83D\uDC95");
|
||||
default ->
|
||||
print(ConsoleColors.GREEN, "[Thanks for gift] ",ConsoleColors.YELLOW, event.getGift().getName(), "X", event.getCombo());
|
||||
case ROSE -> print(ConsoleColors.RED, " roses!", "\uD83D\uDC95");
|
||||
case GG -> print(ConsoleColors.YELLOW, " GOOD GAME!");
|
||||
case TIKTOK -> print(ConsoleColors.CYAN,"Thanks for TikTok");
|
||||
default -> print(ConsoleColors.GREEN, "[Thanks for gift] ", ConsoleColors.YELLOW, event.getGift().getName(), "X", event.getCombo());
|
||||
}
|
||||
})
|
||||
.onConnected((client, event) ->
|
||||
@@ -54,7 +54,7 @@ public class SimpleExample {
|
||||
})
|
||||
.onJoin((client, event) ->
|
||||
{
|
||||
print(ConsoleColors.GREEN, "Join -> ", ConsoleColors.WHITE_BRIGHT, event.getUser().getName());
|
||||
print(ConsoleColors.WHITE_BRIGHT, "Join ->", ConsoleColors.GREEN, event.getUser().getName());
|
||||
})
|
||||
.onComment((client, event) ->
|
||||
{
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user