Clean imports
This commit is contained in:
1 parent
3b7d8bc6b9
commit
26a0fdc25a
35 files changed
+137
-87
No files matched your search
@@ -38,7 +38,7 @@ public class MusicBot {
|
||||
jda.getPresence().setActivity(Activity.watching("me load..."));
|
||||
jda.addEventListener(new MessageReceivedHandler(), new EditHandler(), new ServerJoinHandler());
|
||||
|
||||
new WebApi();
|
||||
new WebApi(9000);
|
||||
jda.getPresence().setActivity(Activity.watching("you"));
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new BaseThreadFactory("shutdown").newThread(new ShutdownThread()));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package netneutrality.command;/*
|
||||
package netneutrality.command;
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package netneutrality.command;/*
|
||||
package netneutrality.command;
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
|
||||
@@ -3,7 +3,8 @@ package netneutrality.command;
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* This file is closed-source. It should not be distributed or copied in any way or form
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package netneutrality.db;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
public abstract class AbstractController {
|
||||
|
||||
protected MysqlDatabase database;
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package netneutrality.db;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.sql.SQLException;
|
||||
@@ -8,10 +15,8 @@ import java.util.Set;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import netneutrality.MusicBot;
|
||||
import netneutrality.ThreadManager;
|
||||
import netneutrality.utils.Settings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.reflections.Reflections;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -71,9 +76,8 @@ public class DBController {
|
||||
if (controllers.isEmpty())
|
||||
loadControllers();
|
||||
|
||||
((ScheduledExecutorService) ThreadManager.getExecutor("db-keepalive", ThreadManager.ExecutorType.SCHEDULED)).scheduleWithFixedDelay(() -> {
|
||||
DBController.get().query("SELECT 1;");
|
||||
}, 0, 120, TimeUnit.SECONDS);
|
||||
((ScheduledExecutorService) ThreadManager.getExecutor("db-keepalive", ThreadManager.ExecutorType.SCHEDULED))
|
||||
.scheduleWithFixedDelay(() -> DBController.get().query("SELECT 1;"), 0, 120, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package netneutrality.db;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MysqlConnector {
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package netneutrality.db;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@@ -185,7 +192,6 @@ public class MysqlDatabase {
|
||||
*
|
||||
* @param query The PreparedStatement object
|
||||
* @param params The parameters to be included in the prepared statement
|
||||
* @throws SQLException
|
||||
*/
|
||||
private void resolveParameters(PreparedStatement query, Object... params) throws SQLException {
|
||||
int index = 1;
|
||||
@@ -200,16 +206,13 @@ public class MysqlDatabase {
|
||||
query.setLong(index, (Long) p);
|
||||
} else if (p instanceof Double) {
|
||||
query.setDouble(index, (double) p);
|
||||
} else if (p instanceof java.sql.Date) {
|
||||
java.sql.Date d = (java.sql.Date) p;
|
||||
query.setDate(index, d);
|
||||
} else if (p instanceof java.util.Date) {
|
||||
java.util.Date d = (java.util.Date) p;
|
||||
Timestamp ts = new Timestamp(d.getTime());
|
||||
} else if (p instanceof java.sql.Date date) {
|
||||
query.setDate(index, date);
|
||||
} else if (p instanceof java.util.Date date) {
|
||||
Timestamp ts = new Timestamp(date.getTime());
|
||||
query.setTimestamp(index, ts);
|
||||
} else if (p instanceof Calendar) {
|
||||
Calendar cal = (Calendar) p;
|
||||
Timestamp ts = new Timestamp(cal.getTimeInMillis());
|
||||
} else if (p instanceof Calendar cal) {
|
||||
Timestamp ts = new Timestamp(cal.getTimeInMillis());
|
||||
query.setTimestamp(index, ts);
|
||||
} else if (p == null) {
|
||||
query.setNull(index, Types.NULL);
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package netneutrality.db.controllers;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import netneutrality.db.AbstractController;
|
||||
import netneutrality.db.models.MBlacklist;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package netneutrality.db.controllers;/*
|
||||
package netneutrality.db.controllers;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package netneutrality.db.controllers;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import netneutrality.db.AbstractController;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package netneutrality.db.entities;/*
|
||||
package netneutrality.db.entities;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
import netneutrality.MusicBot;
|
||||
import netneutrality.db.DBController;
|
||||
import netneutrality.db.models.MTableModel;
|
||||
import netneutrality.handler.LogHandler;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package netneutrality.db.entities;/*
|
||||
package netneutrality.db.entities;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package netneutrality.db.entities;/*
|
||||
package netneutrality.db.entities;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package netneutrality.db.entities;/*
|
||||
package netneutrality.db.entities;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
@@ -8,8 +10,6 @@ package netneutrality.db.entities;/*
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.db.models.MTableModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OPermission extends AbstractEntity {
|
||||
private final String guild_id;
|
||||
private final String role_id;
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package netneutrality.db.models;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
public class MMessage {
|
||||
|
||||
private final String serverId;
|
||||
|
||||
@@ -3,7 +3,8 @@ package netneutrality.db.models;
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* This file is closed-source. It should not be distributed or copied in any way or form
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -3,7 +3,8 @@ package netneutrality.db.models;
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* This file is closed-source. It should not be distributed or copied in any way or form
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -3,28 +3,29 @@ package netneutrality.db.models;
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* This file is closed-source. It should not be distributed or copied in any way or form
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
public class MSellyOrder {
|
||||
|
||||
private String id;
|
||||
private String product_id;
|
||||
private String email;
|
||||
private String ip;
|
||||
private float value;
|
||||
private String currency;
|
||||
private String gateway;
|
||||
private int risk;
|
||||
private int status;
|
||||
private int cryptoValue;
|
||||
private String cryptoAddress;
|
||||
private float usdValue;
|
||||
private String createdAt;
|
||||
private final String id;
|
||||
private final String productId;
|
||||
private final String email;
|
||||
private final String ip;
|
||||
private final float value;
|
||||
private final String currency;
|
||||
private final String gateway;
|
||||
private final int risk;
|
||||
private final int status;
|
||||
private final int cryptoValue;
|
||||
private final String cryptoAddress;
|
||||
private final float usdValue;
|
||||
private final String createdAt;
|
||||
|
||||
public MSellyOrder(String id, String product_id, String email, String ip, float value, String currency, String gateway, int risk, int status, int cryptoValue, String cryptoAddress, float usdValue, String createdAt) {
|
||||
public MSellyOrder(String id, String productId, String email, String ip, float value, String currency, String gateway, int risk, int status, int cryptoValue, String cryptoAddress, float usdValue, String createdAt) {
|
||||
this.id = id;
|
||||
this.product_id = product_id;
|
||||
this.productId = productId;
|
||||
this.email = email;
|
||||
this.ip = ip;
|
||||
this.value = value;
|
||||
@@ -41,12 +42,11 @@ public class MSellyOrder {
|
||||
//TODO: Construct from JSONObject
|
||||
|
||||
public String getId() {
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getProduct_id() {
|
||||
return product_id;
|
||||
public String getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
@@ -97,7 +97,7 @@ public class MSellyOrder {
|
||||
public String toString() {
|
||||
return "MSellyOrder{" +
|
||||
"id='" + id + '\'' +
|
||||
", product_id='" + product_id + '\'' +
|
||||
", product_id='" + productId + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", ip='" + ip + '\'' +
|
||||
", value='" + value + '\'' +
|
||||
|
||||
@@ -3,7 +3,8 @@ package netneutrality.db.models;
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* This file is closed-source. It should not be distributed or copied in any way or form
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
public class MSellyProduct {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package netneutrality.exceptions;/*
|
||||
package netneutrality.exceptions;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package netneutrality.exceptions;/*
|
||||
package netneutrality.exceptions;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
@@ -9,7 +11,7 @@ import netneutrality.command.CommandContext;
|
||||
|
||||
public abstract class CommandException extends RuntimeException {
|
||||
|
||||
public static String DEFAULT_MESSAGE = "Unknown error during command execution.";
|
||||
public static final String DEFAULT_MESSAGE = "Unknown error during command execution.";
|
||||
private final CommandContext context;
|
||||
|
||||
public CommandException(String message, CommandContext context, Throwable cause) {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package netneutrality.exceptions;/*
|
||||
package netneutrality.exceptions;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package netneutrality.exceptions;/*
|
||||
package netneutrality.exceptions;
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
|
||||
@@ -8,7 +8,6 @@ package netneutrality.handler;
|
||||
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import netneutrality.GuildManager;
|
||||
import netneutrality.MusicBot;
|
||||
import netneutrality.command.CommandContext;
|
||||
import netneutrality.exceptions.CommandErrorException;
|
||||
import netneutrality.exceptions.CommandExecutionException;
|
||||
|
||||
@@ -13,9 +13,7 @@ import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import netneutrality.db.DBController;
|
||||
import netneutrality.db.MysqlDatabase;
|
||||
import netneutrality.db.controllers.DBMessage;
|
||||
import netneutrality.db.controllers.DBSettings;
|
||||
import netneutrality.db.models.MTableModel;
|
||||
|
||||
public class EditHandler extends ListenerAdapter {
|
||||
|
||||
@@ -7,7 +7,6 @@ package netneutrality.handler.hooks.message;
|
||||
*/
|
||||
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import netneutrality.GuildManager;
|
||||
|
||||
@@ -19,11 +19,15 @@ import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
public class MessageRateLimiterImpl implements IMessageRateLimiter {
|
||||
private int messagePerSecond = 5;
|
||||
private final int messagePerSecond = 5;
|
||||
private static Member lastSender;
|
||||
private static OffsetDateTime timestamp;
|
||||
private static final long cooldown = 500000000L; // 1 seconds = 1000000000 nanoseconds
|
||||
|
||||
public MessageRateLimiterImpl() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void check(Member member, Message message, TextChannel channel) {
|
||||
|
||||
@@ -44,7 +48,5 @@ public class MessageRateLimiterImpl implements IMessageRateLimiter {
|
||||
|
||||
lastSender = member;
|
||||
timestamp = message.getTimeCreated();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import java.util.Map;
|
||||
|
||||
public class Selly {
|
||||
|
||||
private byte[] encodedAuth;
|
||||
private final byte[] encodedAuth;
|
||||
|
||||
public Selly(String email, String apiKey) {
|
||||
String concat = email + ":" + apiKey;
|
||||
|
||||
@@ -127,8 +127,6 @@ public class WebModule {
|
||||
|
||||
/**
|
||||
* @return the response as a JSONObject
|
||||
* @throws JSONException
|
||||
* @throws IOException
|
||||
*/
|
||||
public JSONObject getAsObject() throws JSONException, IOException {
|
||||
if (response == null)
|
||||
@@ -141,8 +139,6 @@ public class WebModule {
|
||||
* Use if your response start with an array : [ ]
|
||||
*
|
||||
* @return the response as a JSONArray
|
||||
* @throws JSONException
|
||||
* @throws IOException
|
||||
*/
|
||||
public JSONArray getAsArray() throws JSONException, IOException {
|
||||
if (response == null)
|
||||
@@ -153,8 +149,6 @@ public class WebModule {
|
||||
|
||||
/**
|
||||
* @return the response as a String
|
||||
* @throws JSONException
|
||||
* @throws IOException
|
||||
*/
|
||||
public String getRawData() throws IOException {
|
||||
if (response == null)
|
||||
|
||||
@@ -44,10 +44,11 @@ public class ActionHandler extends AbstractHandler {
|
||||
if (path.startsWith("/actions/settings/current/")) {
|
||||
JSONObject json = new JSONObject();
|
||||
String[] args = exchange.getRequestURI().toString().split("/");
|
||||
String guild = args[args.length - 1];
|
||||
String guildId = args[args.length - 1];
|
||||
|
||||
GuildManager manager = GuildManager.getManager(MusicBot.getJDA().getGuildById(guild));
|
||||
if (manager != null) {
|
||||
Guild guild = MusicBot.getJDA().getGuildById(guildId);
|
||||
if (guild != null) {
|
||||
GuildManager manager = GuildManager.getManager(guild);
|
||||
Map<String, Object> settings = manager.getSettings();
|
||||
JSONObject setting = new JSONObject(settings);
|
||||
|
||||
|
||||
@@ -8,18 +8,12 @@ package netneutrality.http.server;
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import netneutrality.MusicBot;
|
||||
import netneutrality.http.WebModule;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.*;
|
||||
|
||||
public class GuildHandler extends AbstractHandler {
|
||||
|
||||
|
||||
@@ -8,10 +8,8 @@ package netneutrality.http.server;
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class RootHandler extends AbstractHandler {
|
||||
|
||||
|
||||
@@ -21,13 +21,12 @@ import java.util.concurrent.Executors;
|
||||
public class WebApi {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(WebApi.class);
|
||||
private final ExecutorService executor = Executors.newFixedThreadPool(10, new BaseThreadFactory("web-api"));
|
||||
|
||||
private final int port = 9000;
|
||||
private HttpServer server;
|
||||
|
||||
public WebApi() {
|
||||
public WebApi(int port) {
|
||||
logger.info("Starting web server...");
|
||||
|
||||
try {
|
||||
InetAddress localHost = InetAddress.getLoopbackAddress();
|
||||
InetSocketAddress sockAddr = new InetSocketAddress(localHost, port);
|
||||
@@ -39,6 +38,7 @@ public class WebApi {
|
||||
server.createContext("/", new RootHandler());
|
||||
server.createContext("/actions", new ActionHandler());
|
||||
server.createContext("/guilds", new GuildHandler());
|
||||
ExecutorService executor = Executors.newFixedThreadPool(10, new BaseThreadFactory("web-api"));
|
||||
server.setExecutor(executor);
|
||||
server.start();
|
||||
logger.info("Web server started at [" + server.getAddress() + "]");
|
||||
|
||||
Reference in new issue
Block a user