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:
JW
2023-10-12 05:28:06 +02:00
parent bac4389823
commit 7621e32141
22 changed files with 317 additions and 99 deletions

View File

@@ -22,54 +22,56 @@
*/
package io.github.jwdeveloper.tiktok;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
import java.time.Duration;
import java.util.logging.Level;
public class CodeExample
{
public static void main(String[] args)
{
public class CodeExample {
public static void main(String[] args) {
TikTokLive.newClient("mrBeast")
.onGift((liveClient, event) ->
{
System.out.println("Thank you for Money!");
})
.buildAndConnect();
}
public static void codeExample()
{
TikTokLive.newClient("bangbetmenygy")
.onGift((liveClient, event) ->
{
if(event.getGift() == Gift.ROSE)
{
liveClient.getLogger().info("Rose from "+event.getUser().getDisplayName());
return;
}
liveClient.getLogger().info("Thank you for "+event.getGift().getName());
})
.onJoin((liveClient, event) ->
{
liveClient.getLogger().info("Hello "+event.getUser().getDisplayName());
})
.onConnected((liveClient, event) ->
{
liveClient.getLogger().info("Connected to live ");
})
.onError((liveClient, event) ->
{
liveClient.getLogger().info("ERROR! "+event.getException().getMessage());
System.out.println("Thank you for Money!");
})
.buildAndConnect();
}
public static void configExample()
{
public static void codeExample() {
// <code>
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";
default -> "Thank you for " + event.getGift().getName();
};
System.out.println(event.getUser().getProfileName() + " sends " + message);
})
.onGiftCombo((liveClient, event) ->
{
System.out.println(event.getComboState()+ " " + event.getCombo() + " " + event.getGift().getName());
})
.onJoin((liveClient, event) ->
{
System.out.println(event.getUser().getProfileName() + "Hello on my stream! ");
})
.onConnected((liveClient, event) ->
{
System.out.println("Connected to live ");
})
.onError((liveClient, event) ->
{
System.out.println("Error! " + event.getException().getMessage());
})
.buildAndConnect();
// </code>
}
public static void configExample() {
// <code>
TikTokLive.newClient("bangbetmenygy")
.configure((settings) ->
{
@@ -92,6 +94,7 @@ public class CodeExample
settings.setRoomId("XXXXXXXXXXXXXXXXX");
})
.buildAndConnect();
// </code>
}

View File

@@ -0,0 +1,72 @@
/*
* 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.utils.FilesUtility;
import io.github.jwdeveloper.tiktok.utils.TemplateUtility;
import java.util.HashMap;
import java.util.regex.Pattern;
public class CodeExamplesGenerator {
public static void main(String[] args) {
var result = new CodeExamplesGenerator().run();
System.out.println(result);
}
public String run() {
var content = FilesUtility.loadFileContent("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\Tools-ReadmeGenerator\\src\\main\\java\\io\\github\\jwdeveloper\\tiktok\\CodeExample.java");
var p = "<code>(.*?)</code>";
var r = Pattern.compile(p, Pattern.DOTALL);
var m = r.matcher(content);
var pattern = """
```java
{{code}}
```
3. Configure (optional)
```java
{{config}}
```
""";
var values = new HashMap<String, Object>();
m.find();
var code = m.group(0)
.replace("<code>", "")
.replace("// </code>", "")
.replaceAll("(?m)^ {8}", "");
values.put("code", code);
m.find();
values.put("config", m.group(1));
var result = TemplateUtility.generateTemplate(pattern, values);
return result;
}
}

View File

@@ -82,11 +82,15 @@ public class EventsInfoGenerator {
variables.put("method-name", dto.getMethodName());
variables.put("content", doc);
variables.put("event-name", dto.getEventClazz().getSimpleName());
var baseUrl = "https://github.com/jwdeveloper/TikTokLiveJava/blob/master/API/src/main/java/";
baseUrl += dto.getEventClazz().getPackageName().replace(".","/");
baseUrl += "/"+dto.getEventClazz().getSimpleName()+".java";
variables.put("event-file-url",baseUrl);
var temp = """
## {{method-name}} [{{event-name}}](https://github.com/jwdeveloper/TikTok-Live-Java/blob/master/API/src/main/java/io/github/jwdeveloper/tiktok/events/messages.java)
## {{method-name}} [{{event-name}}]({{event-file-url}})
{{content}}

View File

@@ -0,0 +1,47 @@
/*
* 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.utils.FilesUtility;
import java.util.regex.Pattern;
public class ListenerExampleGenerator
{
public static void main(String[] arg)
{
var result = new ListenerExampleGenerator();
System.out.println(result);
}
public String run()
{
var content = FilesUtility.loadFileContent("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\Examples\\src\\main\\java\\io\\github\\jwdeveloper\\tiktok\\ListenerExample.java");
var p = "<code>(.*?)</code>";
var r = Pattern.compile(p, Pattern.DOTALL);
var m = r.matcher(content);
m.find();
return m.group(1);
}
}

View File

@@ -26,48 +26,38 @@ import io.github.jwdeveloper.tiktok.utils.FilesUtility;
import io.github.jwdeveloper.tiktok.utils.TemplateUtility;
import java.util.HashMap;
import java.util.regex.Pattern;
public class ReadmeGenerator
{
public static void main(String[] args)
{
public class ReadmeGenerator {
public static void main(String[] args) {
var generator = new ReadmeGenerator();
generator.generate();
}
public void generate()
{
var template = FilesUtility.getFileFromResource(ReadmeGenerator.class,"template.md");
var variables = new HashMap<String,Object>();
public void generate() {
var template = FilesUtility.getFileFromResource(ReadmeGenerator.class, "template.md");
var variables = new HashMap<String, Object>();
variables.put("version", getCurrentVersion());
var exampleCodePath = "C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\Examples\\src\\main\\java\\io\\github\\jwdeveloper\\tiktok\\SimpleExample.java";
variables.put("code-content", getCodeExample(exampleCodePath));
variables.put("code-content", new CodeExamplesGenerator().run());
variables.put("events-content", new EventsInfoGenerator().run());
var listenerExamplePath = "C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\Examples\\src\\main\\java\\io\\github\\jwdeveloper\\tiktok\\ListenerExample.java";
// variables.put("listener-content", getCodeExample(listenerExamplePath));
variables.put("listener-content",new ListenerExampleGenerator().run());
template = TemplateUtility.generateTemplate(template, variables);
var outputPath = "C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\Tools-ReadmeGenerator\\src\\main\\resources\\output.md";
FilesUtility.saveFile(outputPath, template);
}
public String getCurrentVersion()
{
var version = System.getenv("version");;
public String getCurrentVersion() {
var version = System.getenv("version");
;
return version == null?"NOT_FOUND":version;
return version == null ? "NOT_FOUND" : version;
}
public String getCodeExample(String path)
{
public String getCodeExample(String path) {
var content = FilesUtility.loadFileContent(path);
content = content.substring(content.indexOf("*/")+2);
content = content.substring(content.indexOf("*/") + 2);
return content;
}

