adding discord framework
This commit is contained in:
@@ -44,12 +44,12 @@ public class CarrierFilter {
|
|||||||
//return Uni.createFrom().nothing();
|
//return Uni.createFrom().nothing();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@Broadcast
|
||||||
@Outgoing("eddn-carrier")
|
@Outgoing("eddn-carrier")
|
||||||
public CompletionStage<EddnJournal> brodcastCarrierOnlyEvents() {
|
public Uni<EddnJournal> brodcastCarrierOnlyEvents() {
|
||||||
|
|
||||||
|
|
||||||
return CompletableFuture.supplyAsync(new Supplier<EddnJournal>() {
|
CompletionStage<EddnJournal> stage= CompletableFuture.supplyAsync(new Supplier<EddnJournal>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EddnJournal get() {
|
public EddnJournal get() {
|
||||||
@@ -63,6 +63,7 @@ public class CarrierFilter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return Uni.createFrom().completionStage(stage);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ public class CarrierService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public void save(Carrier car) {
|
public void save(Carrier car) {
|
||||||
org.hibernate.Session session=em.unwrap(org.hibernate.Session.class);
|
org.hibernate.Session session=em.unwrap(org.hibernate.Session.class);
|
||||||
|
//session.merge(car);
|
||||||
session.saveOrUpdate(car);
|
session.saveOrUpdate(car);
|
||||||
em.flush();
|
em.flush();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,17 @@ import javax.enterprise.context.ApplicationScoped;
|
|||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
|
|
||||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||||
|
import org.eclipse.microprofile.reactive.messaging.Incoming;
|
||||||
|
|
||||||
|
import fun.manuel.data.CarrierAnalysesContext;
|
||||||
|
import fun.manuel.data.Message.Event;
|
||||||
import io.quarkus.runtime.Startup;
|
import io.quarkus.runtime.Startup;
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.JDABuilder;
|
import net.dv8tion.jda.api.JDABuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Invite.Channel;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.events.GenericEvent;
|
import net.dv8tion.jda.api.events.GenericEvent;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.hooks.EventListener;
|
import net.dv8tion.jda.api.hooks.EventListener;
|
||||||
@@ -21,9 +26,14 @@ public class DiscordBotService {
|
|||||||
@ConfigProperty(name = "bot.token")
|
@ConfigProperty(name = "bot.token")
|
||||||
private String bottoken;
|
private String bottoken;
|
||||||
private JDA jda;
|
private JDA jda;
|
||||||
|
private User manuel;
|
||||||
|
private MessageChannel channel;
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void startup() throws LoginException {
|
private void startup() throws LoginException, InterruptedException {
|
||||||
this.jda=JDABuilder.createDefault(bottoken).build();
|
this.jda=JDABuilder.createDefault(bottoken).addEventListeners(pingpong).build();
|
||||||
|
jda.awaitReady();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EventListener pingpong=new EventListener() {
|
EventListener pingpong=new EventListener() {
|
||||||
@@ -33,6 +43,7 @@ public class DiscordBotService {
|
|||||||
if(eventg instanceof MessageReceivedEvent) {
|
if(eventg instanceof MessageReceivedEvent) {
|
||||||
MessageReceivedEvent event=(MessageReceivedEvent) eventg;
|
MessageReceivedEvent event=(MessageReceivedEvent) eventg;
|
||||||
if (event.getAuthor().isBot()) return;
|
if (event.getAuthor().isBot()) return;
|
||||||
|
|
||||||
// We don't want to respond to other bot accounts, including ourself
|
// We don't want to respond to other bot accounts, including ourself
|
||||||
Message message = event.getMessage();
|
Message message = event.getMessage();
|
||||||
String content = message.getContentRaw();
|
String content = message.getContentRaw();
|
||||||
@@ -41,9 +52,34 @@ public class DiscordBotService {
|
|||||||
if (content.equals("!ping"))
|
if (content.equals("!ping"))
|
||||||
{
|
{
|
||||||
MessageChannel channel = event.getChannel();
|
MessageChannel channel = event.getChannel();
|
||||||
|
|
||||||
channel.sendMessage("Pong!").queue(); // Important to call .queue() on the RestAction returned by sendMessage(...)
|
channel.sendMessage("Pong!").queue(); // Important to call .queue() on the RestAction returned by sendMessage(...)
|
||||||
}
|
}
|
||||||
|
if (content.equals("!setlog")){
|
||||||
|
MessageChannel cha = event.getChannel();
|
||||||
|
cha.sendMessage("Set channel!").queue(); // Important to call .queue() on the RestAction returned by sendMessage(...)
|
||||||
|
channel=cha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Incoming("carrier-update")
|
||||||
|
public void sendcarrierLog(CarrierAnalysesContext context) {
|
||||||
|
if(channel!=null) {
|
||||||
|
StringBuilder stringBuilder=new StringBuilder();
|
||||||
|
stringBuilder.append("Carrier Event: " + context.getFreshCarrier().getId() + " | " + context.getEntry().getMessage().getEvent().toString());
|
||||||
|
|
||||||
|
if(context.getStoredCarrier()!=null) {
|
||||||
|
if (context.getEntry().getMessage().getEvent() == Event.CARRIER_JUMP) {
|
||||||
|
stringBuilder.append("\t" + context.getStoredCarrier().getSystem() + " -> " + context.getFreshCarrier().getSystem());
|
||||||
|
}else {
|
||||||
|
stringBuilder.append("\tUpdated: " + context.getFreshCarrier().toString());
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
stringBuilder.append("\tRegisterd: " + context.getFreshCarrier().toString());
|
||||||
|
}
|
||||||
|
channel.sendMessage(stringBuilder.toString()).queue();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,10 +41,13 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.CompletionStage;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.function.Supplier;
|
||||||
import java.util.zip.DataFormatException;
|
import java.util.zip.DataFormatException;
|
||||||
import java.util.zip.Inflater;
|
import java.util.zip.Inflater;
|
||||||
|
|
||||||
@@ -76,13 +79,23 @@ public class EddnPump {
|
|||||||
|
|
||||||
@Outgoing("eddn-full")
|
@Outgoing("eddn-full")
|
||||||
public Uni<EddnJournal> publishJournal() {
|
public Uni<EddnJournal> publishJournal() {
|
||||||
try {
|
|
||||||
return Uni.createFrom().item(journalqueue.take());
|
CompletionStage<EddnJournal> stage= CompletableFuture.supplyAsync(new Supplier<EddnJournal>() {
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
@Override
|
||||||
e.printStackTrace();
|
public EddnJournal get() {
|
||||||
}
|
// TODO Auto-generated method stub
|
||||||
return null;
|
try {
|
||||||
|
return journalqueue.take();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Uni.createFrom().completionStage(stage);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,4 +3,4 @@
|
|||||||
quarkus.datasource.db-kind=h2
|
quarkus.datasource.db-kind=h2
|
||||||
quarkus.datasource.jdbc.url=jdbc:h2:~\\default
|
quarkus.datasource.jdbc.url=jdbc:h2:~\\default
|
||||||
quarkus.hibernate-orm.database.generation=none
|
quarkus.hibernate-orm.database.generation=none
|
||||||
bot.token=NzIyNDEyODk5Nzc5NDc3NTk0.Xuivdw.hiqHtxIG6jLXukYDJvhNYxW95P4
|
bot.token=NzIyNDEyODk5Nzc5NDc3NTk0.XujBYA.VB47K8Vi7SNGjccizMFZef6wHjM
|
||||||
Reference in New Issue
Block a user