Skip to content

Commit

Permalink
Build 3.3.1
Browse files Browse the repository at this point in the history
- Bugfix
  • Loading branch information
Blade2021 committed May 25, 2022
1 parent 3421dda commit 5ebf573
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 40 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

mainClassName = 'rsystems.HiveBot'

version '3.3.0'
version '3.3.1'

sourceCompatibility = 11
targetCompatibility = 11
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/rsystems/HiveBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class HiveBot {

public static JDAImpl jda = null;

public static OBSRemoteController obsRemoteController;
public static OBSRemoteController obsRemoteController = new OBSRemoteController(String.format("ws://%s:%s",Config.get("OBS-ADDRESS"),Config.get("OBS-PORT")), false, Config.get("obs-key"));

public static Guild mainGuild() {
return jda.getGuildById(Config.get("GUILD_ID"));
Expand Down Expand Up @@ -107,7 +107,7 @@ public static void main(String[] args) throws LoginException {
api.awaitReady();
jda = (JDAImpl) api;

obsRemoteController = new OBSRemoteController(String.format("ws://%s:%s",Config.get("OBS-ADDRESS"),Config.get("OBS-PORT")), false, Config.get("obs-key"));
//obsRemoteController = new OBSRemoteController(String.format("ws://%s:%s",Config.get("OBS-ADDRESS"),Config.get("OBS-PORT")), false, Config.get("obs-key"));

referenceHandler.loadReferences();

Expand Down
6 changes: 1 addition & 5 deletions src/main/java/rsystems/commands/debug/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ public boolean isOwnerOnly() {

@Override
public void dispatch(User sender, MessageChannel channel, Message message, String content, MessageReceivedEvent event) throws SQLException {
HiveBot.obsRemoteController.setSourceVisibility("Test","Dog",true, callback -> {
System.out.println("Test2");
System.out.println(callback.toString());
});

HiveBot.obsRemoteController.connect();
}

@Override
Expand Down
77 changes: 48 additions & 29 deletions src/main/java/rsystems/objects/StreamHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
import rsystems.tasks.BotActivity;

import java.awt.*;
import java.net.Inet4Address;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.List;

import static rsystems.HiveBot.obsRemoteController;

public class StreamHandler extends ListenerAdapter {

private boolean streamActive = false;
Expand Down Expand Up @@ -85,71 +82,73 @@ public void acceptNextRequest() {
if (HiveBot.database.consumePoints(request.getRequestingUserID(), request.getSelectedAnimation().getCost()) >= 1) {

logger.info("Animation request {} ID: {}", request.getRequestingUserID(), request.getSelectedAnimation().getId());
logger.info("New Queue Size: {}",requestsQueue.size());

animationCooldown = Instant.now().plus(request.getSelectedAnimation().getCooldown(),ChronoUnit.MINUTES);
notifyAcceptedAnimationRequest(request);
logger.info("New Queue Size: {}", requestsQueue.size());

try {
// Call webhook
obsRemoteController.setSourceVisibility(Animation.getSceneName(), Animation.getSourceName(), true, callback -> {
HiveBot.obsRemoteController.setSourceVisibility(Animation.getSceneName(), Animation.getSourceName(), true, callback -> {

if (callback.getStatus().equalsIgnoreCase("ok")) {

this.animationCooldown = Instant.now().plus(Animation.getCooldown(), ChronoUnit.MINUTES);
notifyAcceptedAnimationRequest(request);

try {
HiveBot.database.recordAnimationLog(this.currentStreamID,request);
HiveBot.database.recordAnimationLog(this.currentStreamID, request);
} catch (SQLException e) {
throw new RuntimeException(e);

}

//Set the handling request too false to allow another request
this.handlingRequest = false;
} else {

// Return points to user
try {
HiveBot.database.refundPoints(request.getRequestingUserID(), request.getSelectedAnimation().getCost());
} catch (SQLException e) {
throw new RuntimeException(e);
logger.error("SQL Exception encountered - Refunding Points to User: {}",request.getRequestingUserID());
}
}
});
} catch (Exception e) {

// Return points to user
logger.error("OBS Controller request failed, Attempting to refund points to user");

try {
HiveBot.database.refundPoints(request.getRequestingUserID(), request.getSelectedAnimation().getCost());

if (HiveBot.database.refundPoints(request.getRequestingUserID(), request.getSelectedAnimation().getCost()) >= 1) {
logger.info("Refunded points to {} successfully", request.getRequestingUserID());
}

} catch (SQLException ex) {
throw new RuntimeException(e);
}

logger.error("Failed to refund points to User: {} Points: {}", request.getRequestingUserID(), request.getSelectedAnimation().getCost());
}
//HiveBot.obsRemoteController.connect();
}
}

} catch (SQLException e) {
throw new RuntimeException(e);
logger.error("SQL Exception encountered - Consuming Points from User: {}",request.getRequestingUserID());
}


}
}

private void notifyAcceptedAnimationRequest(DispatchRequest request){
private void notifyAcceptedAnimationRequest(DispatchRequest request) {
final String notifyChannelID = Config.get("STREAM_REQUESTS_POST_CHANNELID");
final TextChannel channel = HiveBot.mainGuild().getTextChannelById(notifyChannelID);

if(channel != null){
if(channel.canTalk()){
if (channel != null) {
if (channel.canTalk()) {
//Create message embed from request
EmbedBuilder builder = new EmbedBuilder();
builder.setTitle("Animation Request");
builder.setColor(HiveBot.getColor(HiveBot.colorType.USER));
builder.setDescription(String.format("**Animation ID:** %d\n" +
"**Animation Name:** %s",request.getSelectedAnimation().getId(),request.getSelectedAnimation().getSourceName()));
builder.addField("Requesting User",request.getRequestingUserID().toString(),true);
builder.addField("Cooldown Expire:", String.format("<t:%d:R>",animationCooldown.getEpochSecond()),true);
builder.addField("Queue Size: ",String.format("%d of %d",requestsQueue.size(),maxQueueSize),false);
"**Animation Name:** %s", request.getSelectedAnimation().getId(), request.getSelectedAnimation().getSourceName()));
builder.addField("Requesting User", request.getRequestingUserID().toString(), true);
builder.addField("Cooldown Expire:", String.format("<t:%d:R>", animationCooldown.getEpochSecond()), true);
builder.addField("Remaining Queue: ", String.format("%d of %d", requestsQueue.size(), maxQueueSize), false);

channel.sendMessageEmbeds(builder.build()).queue();
builder.clear();
Expand Down Expand Up @@ -234,14 +233,14 @@ public void setStreamActive(boolean streamActive, String streamTopic) {
this.streamActive = streamActive;
}

public Integer clearRequestQueue(){
public Integer clearRequestQueue() {

Integer removedRequests = 0;

// REFUND POINTS FOR UNCALLED AnimationS
for (DispatchRequest request : this.requestsQueue) {
try {
if(HiveBot.database.refundPoints(request.getRequestingUserID(), request.getSelectedAnimation().getCost()) >= 1){
if (HiveBot.database.refundPoints(request.getRequestingUserID(), request.getSelectedAnimation().getCost()) >= 1) {
this.requestsQueue.remove(request);
removedRequests++;
}
Expand All @@ -253,10 +252,14 @@ public Integer clearRequestQueue(){
return removedRequests;
}

public Integer getQueueSize(){
public Integer getQueueSize() {
return this.requestsQueue.size();
}

public Integer getMaxQueueSize() {
return this.maxQueueSize;
}

public String getStreamTopic() {
return streamTopic;
}
Expand Down Expand Up @@ -611,4 +614,20 @@ public boolean isFirstHereClaimed() {
public void setFirstHereClaimed(boolean firstHereClaimed) {
this.firstHereClaimed = firstHereClaimed;
}

public int getSpentCashews() {
return spentCashews;
}

public void setSpentCashews(int spentCashews) {
this.spentCashews = spentCashews;
}

public int getAnimationsCalled() {
return AnimationsCalled;
}

public void setAnimationsCalled(int animationsCalled) {
AnimationsCalled = animationsCalled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public SlashCommandData getCommandData() {
subCommands.add(new SubcommandData("animation-killswitch","Enable/Disable the dispatch of animations").addOption(OptionType.BOOLEAN,"allowance","True = Animations allowed / False = Animations Disabled",true));
subCommands.add(new SubcommandData("status","Get the status of the Stream Handler"));
subCommands.add(new SubcommandData("clear-queue","Clear the current request queue"));
subCommands.add(new SubcommandData("reconnect","Reconnect to the Stream Controller"));

slashCommandData.addSubcommands(subCommands);

Expand Down Expand Up @@ -67,7 +68,13 @@ public void dispatch(User sender, MessageChannel channel, String content, SlashC
}
builder.addField("Animations",animationKS,true);

builder.addField("Request Queue",HiveBot.streamHandler.getQueueSize().toString(),true);
builder.addField("Request Queue",String.format("%d of %d",HiveBot.streamHandler.getQueueSize(),HiveBot.streamHandler.getMaxQueueSize()),true);

builder.addField("First Here Claimed:", String.valueOf(HiveBot.streamHandler.isFirstHereClaimed()).toUpperCase(),true);

builder.addField("Animations Called",String.valueOf(HiveBot.streamHandler.getAnimationsCalled()),true);

builder.addField("Cashews Spent",String.valueOf(HiveBot.streamHandler.getSpentCashews()),true);

reply(event,builder.build());
} else if(event.getSubcommandName().equalsIgnoreCase("clear-queue")){
Expand All @@ -79,6 +86,11 @@ public void dispatch(User sender, MessageChannel channel, String content, SlashC

reply(event,String.format("`%d` requests have been refunded/removed.",amount));

} else if(event.getSubcommandName().equalsIgnoreCase("reconnect")){

HiveBot.obsRemoteController.connect();
reply(event,"Attempting to reconnect to Stream Controller");

}
}

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/rsystems/tasks/CheckRequests.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ public void run() {
if(HiveBot.streamHandler.isStreamActive()){
if(!HiveBot.streamHandler.isHandlingRequest()){
if(HiveBot.streamHandler.getAnimationCooldown().isBefore(Instant.now())) {
logger.debug("Stream Mode: active | Handling Requests: false | Cooldown is satisfied - Calling next request");
HiveBot.streamHandler.acceptNextRequest();

try {
logger.debug("Stream Mode: active | Handling Requests: false | Cooldown is satisfied - Calling next request");
HiveBot.streamHandler.acceptNextRequest();
} catch (Exception e){
logger.info("Stream Handler ran into an error. Trying again in 60 seconds");
}
}
}
}
Expand Down

0 comments on commit 5ebf573

Please sign in to comment.