Greg dev #269
1 changed files with 35 additions and 38 deletions
|
|
@ -4,7 +4,6 @@ import com.bbn.hadder.core.Config;
|
|||
import com.rethinkdb.RethinkDB;
|
||||
import com.rethinkdb.gen.exc.ReqlOpFailedError;
|
||||
import com.rethinkdb.net.Connection;
|
||||
import com.rethinkdb.net.Cursor;
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
|
@ -56,33 +55,31 @@ public class Rethink {
|
|||
|
||||
public Object get(String table, String where, String value, String column) {
|
||||
JSONArray array = this.getAsArray(table, where, value);
|
||||
if (array.length()>0)
|
||||
if (array.length() > 0)
|
||||
if (array.getJSONObject(0).has(column))
|
||||
return array.getJSONObject(0).get(column);
|
||||
else return null;
|
||||
else return null;
|
||||
}
|
||||
|
||||
public String update(String table, String wherevalue, String what, String whatvalue) {
|
||||
String out = "";
|
||||
public void update(String table, String value, String what, String whatvalue) {
|
||||
try {
|
||||
Cursor cursor = r.table(table).get(wherevalue).update(r.hashMap(what, whatvalue)).run(conn);
|
||||
out=cursor.toString();
|
||||
} catch (ClassCastException ignored) {}
|
||||
return out;
|
||||
r.table(table).get(value).update(r.hashMap(what, whatvalue)).run(conn);
|
||||
} catch (ClassCastException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String insert(String table, Object object) {
|
||||
String out = "";
|
||||
public void insert(String table, Object object) {
|
||||
try {
|
||||
Cursor cursor = r.table(table).insert(object).run(conn);
|
||||
out = cursor.next().toString();
|
||||
} catch (ClassCastException ignored) {}
|
||||
return out;
|
||||
r.table(table).insert(object).run(conn);
|
||||
} catch (ClassCastException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(String table, String where, String wherevalue) {
|
||||
r.table(table).filter(row -> row.g(where.toLowerCase()).eq(wherevalue)).delete().run(conn);
|
||||
public void remove(String table, String where, String value) {
|
||||
r.table(table).filter(row -> row.g(where.toLowerCase()).eq(value)).delete().run(conn);
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
|
|
@ -108,16 +105,16 @@ public class Rethink {
|
|||
}
|
||||
}
|
||||
|
||||
public void setUserPrefix(String prefix, String userid) {
|
||||
this.update("user", userid, "prefix", prefix);
|
||||
public void setUserPrefix(String prefix, String user_id) {
|
||||
this.update("user", user_id, "prefix", prefix);
|
||||
}
|
||||
|
||||
public String getUserPrefix(String id) {
|
||||
return (String) this.get("user", "id", id, "prefix");
|
||||
}
|
||||
|
||||
public void setGuildPrefix(String prefix, String guildid) {
|
||||
this.update("server", guildid, "prefix", prefix);
|
||||
public void setGuildPrefix(String prefix, String guild_id) {
|
||||
this.update("server", guild_id, "prefix", prefix);
|
||||
}
|
||||
|
||||
public String getGuildPrefix(String id) {
|
||||
|
|
@ -139,40 +136,40 @@ public class Rethink {
|
|||
this.insert("user", r.hashMap("id", id).with("prefix", "h.").with("language", "en"));
|
||||
}
|
||||
|
||||
public void setNeededstars(String stars, String guildid) {
|
||||
this.update("server", guildid, "neededstars", stars);
|
||||
public void setNeededstars(String stars, String guild_id) {
|
||||
this.update("server", guild_id, "neededstars", stars);
|
||||
}
|
||||
|
||||
public String getNeededstars(String guildid) {
|
||||
return (String) this.get("server", "id", guildid, "neededstars");
|
||||
public String getNeededstars(String guild_id) {
|
||||
return (String) this.get("server", "id", guild_id, "neededstars");
|
||||
}
|
||||
|
||||
public void setStarboardChannel(String guildid, String channelid) {
|
||||
this.update("server", guildid, "starboard", channelid);
|
||||
public void setStarboardChannel(String guild_id, String channel_id) {
|
||||
this.update("server", guild_id, "starboard", channel_id);
|
||||
}
|
||||
|
||||
public String getStarboardChannel(String guildid) {
|
||||
return (String) this.get("server", "id", guildid, "starboard");
|
||||
public String getStarboardChannel(String guild_id) {
|
||||
return (String) this.get("server", "id", guild_id, "starboard");
|
||||
}
|
||||
|
||||
public boolean hasStarboardChannel(String guildid) {
|
||||
return !this.get("server", "id", guildid, "starboard").equals("");
|
||||
public boolean hasStarboardChannel(String guild_id) {
|
||||
return !this.get("server", "id", guild_id, "starboard").equals("");
|
||||
}
|
||||
|
||||
public void insertStarboardMessage(String messageid, String guildid, String starboardmessageid) {
|
||||
this.insert("stars", r.hashMap("id", messageid).with("guild", guildid).with("starboardmsg", starboardmessageid));
|
||||
public void insertStarboardMessage(String message_id, String guild_id, String starboardmessageid) {
|
||||
this.insert("stars", r.hashMap("id", message_id).with("guild", guild_id).with("starboardmsg", starboardmessageid));
|
||||
}
|
||||
|
||||
public String getStarboardMessage(String messageid) {
|
||||
return (String) this.get("stars", "id", messageid, "starboardmsg");
|
||||
public String getStarboardMessage(String message_id) {
|
||||
return (String) this.get("stars", "id", message_id, "starboardmsg");
|
||||
}
|
||||
|
||||
public void removeStarboardMessage(String messageid) {
|
||||
this.remove("stars", "id", messageid);
|
||||
public void removeStarboardMessage(String message_id) {
|
||||
this.remove("stars", "id", message_id);
|
||||
}
|
||||
|
||||
public boolean hasStarboardMessage(String messageid) {
|
||||
return this.get("stars", "id", messageid, "guild") != null;
|
||||
public boolean hasStarboardMessage(String message_id) {
|
||||
return this.get("stars", "id", message_id, "guild") != null;
|
||||
}
|
||||
|
||||
public void updateRules(String guild_id, String message_id, String role_id, String accept_emote, String decline_emote) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue