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