commit
d546ed563a
5 changed files with 11 additions and 34 deletions
8
pom.xml
8
pom.xml
|
|
@ -5,7 +5,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>Hadder</groupId>
|
<groupId>Hadder</groupId>
|
||||||
<artifactId>Hadder</artifactId>
|
<artifactId>Hadder</artifactId>
|
||||||
<version>1.3.3</version>
|
<version>1.3.11</version>
|
||||||
<name>Hadder</name>
|
<name>Hadder</name>
|
||||||
<inceptionYear>2019</inceptionYear>
|
<inceptionYear>2019</inceptionYear>
|
||||||
<description>Hadder is a multi-purpose Discord bot.</description>
|
<description>Hadder is a multi-purpose Discord bot.</description>
|
||||||
|
|
@ -66,7 +66,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.dv8tion</groupId>
|
<groupId>net.dv8tion</groupId>
|
||||||
<artifactId>JDA</artifactId>
|
<artifactId>JDA</artifactId>
|
||||||
<version>4.1.1_148</version>
|
<version>4.1.1_149</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.json</groupId>
|
<groupId>org.json</groupId>
|
||||||
|
|
@ -76,7 +76,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.rethinkdb</groupId>
|
<groupId>com.rethinkdb</groupId>
|
||||||
<artifactId>rethinkdb-driver</artifactId>
|
<artifactId>rethinkdb-driver</artifactId>
|
||||||
<version>2.4.0</version>
|
<version>2.4.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
|
|
@ -96,7 +96,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sedmelluq</groupId>
|
<groupId>com.sedmelluq</groupId>
|
||||||
<artifactId>lavaplayer</artifactId>
|
<artifactId>lavaplayer</artifactId>
|
||||||
<version>1.3.47</version>
|
<version>1.3.48</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ public class Hadder {
|
||||||
Rethink rethink = new Rethink(config);
|
Rethink rethink = new Rethink(config);
|
||||||
rethink.connect();
|
rethink.connect();
|
||||||
|
|
||||||
DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.create(GatewayIntent.GUILD_MEMBERS, GatewayIntent.DIRECT_MESSAGE_REACTIONS, GatewayIntent.GUILD_PRESENCES, GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.GUILD_EMOJIS, GatewayIntent.GUILD_MESSAGES);
|
DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.create(GatewayIntent.getIntents(GatewayIntent.ALL_INTENTS));
|
||||||
|
|
||||||
builder.setAutoReconnect(true);
|
builder.setAutoReconnect(true);
|
||||||
builder.setShardsTotal(1);
|
builder.setShardsTotal(1);
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,10 @@ import com.rethinkdb.RethinkDB;
|
||||||
import com.rethinkdb.gen.exc.ReqlNonExistenceError;
|
import com.rethinkdb.gen.exc.ReqlNonExistenceError;
|
||||||
import com.rethinkdb.gen.exc.ReqlOpFailedError;
|
import com.rethinkdb.gen.exc.ReqlOpFailedError;
|
||||||
import com.rethinkdb.net.Connection;
|
import com.rethinkdb.net.Connection;
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
|
|
||||||
public class Rethink {
|
public class Rethink {
|
||||||
private RethinkDB r = RethinkDB.r;
|
private RethinkDB r = RethinkDB.r;
|
||||||
|
|
@ -52,33 +50,12 @@ public class Rethink {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONArray getAsArray(String table, String where, String value) {
|
|
||||||
try {
|
|
||||||
String string = r.table(table).filter(row -> row.g(where.toLowerCase()).eq(value)).coerceTo("array").toJson().run(conn);
|
|
||||||
return new JSONArray(string);
|
|
||||||
} catch (NoSuchElementException e) {
|
|
||||||
return null;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return new JSONArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object get(String table, String where, String value, String column) {
|
|
||||||
JSONArray array = this.getAsArray(table, where, value);
|
|
||||||
if (array.length() > 0)
|
|
||||||
if (array.getJSONObject(0).has(column))
|
|
||||||
return array.getJSONObject(0).get(column);
|
|
||||||
else return null;
|
|
||||||
else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getByID(String table, String where, String column) {
|
public Object getByID(String table, String where, String column) {
|
||||||
return r.table(table).get(where).getField(column).run(conn);
|
return r.table(table).get(where).getField(column).run(conn).first();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject getObjectByID(String table, String id) {
|
public JSONObject getObjectByID(String table, String id) {
|
||||||
String response = r.table(table).get(id).toJson().run(conn);
|
String response = String.valueOf(r.table(table).get(id).toJson().run(conn).first());
|
||||||
try {
|
try {
|
||||||
return new JSONObject(response);
|
return new JSONObject(response);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
|
@ -163,7 +140,7 @@ public class Rethink {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pushServer(RethinkServer server) {
|
public void push(RethinkServer server) {
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
for (Field field : server.getClass().getDeclaredFields()) {
|
for (Field field : server.getClass().getDeclaredFields()) {
|
||||||
if (!field.getName().equals("rethink")) {
|
if (!field.getName().equals("rethink")) {
|
||||||
|
|
@ -177,7 +154,7 @@ public class Rethink {
|
||||||
r.table("server").get(server.getId()).update(object.toMap()).run(conn);
|
r.table("server").get(server.getId()).update(object.toMap()).run(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pushUser(RethinkUser user) {
|
public void push(RethinkUser user) {
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
for (Field field : user.getClass().getDeclaredFields()) {
|
for (Field field : user.getClass().getDeclaredFields()) {
|
||||||
if (!field.getName().equals("rethink")) {
|
if (!field.getName().equals("rethink")) {
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,6 @@ public class RethinkServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void push() {
|
public void push() {
|
||||||
rethink.pushServer(this);
|
rethink.push(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,6 @@ public class RethinkUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void push() {
|
public void push() {
|
||||||
rethink.pushUser(this);
|
rethink.push(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue