Remove RethinkDB
This commit is contained in:
parent
5c5153212a
commit
e7fd553c4d
@ -24,7 +24,6 @@ dependencies {
|
||||
implementation 'org.xerial:sqlite-jdbc:3.30.1'
|
||||
implementation 'com.github.Kaaz:ConfigurationBuilder:0.4'
|
||||
implementation 'org.javacord:javacord:3.0.6'
|
||||
implementation group: 'com.rethinkdb', name: 'rethinkdb-driver', version: '2.3.3' // set for removal
|
||||
implementation 'com.vdurmont:emoji-java:4.0.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.4.0'
|
||||
|
||||
|
@ -5,8 +5,6 @@
|
||||
|
||||
package dev.salmonllama.fsbot;
|
||||
|
||||
import com.rethinkdb.RethinkDB;
|
||||
import com.rethinkdb.net.Connection;
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
import dev.salmonllama.fsbot.database.FSDB;
|
||||
import dev.salmonllama.fsbot.guthix.Guthix;
|
||||
@ -14,7 +12,6 @@ import dev.salmonllama.fsbot.listeners.*;
|
||||
import org.javacord.api.DiscordApiBuilder;
|
||||
|
||||
import dev.salmonllama.fsbot.utilities.Constants;
|
||||
import dev.salmonllama.fsbot.utilities.database.DatabaseUtilities;
|
||||
|
||||
// TODO: auto-switching status messages.
|
||||
// TODO: Add an official Logger --> logging to Discord, not console
|
||||
@ -27,20 +24,15 @@ public class Main {
|
||||
|
||||
FSDB.init();
|
||||
|
||||
// Initialise the database with values from the bot's config file
|
||||
RethinkDB r = RethinkDB.r;
|
||||
Connection conn = r.connection().hostname("localhost").port(28015).connect();
|
||||
|
||||
new DiscordApiBuilder().setToken(BotConfig.TOKEN).login().thenAccept(api -> {
|
||||
DatabaseUtilities db = new DatabaseUtilities(r, conn, api);
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
Guthix guthix = new Guthix(api, db);
|
||||
Guthix guthix = new Guthix(api);
|
||||
|
||||
// Register listeners
|
||||
api.addMessageCreateListener(new ImageListener(r, conn));
|
||||
api.addServerMemberJoinListener(new NewMemberListener(api));
|
||||
api.addServerJoinListener(new ServerJoined(api, db));
|
||||
api.addMessageCreateListener(new ImageListener());
|
||||
api.addServerMemberJoinListener(new NewMemberListener());
|
||||
api.addServerJoinListener(new ServerJoined(api));
|
||||
api.addMessageCreateListener(new ThumbsListener());
|
||||
api.addMessageCreateListener(new AchievementListener());
|
||||
api.addMessageCreateListener(new ReportListener());
|
||||
|
@ -5,8 +5,6 @@
|
||||
|
||||
package dev.salmonllama.fsbot.commands.developer;
|
||||
|
||||
import com.rethinkdb.RethinkDB;
|
||||
import com.rethinkdb.net.Connection;
|
||||
import com.vdurmont.emoji.EmojiManager;
|
||||
import dev.salmonllama.fsbot.database.controllers.GalleryController;
|
||||
import dev.salmonllama.fsbot.database.models.GalleryChannel;
|
||||
|
@ -10,21 +10,10 @@ import dev.salmonllama.fsbot.guthix.Command;
|
||||
import dev.salmonllama.fsbot.guthix.CommandContext;
|
||||
import dev.salmonllama.fsbot.guthix.CommandPermission;
|
||||
import dev.salmonllama.fsbot.guthix.PermissionType;
|
||||
import dev.salmonllama.fsbot.utilities.ColorRole;
|
||||
import dev.salmonllama.fsbot.utilities.database.RoleColourUtility;
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.entity.channel.TextChannel;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
import org.javacord.api.entity.permission.Role;
|
||||
import org.javacord.api.entity.server.Server;
|
||||
import dev.salmonllama.fsbot.utilities.warnings.Warning;
|
||||
import org.javacord.api.entity.user.User;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ColorCommand extends Command {
|
||||
@Override public String name() { return "Color"; }
|
||||
@ -36,72 +25,6 @@ public class ColorCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandContext ctx) {
|
||||
if (!ctx.getServer().isPresent()) {
|
||||
ctx.reply("This command must be used inside a server.");
|
||||
return;
|
||||
}
|
||||
String[] args = ctx.getArgs();
|
||||
DiscordApi api = ctx.getApi();
|
||||
Server server = ctx.getServer().get();
|
||||
User user = ctx.getUser();
|
||||
TextChannel channel = ctx.getChannel();
|
||||
|
||||
// Live server
|
||||
if (!server.getIdAsString().equals(BotConfig.HOME_SERVER)) { return; }
|
||||
|
||||
if (!user.getRoles(server).contains(server.getRoleById(BotConfig.HYDRIX_ROLE).orElseThrow(AssertionError::new))) {
|
||||
channel.sendMessage(new Warning("You need the Hydrix role to use this").sendWarning());
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length != 1) {
|
||||
channel.sendMessage(new Warning("Not enough arguments provided").sendWarning());
|
||||
return;
|
||||
}
|
||||
|
||||
// args[0] is the subcommand, either list, or a colour
|
||||
if (args[0].equals("list")) {
|
||||
System.out.println(RoleColourUtility.getAllRoleInfo());
|
||||
return;
|
||||
}
|
||||
|
||||
String roleId = RoleColourUtility.getColour(args[0]);
|
||||
Role role;
|
||||
|
||||
if (!api.getRoleById(roleId).isPresent()) {
|
||||
channel.sendMessage(new Warning("That role doesn't exist, mate!").sendWarning());
|
||||
return;
|
||||
}
|
||||
else {
|
||||
role = api.getRoleById(roleId).get();
|
||||
}
|
||||
|
||||
// Actual command logic now
|
||||
|
||||
// Remove all the colour roles from the user, except the target one
|
||||
List<ColorRole> allRoles = RoleColourUtility.getAllRoles();
|
||||
allRoles.forEach(r -> {
|
||||
if (r.id.equals(roleId)) {
|
||||
server.removeRoleFromUser(user, server.getRoleById(r.id).orElseThrow(AssertionError::new));
|
||||
}
|
||||
});
|
||||
|
||||
// If user already has the role, remove it
|
||||
if (user.getRoles(server).contains(role)) {
|
||||
user.removeRole(role);
|
||||
channel.sendMessage(new EmbedBuilder()
|
||||
.setColor(Color.GREEN)
|
||||
.setTitle("Role Removed")
|
||||
.addInlineField("Role:", role.getName())
|
||||
);
|
||||
}
|
||||
else {
|
||||
user.addRole(role);
|
||||
channel.sendMessage(new EmbedBuilder()
|
||||
.setColor(Color.GREEN)
|
||||
.setTitle("Role Added")
|
||||
.addInlineField("Role:", role.getName())
|
||||
);
|
||||
}
|
||||
ctx.reply("This command is a WIP and will be available soon");
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,6 @@ import dev.salmonllama.fsbot.guthix.Command;
|
||||
import dev.salmonllama.fsbot.guthix.CommandContext;
|
||||
import dev.salmonllama.fsbot.guthix.CommandPermission;
|
||||
import dev.salmonllama.fsbot.guthix.PermissionType;
|
||||
import org.javacord.api.entity.channel.TextChannel;
|
||||
import org.javacord.api.entity.server.Server;
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
import dev.salmonllama.fsbot.utilities.ColorRole;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -28,17 +24,6 @@ public class ColorsCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandContext ctx) {
|
||||
if (!ctx.getServer().isPresent()) {
|
||||
ctx.reply("This command must be used in a server.");
|
||||
return;
|
||||
}
|
||||
Server server = ctx.getServer().get();
|
||||
TextChannel channel = ctx.getChannel();
|
||||
|
||||
if (!server.getIdAsString().equals(BotConfig.HOME_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
channel.sendMessage(ColorRole.rolesListEmbed());
|
||||
ctx.reply("This command is a WIP and will be available soon.");
|
||||
}
|
||||
}
|
||||
|
@ -10,14 +10,7 @@ import dev.salmonllama.fsbot.guthix.Command;
|
||||
import dev.salmonllama.fsbot.guthix.CommandContext;
|
||||
import dev.salmonllama.fsbot.guthix.CommandPermission;
|
||||
import dev.salmonllama.fsbot.guthix.PermissionType;
|
||||
import dev.salmonllama.fsbot.utilities.database.RoleColourUtility;
|
||||
import dev.salmonllama.fsbot.utilities.warnings.Warning;
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.entity.channel.TextChannel;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
import org.javacord.api.entity.permission.Role;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -32,31 +25,6 @@ public class AddColorCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandContext ctx) {
|
||||
String[] args = (String[]) ctx.getArgs();
|
||||
TextChannel channel = ctx.getChannel();
|
||||
DiscordApi api = ctx.getApi();
|
||||
|
||||
if (args.length != 2) {
|
||||
channel.sendMessage(new Warning("Insufficient arguments").sendWarning());
|
||||
return;
|
||||
}
|
||||
|
||||
String colour = args[0];
|
||||
String id = args[1];
|
||||
|
||||
Role role = api.getRoleById(args[1]).orElse(null);
|
||||
if (role == null) {
|
||||
channel.sendMessage(new Warning("Supplied roleId isn't a roleId").sendWarning());
|
||||
return;
|
||||
}
|
||||
|
||||
RoleColourUtility.addColourRole(colour, id);
|
||||
|
||||
channel.sendMessage(new EmbedBuilder()
|
||||
.setTitle(role.getName())
|
||||
.setColor(role.getColor().orElse(Color.GREEN))
|
||||
.addField("Role id:", role.getIdAsString())
|
||||
.addField("Colour to be stored as:", args[0])
|
||||
);
|
||||
ctx.reply("This command is a WIP and will be available soon.");
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,6 @@ import dev.salmonllama.fsbot.guthix.Command;
|
||||
import dev.salmonllama.fsbot.guthix.CommandContext;
|
||||
import dev.salmonllama.fsbot.guthix.CommandPermission;
|
||||
import dev.salmonllama.fsbot.guthix.PermissionType;
|
||||
import org.javacord.api.DiscordApi;
|
||||
import dev.salmonllama.fsbot.utilities.database.DatabaseUtilities;
|
||||
import dev.salmonllama.fsbot.utilities.exceptions.DiscordError;
|
||||
import dev.salmonllama.fsbot.utilities.exceptions.OutfitNotFoundException;
|
||||
import org.javacord.api.entity.channel.TextChannel;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -14,7 +14,6 @@ import dev.salmonllama.fsbot.guthix.CommandPermission;
|
||||
import dev.salmonllama.fsbot.guthix.PermissionType;
|
||||
import org.javacord.api.entity.channel.TextChannel;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
import dev.salmonllama.fsbot.utilities.database.DatabaseUtilities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -10,7 +10,6 @@ import dev.salmonllama.fsbot.guthix.Command;
|
||||
import dev.salmonllama.fsbot.guthix.CommandContext;
|
||||
import dev.salmonllama.fsbot.guthix.CommandPermission;
|
||||
import dev.salmonllama.fsbot.guthix.PermissionType;
|
||||
import dev.salmonllama.fsbot.utilities.database.ServerConfUtility;
|
||||
import dev.salmonllama.fsbot.utilities.warnings.Warning;
|
||||
import org.javacord.api.entity.channel.TextChannel;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
@ -31,84 +30,6 @@ public class WelcomeMessageCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandContext ctx) {
|
||||
if (!ctx.getServer().isPresent()) {
|
||||
ctx.reply("You must use this command in a server");
|
||||
return;
|
||||
}
|
||||
String[] args = ctx.getArgs();
|
||||
TextChannel channel = ctx.getChannel();
|
||||
Server server = ctx.getServer().get();
|
||||
|
||||
if (!server.getIdAsString().equals(BotConfig.HOME_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 0) channel.sendMessage(new Warning("Not enough arguments provided").sendWarning());
|
||||
|
||||
switch (args[0]) {
|
||||
case ("get"):
|
||||
channel.sendMessage(fetchWelcomeMsg(server));
|
||||
break;
|
||||
case ("set"):
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
sb.append(String.format("%s ", args[i]));
|
||||
}
|
||||
|
||||
channel.sendMessage(updateWelcomeMsg(sb.toString(), server));
|
||||
break;
|
||||
case ("getchannel"):
|
||||
channel.sendMessage(fetchWelcomeChannel(server));
|
||||
break;
|
||||
case ("setchannel"):
|
||||
if (args.length < 2) channel.sendMessage(new Warning("Not enough arguments provided").sendWarning());
|
||||
|
||||
channel.sendMessage(updateWelcomeChannel(args[1], server));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private EmbedBuilder fetchWelcomeMsg(Server server) {
|
||||
|
||||
ServerConfUtility conf = new ServerConfUtility(server.getIdAsString());
|
||||
String msg = conf.getWelcomeMsg();
|
||||
|
||||
return new EmbedBuilder()
|
||||
.setColor(Color.GREEN)
|
||||
.setTitle("Current welcome message:")
|
||||
.setDescription(msg);
|
||||
}
|
||||
|
||||
private EmbedBuilder updateWelcomeMsg(String msg, Server server) {
|
||||
|
||||
ServerConfUtility conf = new ServerConfUtility(server.getIdAsString());
|
||||
conf.setWelcomeMsg(msg);
|
||||
|
||||
return new EmbedBuilder()
|
||||
.setColor(Color.GREEN)
|
||||
.setTitle("Welcome message updated")
|
||||
.addField("New welcome message:", msg);
|
||||
}
|
||||
|
||||
private EmbedBuilder fetchWelcomeChannel(Server server) {
|
||||
|
||||
ServerConfUtility conf = new ServerConfUtility(server.getIdAsString());
|
||||
String welcomeChannel = conf.getWelcomeChannel();
|
||||
|
||||
return new EmbedBuilder()
|
||||
.setColor(Color.GREEN)
|
||||
.setTitle("Current welcome channel:")
|
||||
.setDescription(welcomeChannel);
|
||||
}
|
||||
|
||||
private EmbedBuilder updateWelcomeChannel(String id, Server server) {
|
||||
|
||||
ServerConfUtility conf = new ServerConfUtility(server.getIdAsString());
|
||||
conf.setWelcomeChannel(id);
|
||||
|
||||
return new EmbedBuilder()
|
||||
.setColor(Color.GREEN)
|
||||
.setTitle("Welcome channel updated:")
|
||||
.addField("New welcome channel:", id);
|
||||
ctx.reply("This command is a WIP and will be available soon.");
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import dev.salmonllama.fsbot.commands.staff.*;
|
||||
import dev.salmonllama.fsbot.commands.developer.InviteCommand;
|
||||
import dev.salmonllama.fsbot.commands.developer.CreateGalleryCommand;
|
||||
import dev.salmonllama.fsbot.commands.developer.EvalCommand;
|
||||
import dev.salmonllama.fsbot.utilities.database.DatabaseUtilities;
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.entity.message.MessageAuthor;
|
||||
import org.javacord.api.event.message.MessageCreateEvent;
|
||||
@ -27,17 +26,14 @@ import java.util.HashMap;
|
||||
public class Guthix implements MessageCreateListener {
|
||||
@SuppressWarnings("unused")
|
||||
private DiscordApi api;
|
||||
private DatabaseUtilities db;
|
||||
|
||||
private Registry registry;
|
||||
private PermissionManager manager;
|
||||
|
||||
public Guthix(DiscordApi api, DatabaseUtilities db) {
|
||||
public Guthix(DiscordApi api) {
|
||||
this.api = api;
|
||||
api.addMessageCreateListener(this);
|
||||
|
||||
this.db = db;
|
||||
|
||||
manager = new PermissionManager();
|
||||
registry = new Registry();
|
||||
|
||||
@ -47,7 +43,6 @@ public class Guthix implements MessageCreateListener {
|
||||
public void initCommands() {
|
||||
// Developer Commands
|
||||
addCommand(new TestCommand());
|
||||
addCommand(new EvalCommand(db));
|
||||
addCommand(new CreateGalleryCommand());
|
||||
addCommand(new InviteCommand());
|
||||
|
||||
@ -56,7 +51,7 @@ public class Guthix implements MessageCreateListener {
|
||||
addCommand(new GetServersCommand());
|
||||
addCommand(new AddColorCommand());
|
||||
addCommand(new GetOutfitCommand());
|
||||
addCommand(new RetagCommand(db));
|
||||
addCommand(new RetagCommand());
|
||||
addCommand(new RemoveOutfitCommand());
|
||||
addCommand(new OutfitInfoCommand());
|
||||
addCommand(new SetStatusCommand());
|
||||
|
@ -5,8 +5,6 @@
|
||||
|
||||
package dev.salmonllama.fsbot.listeners;
|
||||
|
||||
import com.rethinkdb.RethinkDB;
|
||||
import com.rethinkdb.net.Connection;
|
||||
import dev.salmonllama.fsbot.database.controllers.GalleryController;
|
||||
import dev.salmonllama.fsbot.database.controllers.OutfitController;
|
||||
import dev.salmonllama.fsbot.database.models.Outfit;
|
||||
@ -20,12 +18,7 @@ import java.sql.Timestamp;
|
||||
|
||||
public class ImageListener implements MessageCreateListener {
|
||||
|
||||
final RethinkDB r;
|
||||
final Connection conn;
|
||||
|
||||
public ImageListener(RethinkDB r, Connection conn) {
|
||||
this.r = r;
|
||||
this.conn = conn;
|
||||
public ImageListener() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,33 +5,20 @@
|
||||
|
||||
package dev.salmonllama.fsbot.listeners;
|
||||
|
||||
import dev.salmonllama.fsbot.utilities.database.ServerConfUtility;
|
||||
import org.javacord.api.DiscordApi;
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
import org.javacord.api.event.server.member.ServerMemberJoinEvent;
|
||||
import org.javacord.api.listener.server.member.ServerMemberJoinListener;
|
||||
|
||||
public class NewMemberListener implements ServerMemberJoinListener {
|
||||
|
||||
private DiscordApi api;
|
||||
|
||||
public NewMemberListener(DiscordApi api) {
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
public void onServerMemberJoin(ServerMemberJoinEvent event) {
|
||||
|
||||
if (!event.getServer().getIdAsString().equals("340511685024546816")) return;
|
||||
if (!event.getServer().getIdAsString().equals(BotConfig.HOME_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerConfUtility conf = new ServerConfUtility(event.getServer().getIdAsString());
|
||||
String welcomeMsg = conf.getWelcomeMsg();
|
||||
String welcomeChannel = conf.getWelcomeChannel();
|
||||
// String logMessage = String.format(welcomeMsg, event.getUser().getMentionTag());
|
||||
|
||||
String logMessage = String.format(welcomeMsg, event.getUser().getMentionTag());
|
||||
|
||||
api.getChannelById(welcomeChannel).ifPresent(chnl -> {
|
||||
chnl.asServerTextChannel().ifPresent(channel -> {
|
||||
channel.sendMessage(logMessage);
|
||||
});
|
||||
});
|
||||
event.getApi().getServerTextChannelById(BotConfig.WELCOME_CHANNEL).ifPresent(channel -> channel.sendMessage("Welcome!"));
|
||||
}
|
||||
}
|
||||
|
@ -5,22 +5,16 @@
|
||||
|
||||
package dev.salmonllama.fsbot.listeners;
|
||||
|
||||
import dev.salmonllama.fsbot.utilities.database.DatabaseUtilities;
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
import org.javacord.api.event.server.ServerJoinEvent;
|
||||
import org.javacord.api.listener.server.ServerJoinListener;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ServerJoined implements ServerJoinListener {
|
||||
|
||||
private DiscordApi api;
|
||||
private DatabaseUtilities db;
|
||||
|
||||
public ServerJoined(DiscordApi api, DatabaseUtilities db) {
|
||||
public ServerJoined(DiscordApi api) {
|
||||
this.api = api;
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
public void onServerJoin(ServerJoinEvent event) { // TODO: This needs fixing yo
|
||||
|
Loading…
Reference in New Issue
Block a user