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