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:
@@ -1,6 +1,30 @@
|
||||
/*
|
||||
* 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.tools.collector;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.TikTokLive;
|
||||
import io.github.jwdeveloper.tiktok.events.messages.TikTokGiftEvent;
|
||||
import io.github.jwdeveloper.tiktok.events.messages.TikTokJoinEvent;
|
||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveMessageException;
|
||||
import io.github.jwdeveloper.tiktok.tools.collector.db.TikTokDatabase;
|
||||
import io.github.jwdeveloper.tiktok.tools.collector.tables.ExceptionInfoModel;
|
||||
@@ -24,10 +48,14 @@ public class RunCollector {
|
||||
|
||||
public static List<String> ignoredEvents;
|
||||
|
||||
public static List<Class<?>> filter;
|
||||
|
||||
public static void main(String[] args) throws SQLException {
|
||||
ignoredEvents = new ArrayList<>();
|
||||
//ignoredEvents = List.of("TikTokJoinEvent","TikTokLikeEvent");
|
||||
|
||||
filter = new ArrayList<>();
|
||||
filter.add(TikTokGiftEvent.class);
|
||||
|
||||
var db = new TikTokDatabase("test");
|
||||
db.init();
|
||||
@@ -35,33 +63,45 @@ public class RunCollector {
|
||||
var errors = db.selectErrors();
|
||||
|
||||
var users = new ArrayList<String>();
|
||||
// users.add("mia_tattoo");
|
||||
// users.add("moniczkka");
|
||||
// users.add("besin1276");
|
||||
users.add("evequinte96");
|
||||
for (var user : users) {
|
||||
runTikTokLiveInstance(user, db);
|
||||
users.add("mia_tattoo");
|
||||
users.add("mr_wavecheck");
|
||||
users.add("bangbetmenygy");
|
||||
users.add("larasworld0202");
|
||||
for (var user : users)
|
||||
{
|
||||
try {
|
||||
runTikTokLiveInstance(user, db);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void runTikTokLiveInstance(String tiktokUser, TikTokDatabase tikTokDatabase) {
|
||||
|
||||
TikTokLive.newClient(tiktokUser)
|
||||
.onConnected((liveClient, event) ->
|
||||
{
|
||||
System.out.println("CONNECTED TO "+liveClient.getRoomInfo().getUserName());
|
||||
})
|
||||
.onWebsocketMessage((liveClient, event) ->
|
||||
{
|
||||
var eventName = event.getEvent().getClass().getSimpleName();
|
||||
|
||||
if (ignoredEvents.contains(eventName)) {
|
||||
if(filter.size() != 0 && !filter.contains(event.getEvent().getClass()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var binary = Base64.getEncoder().encodeToString(event.getMessage().getBinary().toByteArray());
|
||||
var model = TikTokMessageModel.builder()
|
||||
.type("message")
|
||||
.hostName(tiktokUser)
|
||||
.eventName(eventName)
|
||||
.eventContent(binary)
|
||||
.build();
|
||||
var binary = Base64.getEncoder().encodeToString(event.getMessage().toByteArray());
|
||||
var model = new TikTokMessageModel();
|
||||
model.setType("messsage");
|
||||
model.setHostName(tiktokUser);
|
||||
model.setEventName(eventName);
|
||||
model.setEventContent(binary);
|
||||
|
||||
tikTokDatabase.insertMessage(model);
|
||||
System.out.println("EVENT: [" + tiktokUser + "] " + eventName);
|
||||
@@ -93,7 +133,7 @@ public class RunCollector {
|
||||
exception.printStackTrace();
|
||||
|
||||
})
|
||||
.buildAndRun();
|
||||
.buildAndRunAsync();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* 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.tools.collector.db;
|
||||
|
||||
public class SqlConsts
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* 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.tools.collector.db;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.tools.collector.tables.TikTokErrorModel;
|
||||
@@ -11,18 +33,17 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class TikTokDatabase
|
||||
{
|
||||
public class TikTokDatabase {
|
||||
private final String database;
|
||||
private TikTokMessageModelDAO messagesTable;
|
||||
private TikTokErrorModelDAO errorTable;
|
||||
|
||||
public TikTokDatabase(String database) {
|
||||
this.database =database;
|
||||
public TikTokDatabase(String database) {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public void init() throws SQLException {
|
||||
var jdbcUrl ="jdbc:sqlite:"+database+".db";
|
||||
var jdbcUrl = "jdbc:sqlite:" + database + ".db";
|
||||
var connection = DriverManager.getConnection(jdbcUrl);
|
||||
var jdbi = Jdbi.create(jdbcUrl)
|
||||
.installPlugin(new SqlObjectPlugin());
|
||||
@@ -30,27 +51,27 @@ public class TikTokDatabase
|
||||
handle.execute(SqlConsts.CREATE_MESSAGES_TABLE);
|
||||
handle.execute(SqlConsts.CREATE_ERROR_TABLE);
|
||||
});
|
||||
// jdbi.registerRowMapper(new TikTokErrorModelMapper());
|
||||
messagesTable = jdbi.onDemand(TikTokMessageModelDAO.class);
|
||||
errorTable = jdbi.onDemand(TikTokErrorModelDAO.class);
|
||||
}
|
||||
|
||||
public void insertMessage(TikTokMessageModel message)
|
||||
{
|
||||
public void insertMessage(TikTokMessageModel message) {
|
||||
var dateFormat = new SimpleDateFormat("dd:MM:yyyy HH:mm:ss.SSS");
|
||||
message.setCreatedAt(dateFormat.format(new Date()));
|
||||
messagesTable.insertTikTokMessage(message);
|
||||
}
|
||||
|
||||
public void insertError(TikTokErrorModel message)
|
||||
{
|
||||
public void insertError(TikTokErrorModel message) {
|
||||
var dateFormat = new SimpleDateFormat("dd:MM:yyyy HH:mm:ss.SSS");
|
||||
message.setCreatedAt(dateFormat.format(new Date()));
|
||||
errorTable.insertTikTokMessage(message);
|
||||
}
|
||||
|
||||
public List<TikTokErrorModel> selectErrors()
|
||||
{
|
||||
return errorTable.selectErrors();
|
||||
public List<TikTokErrorModel> selectErrors() {
|
||||
return errorTable.selectErrors();
|
||||
}
|
||||
|
||||
public List<TikTokMessageModel> selectMessages() {
|
||||
return messagesTable.select();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* 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.tools.collector.db;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.tools.collector.tables.TikTokErrorModel;
|
||||
|
||||
@@ -1,12 +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.tools.collector.db;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.tools.collector.tables.TikTokErrorModel;
|
||||
import io.github.jwdeveloper.tiktok.tools.collector.tables.TikTokMessageModel;
|
||||
import org.jdbi.v3.sqlobject.config.RegisterBeanMapper;
|
||||
import org.jdbi.v3.sqlobject.customizer.BindBean;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterBeanMapper(TikTokMessageModel.class)
|
||||
public interface TikTokMessageModelDAO
|
||||
{
|
||||
@SqlUpdate("INSERT INTO TikTokMessageModel (hostName, eventName,type, eventContent, createdAt) " +
|
||||
"VALUES (:hostName, :eventName, :type, :eventContent, :createdAt)")
|
||||
void insertTikTokMessage(@BindBean TikTokMessageModel message);
|
||||
|
||||
@SqlQuery("SELECT * FROM TikTokMessageModel")
|
||||
List<TikTokMessageModel> select();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* 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.tools.collector.tables;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
/*
|
||||
* 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.tools.collector.tables;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -1,11 +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.tools.collector.tables;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class TikTokMessageModel
|
||||
{
|
||||
private Integer id;
|
||||
|
||||
@@ -1,51 +1,93 @@
|
||||
/*
|
||||
* 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.tools.tester;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import io.github.jwdeveloper.tiktok.ClientSettings;
|
||||
import io.github.jwdeveloper.tiktok.TikTokGiftManager;
|
||||
import io.github.jwdeveloper.tiktok.TikTokRoomInfo;
|
||||
import io.github.jwdeveloper.tiktok.events.messages.TikTokErrorEvent;
|
||||
import io.github.jwdeveloper.tiktok.events.messages.TikTokGiftComboFinishedEvent;
|
||||
import io.github.jwdeveloper.tiktok.events.messages.TikTokGiftEvent;
|
||||
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftManager;
|
||||
import io.github.jwdeveloper.tiktok.handlers.TikTokEventObserver;
|
||||
import io.github.jwdeveloper.tiktok.handlers.TikTokMessageHandlerRegistration;
|
||||
import io.github.jwdeveloper.tiktok.messages.WebcastResponse;
|
||||
import io.github.jwdeveloper.tiktok.tools.collector.db.TikTokDatabase;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Base64;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class RunTester {
|
||||
|
||||
public static void main(String[] args) throws SQLException, InvalidProtocolBufferException {
|
||||
|
||||
var db = new TikTokDatabase("test");
|
||||
db.init();
|
||||
var errors = db.selectErrors();
|
||||
public static void main(String[] args) throws Exception {
|
||||
var db = new TikTokDatabase("test");
|
||||
db.init();
|
||||
var errors = db.selectErrors();
|
||||
|
||||
|
||||
var handler = getMessageHandler();
|
||||
for (var error : errors) {
|
||||
|
||||
var bytes = Base64.getDecoder().decode(error.getResponse());
|
||||
var response = WebcastResponse.parseFrom(bytes);
|
||||
handler.handle(null,response);
|
||||
|
||||
var handler = getMessageHandler();
|
||||
for (var error : errors) {
|
||||
|
||||
var bytes = Base64.getDecoder().decode(error.getResponse());
|
||||
var response = WebcastResponse.parseFrom(bytes);
|
||||
handler.handle(null, response);
|
||||
}
|
||||
|
||||
var messags = db.selectMessages();
|
||||
for (var msg : messags) {
|
||||
if (!msg.getEventName().contains("Gift")) {
|
||||
continue;
|
||||
}
|
||||
var bytes = Base64.getDecoder().decode(msg.getEventContent());
|
||||
var response = WebcastResponse.Message.parseFrom(bytes);
|
||||
handler.handleSingleMessage(null, response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static TikTokMessageHandlerRegistration getMessageHandler()
|
||||
{
|
||||
public static TikTokMessageHandlerRegistration getMessageHandler() {
|
||||
var observer = new TikTokEventObserver();
|
||||
observer.<TikTokErrorEvent>subscribe(TikTokErrorEvent.class,(liveClient, event) ->
|
||||
observer.<TikTokGiftEvent>subscribe(TikTokGiftEvent.class, (liveClient, event) ->
|
||||
{
|
||||
event.getException().printStackTrace();
|
||||
var sb = new StringBuilder();
|
||||
sb.append("Event: " + event.getGift());
|
||||
sb.append(" combo: " + event.getComboCount());
|
||||
sb.append(" index " + event.getComboIndex());
|
||||
sb.append(" sender " + event.getSender().getNickName());
|
||||
sb.append(" finished " + event.getComboFinished());
|
||||
System.out.println(sb.toString());
|
||||
});
|
||||
observer.<TikTokGiftComboFinishedEvent>subscribe(TikTokGiftComboFinishedEvent.class, (liveClient, event) ->
|
||||
{
|
||||
System.out.println("Combo finished event! " + event.getComboCount() + " " + event.getGift());
|
||||
});
|
||||
observer.<TikTokErrorEvent>subscribe(TikTokErrorEvent.class, (liveClient, event) ->
|
||||
{
|
||||
event.getException().printStackTrace();
|
||||
});
|
||||
var settings = new ClientSettings();
|
||||
//settings.setPrintMessageData(true);
|
||||
var logger = Logger.getGlobal();
|
||||
var roomInfo = new TikTokRoomInfo();
|
||||
var manager = new TikTokGiftManager();
|
||||
return new TikTokMessageHandlerRegistration(observer,settings,logger,manager,roomInfo);
|
||||
return new TikTokMessageHandlerRegistration(observer, manager, roomInfo);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user