View File

@@ -29,7 +29,7 @@
</div>
# Introduction
A Java library inspired by [TikTokLive](https://github.com/isaackogan/TikTokLive) and [TikTokLiveSharp](https://github.com/sebheron/TikTokLiveSharp). Use it to receive live stream events such as comments and gifts in realtime from [TikTok LIVE](https://www.tiktok.com/live) by connecting to TikTok's internal WebCast push service.
A Java library inspired by [TikTokLive](https://github.com/isaackogan/TikTokLive) and [TikTokLiveSharp](https://github.com/frankvHoof93/TikTokLiveSharp). Use it to receive live stream events such as comments and gifts in realtime from [TikTok LIVE](https://www.tiktok.com/live) by connecting to TikTok's internal WebCast push service.
The library includes a wrapper that connects to the WebCast service using just the username (`uniqueId`). This allows you to connect to your own live chat as well as the live chat of other streamers.
No credentials are required. Events such as [Members Joining](#member), [Gifts](#gift), [Subscriptions](#subscribe), [Viewers](#roomuser), [Follows](#social), [Shares](#social), [Questions](#questionnew), [Likes](#like) and [Battles](#linkmicbattle) can be tracked.
@@ -45,9 +45,8 @@ Do you prefer other programming languages?
#### Overview
- [Getting started](#getting-started)
- [Configuration](#configuration)
- [Methods](#methods)
- [Events](#events)
- [Listeners](#listeners)
- [Contributing](#contributing)
## Getting started
@@ -74,20 +73,20 @@ Do you prefer other programming languages?
2. Create your first chat connection
```java
{{code-content}}
```
## Events
{{events-content}}
<br>
## Listener Example
## Listeners
```java
{{listener-content}}
```
## Contributing
Your improvements are welcome! Feel free to open an <a href="https://github.com/jwdeveloper/TikTok-Live-Java/issues">issue</a> or <a href="https://github.com/jwdeveloper/TikTok-Live-Java/pulls">pull request</a>.