More object oriented programming
This commit is contained in:
parent
82a714791d
commit
634d96b426
@ -38,4 +38,4 @@ compileJava.options.encoding = 'UTF-8'
|
|||||||
compileJava.options.fork = true
|
compileJava.options.fork = true
|
||||||
|
|
||||||
// Change this if you are getting errors building
|
// Change this if you are getting errors building
|
||||||
compileJava.options.forkOptions.executable = 'C:\\Program Files\\Java\\jdk1.8.0_144\\bin\\javac.exe'
|
compileJava.options.forkOptions.executable = 'C:\\Program Files\\Java\\jdk1.8.0_131\\bin\\javac.exe'
|
@ -26,7 +26,6 @@ public class Database {
|
|||||||
private String database;
|
private String database;
|
||||||
|
|
||||||
private int port = 3306;
|
private int port = 3306;
|
||||||
private int timeout = 60 * 1000;
|
|
||||||
|
|
||||||
private HikariDataSource source;
|
private HikariDataSource source;
|
||||||
private HikariConfig config = new HikariConfig();
|
private HikariConfig config = new HikariConfig();
|
||||||
@ -49,6 +48,8 @@ public class Database {
|
|||||||
this.config.setUsername(this.username = username);
|
this.config.setUsername(this.username = username);
|
||||||
this.config.setPassword(this.password = password);
|
this.config.setPassword(this.password = password);
|
||||||
this.source = new HikariDataSource(config);
|
this.source = new HikariDataSource(config);
|
||||||
|
this.source.setPoolName("rixa");
|
||||||
|
this.source.setMaximumPoolSize(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,15 +62,6 @@ public class Database {
|
|||||||
return new DatabaseOptions();
|
return new DatabaseOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Connects to the database
|
|
||||||
*
|
|
||||||
* @return Whether it connected or not
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public void init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a query to the database
|
* Sends a query to the database
|
||||||
*
|
*
|
||||||
@ -88,7 +80,7 @@ public class Database {
|
|||||||
return Optional.of(preparedStatement.executeUpdate());
|
return Optional.of(preparedStatement.executeUpdate());
|
||||||
}
|
}
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
System.out.println("INFO: Couldn't send update / query! : " + exception.getLocalizedMessage());
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,7 +98,7 @@ public class Database {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
// Can't handle closing statement
|
// Can't handle closing statement
|
||||||
e.printStackTrace();
|
System.out.println("INFO: Close connection! : " + e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +111,7 @@ public class Database {
|
|||||||
*/
|
*/
|
||||||
public Optional<PreparedStatement> prepare(Statement statement) {
|
public Optional<PreparedStatement> prepare(Statement statement) {
|
||||||
try {
|
try {
|
||||||
PreparedStatement preparedStatement = source.getConnection().prepareStatement(statement.getSQL());
|
PreparedStatement preparedStatement = getConnection().get().prepareStatement(statement.getSQL());
|
||||||
for (Map.Entry<Integer, Parameter> parameter : statement.getParameters().entrySet()) {
|
for (Map.Entry<Integer, Parameter> parameter : statement.getParameters().entrySet()) {
|
||||||
switch (parameter.getValue().getType()) {
|
switch (parameter.getValue().getType()) {
|
||||||
case STRING:
|
case STRING:
|
||||||
@ -156,7 +148,7 @@ public class Database {
|
|||||||
}
|
}
|
||||||
return Optional.of(preparedStatement);
|
return Optional.of(preparedStatement);
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
System.out.println("INFO: Couldn't prepare statement : " + exception.getLocalizedMessage());
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +164,7 @@ public class Database {
|
|||||||
try {
|
try {
|
||||||
return Optional.of(source.getConnection().prepareStatement(sql));
|
return Optional.of(source.getConnection().prepareStatement(sql));
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
System.out.println("INFO: Couldn't send update / query! : " + exception.getLocalizedMessage());
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,6 +179,7 @@ public class Database {
|
|||||||
try {
|
try {
|
||||||
return Optional.of(source.getConnection());
|
return Optional.of(source.getConnection());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
System.out.println("INFO: Couldn't get connection : " + e.getLocalizedMessage());
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
package me.majrly.database;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apart of the database api to manage all your databases
|
|
||||||
*
|
|
||||||
* @author Majrly
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public class DatabaseManager {
|
|
||||||
|
|
||||||
private static HashMap<String, Database> databases = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a database to {@link #databases}
|
|
||||||
*
|
|
||||||
* @param database The database you want to add
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public static void addDatabase(Database database) {
|
|
||||||
databases.put(database.getName(), database);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a database with specified name from {@link #databases}
|
|
||||||
*
|
|
||||||
* @param name The name of the database you want to obtain
|
|
||||||
* @return The database wrapper
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public static Database getDatabase(String name) {
|
|
||||||
return databases.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters
|
|
||||||
public static HashMap<String, Database> getDatabases() {
|
|
||||||
return databases;
|
|
||||||
}
|
|
||||||
}
|
|
@ -25,7 +25,9 @@ import me.savvy.rixa.data.filemanager.LanguageManager;
|
|||||||
import me.savvy.rixa.events.BotEvent;
|
import me.savvy.rixa.events.BotEvent;
|
||||||
import me.savvy.rixa.events.MemberEvent;
|
import me.savvy.rixa.events.MemberEvent;
|
||||||
import me.savvy.rixa.events.MessageEvent;
|
import me.savvy.rixa.events.MessageEvent;
|
||||||
|
import me.savvy.rixa.events.Shutdown;
|
||||||
import me.savvy.rixa.events.VoiceChannel;
|
import me.savvy.rixa.events.VoiceChannel;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.modules.reactions.handlers.React;
|
import me.savvy.rixa.modules.reactions.handlers.React;
|
||||||
import me.savvy.rixa.modules.reactions.handlers.ReactionManager;
|
import me.savvy.rixa.modules.reactions.handlers.ReactionManager;
|
||||||
import me.savvy.rixa.modules.reactions.react.ConfigReaction;
|
import me.savvy.rixa.modules.reactions.react.ConfigReaction;
|
||||||
@ -38,6 +40,7 @@ import net.dv8tion.jda.core.OnlineStatus;
|
|||||||
import net.dv8tion.jda.core.entities.Game;
|
import net.dv8tion.jda.core.entities.Game;
|
||||||
import net.dv8tion.jda.core.exceptions.RateLimitedException;
|
import net.dv8tion.jda.core.exceptions.RateLimitedException;
|
||||||
import net.dv8tion.jda.core.hooks.AnnotatedEventManager;
|
import net.dv8tion.jda.core.hooks.AnnotatedEventManager;
|
||||||
|
import net.dv8tion.jda.core.requests.Route;
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -65,9 +68,6 @@ public class Rixa {
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private static Database database;
|
private static Database database;
|
||||||
private static ChatterBotFactory factory;
|
|
||||||
private static ChatterBotSession chatBotSession;
|
|
||||||
private static ChatterBot chatBot;
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private LanguageManager languageManager;
|
private LanguageManager languageManager;
|
||||||
@ -75,17 +75,28 @@ public class Rixa {
|
|||||||
@Setter
|
@Setter
|
||||||
private ScheduledExecutorService executorService;
|
private ScheduledExecutorService executorService;
|
||||||
|
|
||||||
|
private static ChatterBotFactory factory;
|
||||||
|
private static ChatterBotSession chatBotSession;
|
||||||
|
private static ChatterBot chatBot;
|
||||||
|
|
||||||
// String search = event.getMessage().getContent().substring(event.getMessage().getContent().indexOf(" ") + 1);
|
// String search = event.getMessage().getContent().substring(event.getMessage().getContent().indexOf(" ") + 1);
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
instance = new Rixa();
|
instance = new Rixa();
|
||||||
shardsList = new LinkedList<>();
|
shardsList = new LinkedList<>();
|
||||||
// config = new ConfigManager();
|
|
||||||
config = new ConfigManager(new File("Rixa/config.json"));
|
config = new ConfigManager(new File("Rixa/config.json"));
|
||||||
load();
|
load();
|
||||||
|
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
getShardsList().forEach(JDA::shutdown);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void load() {
|
private static void load() {
|
||||||
getInstance().setExecutorService(Executors.newSingleThreadScheduledExecutor());
|
getInstance().setExecutorService(Executors.newSingleThreadScheduledExecutor());
|
||||||
|
|
||||||
database = Database.options()
|
database = Database.options()
|
||||||
.type("mysql")
|
.type("mysql")
|
||||||
.hostname(String.valueOf(config.getJsonObject().getJSONObject("sql").getString("hostName")), config.getJsonObject().getJSONObject("sql").getInt("portNumber"))
|
.hostname(String.valueOf(config.getJsonObject().getJSONObject("sql").getString("hostName")), config.getJsonObject().getJSONObject("sql").getInt("portNumber"))
|
||||||
@ -97,6 +108,7 @@ public class Rixa {
|
|||||||
database.send(new Update(databaseTables.getQuery()));
|
database.send(new Update(databaseTables.getQuery()));
|
||||||
getInstance().getLogger().info("Done checking " + databaseTables.toString());
|
getInstance().getLogger().info("Done checking " + databaseTables.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
getInstance().setLanguageManager(new LanguageManager(new File("Rixa/languages/language.json")));
|
getInstance().setLanguageManager(new LanguageManager(new File("Rixa/languages/language.json")));
|
||||||
try {
|
try {
|
||||||
int shards = 5;
|
int shards = 5;
|
||||||
@ -109,6 +121,7 @@ public class Rixa {
|
|||||||
.addEventListener(new BotEvent())
|
.addEventListener(new BotEvent())
|
||||||
.addEventListener(new MemberEvent())
|
.addEventListener(new MemberEvent())
|
||||||
.addEventListener(new VoiceChannel())
|
.addEventListener(new VoiceChannel())
|
||||||
|
.addEventListener(new Shutdown())
|
||||||
.setGame(Game.of(config.getJsonObject().getString("botGame")))
|
.setGame(Game.of(config.getJsonObject().getString("botGame")))
|
||||||
.setAutoReconnect(true)
|
.setAutoReconnect(true)
|
||||||
.setStatus(OnlineStatus.ONLINE)
|
.setStatus(OnlineStatus.ONLINE)
|
||||||
@ -120,15 +133,17 @@ public class Rixa {
|
|||||||
} catch (LoginException | InterruptedException | RateLimitedException e) {
|
} catch (LoginException | InterruptedException | RateLimitedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Guilds.getGuilds().values().parallelStream().forEach((rixaGuild) -> rixaGuild.load());
|
||||||
|
|
||||||
timeUp = System.currentTimeMillis();
|
timeUp = System.currentTimeMillis();
|
||||||
register(new CommandExec[]{
|
register(new InfoCommand(), new ServerInfoCommand(), new HelpCommand(),
|
||||||
new InfoCommand(), new ServerInfoCommand(), new HelpCommand(),
|
|
||||||
new DeleteMessagesCommand(), new PingCommand(), new PurgeMessagesCommand(),
|
new DeleteMessagesCommand(), new PingCommand(), new PurgeMessagesCommand(),
|
||||||
new BatchMoveCommand(), new MuteCommand(), new MusicCommand(),
|
new BatchMoveCommand(), new MuteCommand(), new MusicCommand(),
|
||||||
new ConfigCommand(), new UrbanDictionaryCommand(), new YoutubeCommand(),
|
new ConfigCommand(), new UrbanDictionaryCommand(), new YoutubeCommand(),
|
||||||
new AddRoleCommand(), new RemoveRoleCommand(), new LevelsCommand(),
|
new AddRoleCommand(), new RemoveRoleCommand(), new LevelsCommand(),
|
||||||
new LeaderboardCommand(), new RaidModeCommand()});
|
new LeaderboardCommand(), new RaidModeCommand());
|
||||||
register(new React[]{new HelpReaction(), new ConfigReaction(), new LeaderboardReaction()});
|
register(new HelpReaction(), new ConfigReaction(), new LeaderboardReaction());
|
||||||
try {
|
try {
|
||||||
factory = new ChatterBotFactory();
|
factory = new ChatterBotFactory();
|
||||||
chatBot = factory.create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477");
|
chatBot = factory.create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477");
|
||||||
@ -138,13 +153,13 @@ public class Rixa {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void register(CommandExec commandExecs[]) {
|
private static void register(CommandExec... commandExecs) {
|
||||||
for (CommandExec command : commandExecs) {
|
for (CommandExec command : commandExecs) {
|
||||||
CommandHandler.registerCommand(command);
|
CommandHandler.registerCommand(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void register(React react[]) {
|
private static void register(React... react) {
|
||||||
for (React reaction : react) {
|
for (React reaction : react) {
|
||||||
ReactionManager.registerReaction(reaction);
|
ReactionManager.registerReaction(reaction);
|
||||||
}
|
}
|
||||||
@ -159,10 +174,15 @@ public class Rixa {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void exit() {
|
||||||
|
getShardsList().forEach(JDA::shutdown);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
try {
|
try {
|
||||||
|
Guilds.getGuilds().values().parallelStream().forEach((rixaGuild) -> rixaGuild.save());
|
||||||
|
Thread.sleep(1200);
|
||||||
database.close();
|
database.close();
|
||||||
getShardsList().forEach(JDA::shutdown);
|
Thread.sleep(200);
|
||||||
Thread.sleep(5000);
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
getLogger().severe("Could not shutdown Rixa instance.");
|
getLogger().severe("Could not shutdown Rixa instance.");
|
||||||
|
@ -5,15 +5,13 @@ import me.savvy.rixa.commands.handlers.CommandExec;
|
|||||||
import me.savvy.rixa.commands.handlers.CommandType;
|
import me.savvy.rixa.commands.handlers.CommandType;
|
||||||
import me.savvy.rixa.commands.handlers.RixaPermission;
|
import me.savvy.rixa.commands.handlers.RixaPermission;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.entities.Role;
|
import net.dv8tion.jda.core.entities.Role;
|
||||||
import net.dv8tion.jda.core.entities.TextChannel;
|
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||||
import net.dv8tion.jda.core.exceptions.PermissionException;
|
import net.dv8tion.jda.core.exceptions.PermissionException;
|
||||||
import net.dv8tion.jda.core.managers.GuildManager;
|
|
||||||
import net.dv8tion.jda.core.requests.restaction.InviteAction;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -28,7 +26,7 @@ public class AddRoleCommand implements CommandExec {
|
|||||||
channelType = ChannelType.TEXT,
|
channelType = ChannelType.TEXT,
|
||||||
usage = "%paddrole", mainCommand = "addrole", aliases = {"ar", "addroles", "ars"})
|
usage = "%paddrole", mainCommand = "addrole", aliases = {"ar", "addroles", "ars"})
|
||||||
public void execute(GuildMessageReceivedEvent event) {
|
public void execute(GuildMessageReceivedEvent event) {
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.ADD_ROLE)) {
|
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.ADD_ROLE)) {
|
||||||
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
return;
|
return;
|
||||||
|
@ -4,6 +4,7 @@ import me.savvy.rixa.commands.handlers.Command;
|
|||||||
import me.savvy.rixa.commands.handlers.CommandExec;
|
import me.savvy.rixa.commands.handlers.CommandExec;
|
||||||
import me.savvy.rixa.commands.handlers.RixaPermission;
|
import me.savvy.rixa.commands.handlers.RixaPermission;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.entities.Member;
|
import net.dv8tion.jda.core.entities.Member;
|
||||||
@ -25,7 +26,7 @@ public class BatchMoveCommand implements CommandExec {
|
|||||||
description = "Move users within one role to another!",
|
description = "Move users within one role to another!",
|
||||||
channelType = ChannelType.TEXT)
|
channelType = ChannelType.TEXT)
|
||||||
public void execute(GuildMessageReceivedEvent event) {
|
public void execute(GuildMessageReceivedEvent event) {
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.BATCH_MOVE)) {
|
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.BATCH_MOVE)) {
|
||||||
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
return;
|
return;
|
||||||
|
@ -5,6 +5,9 @@ import me.savvy.rixa.commands.handlers.CommandExec;
|
|||||||
import me.savvy.rixa.commands.handlers.CommandType;
|
import me.savvy.rixa.commands.handlers.CommandType;
|
||||||
import me.savvy.rixa.commands.handlers.RixaPermission;
|
import me.savvy.rixa.commands.handlers.RixaPermission;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
|
import me.savvy.rixa.modules.levels.LevelsModule;
|
||||||
|
import me.savvy.rixa.modules.music.MusicModule;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.entities.Member;
|
import net.dv8tion.jda.core.entities.Member;
|
||||||
@ -55,7 +58,7 @@ public class ConfigCommand implements CommandExec {
|
|||||||
type = CommandType.ADMIN,
|
type = CommandType.ADMIN,
|
||||||
channelType = ChannelType.TEXT)
|
channelType = ChannelType.TEXT)
|
||||||
public void execute(GuildMessageReceivedEvent event) {
|
public void execute(GuildMessageReceivedEvent event) {
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
if (!rixaGuild.hasPermission(event.getMember(), RixaPermission.ACCESS_CONFIG)) {
|
if (!rixaGuild.hasPermission(event.getMember(), RixaPermission.ACCESS_CONFIG)) {
|
||||||
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.")
|
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.")
|
||||||
.setColor(event.getMember().getColor()).queue(event.getChannel());
|
.setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
@ -166,34 +169,34 @@ public class ConfigCommand implements CommandExec {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Role role = event.getMessage().getMentionedRoles().get(0);
|
Role role = event.getMessage().getMentionedRoles().get(0);
|
||||||
rixaGuild.getMusicModule().setRole(role.getId());
|
((MusicModule) rixaGuild.getModule("Music")).setMusicRole(role.getId());
|
||||||
new MessageBuilder("Successfully set music role to " + role.getName() + "!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder("Successfully set music role to " + role.getName() + "!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
}
|
}
|
||||||
} else if (messages[1].equalsIgnoreCase("enable")) {
|
} else if (messages[1].equalsIgnoreCase("enable")) {
|
||||||
if (messages[2].equalsIgnoreCase("music")) {
|
if (messages[2].equalsIgnoreCase("music")) {
|
||||||
RixaGuild.getGuild(event.getGuild()).getMusicModule().setEnabled(true);
|
((MusicModule) rixaGuild.getModule("Music")).setEnabled(true);
|
||||||
new MessageBuilder("Successfully enabled the music module!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder("Successfully enabled the music module!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
} else if (messages[2].equalsIgnoreCase("levels")) {
|
} else if (messages[2].equalsIgnoreCase("levels")) {
|
||||||
RixaGuild.getGuild(event.getGuild()).getLevelsModule().setEnabled(true);
|
((LevelsModule) rixaGuild.getModule("Levels")).setEnabled(true);
|
||||||
event.getChannel().sendMessage("Successfully enabled the levels module").queue();
|
event.getChannel().sendMessage("Successfully enabled the levels module").queue();
|
||||||
} else if (messages[2].equalsIgnoreCase("joinverification")) {
|
} else if (messages[2].equalsIgnoreCase("joinverification")) {
|
||||||
RixaGuild.getGuild(event.getGuild()).getGuildSettings().setJoinVerification(true);
|
Guilds.getGuild(event.getGuild()).getGuildSettings().setJoinVerification(true);
|
||||||
new MessageBuilder("Successfully enabled Join Verification!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder("Successfully enabled Join Verification!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
}
|
}
|
||||||
} else if (messages[1].equalsIgnoreCase("disable")) {
|
} else if (messages[1].equalsIgnoreCase("disable")) {
|
||||||
if (messages[2].equalsIgnoreCase("music")) {
|
if (messages[2].equalsIgnoreCase("music")) {
|
||||||
RixaGuild.getGuild(event.getGuild()).getMusicModule().setEnabled(false);
|
((MusicModule) rixaGuild.getModule("Music")).setEnabled(false);
|
||||||
new MessageBuilder("Successfully disabled the music module!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder("Successfully disabled the music module!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
} else if (messages[2].equalsIgnoreCase("levels")) {
|
} else if (messages[2].equalsIgnoreCase("levels")) {
|
||||||
RixaGuild.getGuild(event.getGuild()).getLevelsModule().setEnabled(false);
|
((MusicModule) rixaGuild.getModule("Music")).setEnabled(false);
|
||||||
event.getChannel().sendMessage("Successfully disabled the levels module").queue();
|
event.getChannel().sendMessage("Successfully disabled the levels module").queue();
|
||||||
} else if (messages[2].equalsIgnoreCase("joinverification")) {
|
} else if (messages[2].equalsIgnoreCase("joinverification")) {
|
||||||
RixaGuild.getGuild(event.getGuild()).getGuildSettings().setJoinVerification(false);
|
Guilds.getGuild(event.getGuild()).getGuildSettings().setJoinVerification(false);
|
||||||
new MessageBuilder("Successfully disabled Join Verification!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder("Successfully disabled Join Verification!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
} else if (messages[2].equalsIgnoreCase("joinmessage")) {
|
} else if (messages[2].equalsIgnoreCase("joinmessage")) {
|
||||||
RixaGuild.getGuild(event.getGuild()).getGuildSettings().setJoinMessageChannel("default_value");
|
Guilds.getGuild(event.getGuild()).getGuildSettings().setJoinMessageChannel("default_value");
|
||||||
} else if (messages[2].equalsIgnoreCase("quitmessage")) {
|
} else if (messages[2].equalsIgnoreCase("quitmessage")) {
|
||||||
RixaGuild.getGuild(event.getGuild()).getGuildSettings().setQuitMessageChannel("default_value");
|
Guilds.getGuild(event.getGuild()).getGuildSettings().setQuitMessageChannel("default_value");
|
||||||
}
|
}
|
||||||
} else if (messages[1].equalsIgnoreCase("addperm") || messages[1].equalsIgnoreCase("addpermission") || messages[1].equalsIgnoreCase("aperm")) {
|
} else if (messages[1].equalsIgnoreCase("addperm") || messages[1].equalsIgnoreCase("addpermission") || messages[1].equalsIgnoreCase("aperm")) {
|
||||||
String permission = "notFound";
|
String permission = "notFound";
|
||||||
|
@ -5,6 +5,7 @@ import me.savvy.rixa.commands.handlers.CommandExec;
|
|||||||
import me.savvy.rixa.commands.handlers.CommandType;
|
import me.savvy.rixa.commands.handlers.CommandType;
|
||||||
import me.savvy.rixa.commands.handlers.RixaPermission;
|
import me.savvy.rixa.commands.handlers.RixaPermission;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.entities.Role;
|
import net.dv8tion.jda.core.entities.Role;
|
||||||
@ -25,7 +26,7 @@ public class RemoveRoleCommand implements CommandExec {
|
|||||||
channelType = ChannelType.TEXT,
|
channelType = ChannelType.TEXT,
|
||||||
usage = "%premoverole", mainCommand = "removerole", aliases = {"rr", "removeroles"})
|
usage = "%premoverole", mainCommand = "removerole", aliases = {"rr", "removeroles"})
|
||||||
public void execute(GuildMessageReceivedEvent event) {
|
public void execute(GuildMessageReceivedEvent event) {
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.REMOVE_ROLE)) {
|
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.REMOVE_ROLE)) {
|
||||||
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
return;
|
return;
|
||||||
|
@ -4,6 +4,7 @@ import me.savvy.rixa.commands.handlers.Command;
|
|||||||
import me.savvy.rixa.commands.handlers.CommandExec;
|
import me.savvy.rixa.commands.handlers.CommandExec;
|
||||||
import me.savvy.rixa.commands.handlers.CommandType;
|
import me.savvy.rixa.commands.handlers.CommandType;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||||
@ -20,7 +21,7 @@ public class RoleRewardsCommand implements CommandExec {
|
|||||||
usage = "%prolerewards", mainCommand = "rolerewards",
|
usage = "%prolerewards", mainCommand = "rolerewards",
|
||||||
aliases = {"rolereward", "rw"})
|
aliases = {"rolereward", "rw"})
|
||||||
public void execute(GuildMessageReceivedEvent event) {
|
public void execute(GuildMessageReceivedEvent event) {
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
String[] args = event.getMessage().getContent().split(" ");
|
String[] args = event.getMessage().getContent().split(" ");
|
||||||
|
|
||||||
// ?rw <add/remove/list> [level] [role]
|
// ?rw <add/remove/list> [level] [role]
|
||||||
@ -31,7 +32,7 @@ public class RoleRewardsCommand implements CommandExec {
|
|||||||
setColor(event.getMember().getColor()).queue(event.getChannel());
|
setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*if (rixaGuild.getLevelsModule().getRoleRewards().containsKey(Integer.parseInt(args[2]))) {
|
/*if (((LevelsModule) rixaGuild.getModule("Levels")).getRoleRewards().containsKey(Integer.parseInt(args[2]))) {
|
||||||
new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + args[0] + " <add/remove/list> [level] [role].").
|
new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + args[0] + " <add/remove/list> [level] [role].").
|
||||||
setColor(event.getMember().getColor()).queue(event.getChannel());
|
setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
return;
|
return;
|
||||||
@ -51,7 +52,7 @@ public class RoleRewardsCommand implements CommandExec {
|
|||||||
switch(args[1].toLowerCase()) {
|
switch(args[1].toLowerCase()) {
|
||||||
case "list":
|
case "list":
|
||||||
Map<Integer, String> rewards = new HashMap<>();
|
Map<Integer, String> rewards = new HashMap<>();
|
||||||
/* rixaGuild.getLevelsModule().getRoleRewards().forEach((integer, s) -> {
|
/* ((LevelsModule) rixaGuild.getModule("Levels")).getRoleRewards().forEach((integer, s) -> {
|
||||||
|
|
||||||
});*/
|
});*/
|
||||||
break;
|
break;
|
||||||
|
@ -4,10 +4,7 @@ import me.savvy.rixa.commands.handlers.Command;
|
|||||||
import me.savvy.rixa.commands.handlers.CommandExec;
|
import me.savvy.rixa.commands.handlers.CommandExec;
|
||||||
import me.savvy.rixa.commands.handlers.CommandType;
|
import me.savvy.rixa.commands.handlers.CommandType;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.entities.TextChannel;
|
|
||||||
import net.dv8tion.jda.core.entities.User;
|
|
||||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||||
import net.dv8tion.jda.core.requests.restaction.InviteAction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by savit on 7/14/2017.
|
* Created by savit on 7/14/2017.
|
||||||
|
@ -6,7 +6,6 @@ import me.savvy.rixa.commands.handlers.CommandExec;
|
|||||||
import me.savvy.rixa.commands.handlers.CommandType;
|
import me.savvy.rixa.commands.handlers.CommandType;
|
||||||
import net.dv8tion.jda.core.EmbedBuilder;
|
import net.dv8tion.jda.core.EmbedBuilder;
|
||||||
import net.dv8tion.jda.core.JDA;
|
import net.dv8tion.jda.core.JDA;
|
||||||
import net.dv8tion.jda.core.audit.ActionType;
|
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.entities.Member;
|
import net.dv8tion.jda.core.entities.Member;
|
||||||
import net.dv8tion.jda.core.entities.MessageEmbed;
|
import net.dv8tion.jda.core.entities.MessageEmbed;
|
||||||
|
@ -3,6 +3,8 @@ package me.savvy.rixa.commands.general;
|
|||||||
import me.savvy.rixa.commands.handlers.Command;
|
import me.savvy.rixa.commands.handlers.Command;
|
||||||
import me.savvy.rixa.commands.handlers.CommandExec;
|
import me.savvy.rixa.commands.handlers.CommandExec;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
|
import me.savvy.rixa.modules.levels.LevelsModule;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.entities.Message;
|
import net.dv8tion.jda.core.entities.Message;
|
||||||
@ -16,13 +18,13 @@ public class LeaderboardCommand implements CommandExec {
|
|||||||
aliases = {"leaderboards", "levels"},
|
aliases = {"leaderboards", "levels"},
|
||||||
channelType = ChannelType.TEXT)
|
channelType = ChannelType.TEXT)
|
||||||
public void execute(GuildMessageReceivedEvent event) {
|
public void execute(GuildMessageReceivedEvent event) {
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
if (!rixaGuild.getLevelsModule().isEnabled()) {
|
if (!((LevelsModule) rixaGuild.getModule("Levels")).isEnabled()) {
|
||||||
new MessageBuilder("Levels are not enabled on this server!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder("Levels are not enabled on this server!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Message message = event.getChannel().sendMessage
|
Message message = event.getChannel().sendMessage
|
||||||
(rixaGuild.getLevelsModule().leaderboard
|
(((LevelsModule) rixaGuild.getModule("Levels")).leaderboard
|
||||||
(event.getMember(), 1).getBuilder().build()).complete();
|
(event.getMember(), 1).getBuilder().build()).complete();
|
||||||
message.addReaction("\u2B05").complete();
|
message.addReaction("\u2B05").complete();
|
||||||
message.addReaction("\u27A1").complete();
|
message.addReaction("\u27A1").complete();
|
||||||
|
@ -4,7 +4,9 @@ import me.savvy.rixa.Rixa;
|
|||||||
import me.savvy.rixa.commands.handlers.Command;
|
import me.savvy.rixa.commands.handlers.Command;
|
||||||
import me.savvy.rixa.commands.handlers.CommandExec;
|
import me.savvy.rixa.commands.handlers.CommandExec;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.guild.user.UserData;
|
import me.savvy.rixa.guild.user.UserData;
|
||||||
|
import me.savvy.rixa.modules.levels.LevelsModule;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.entities.Member;
|
import net.dv8tion.jda.core.entities.Member;
|
||||||
@ -24,8 +26,8 @@ public class LevelsCommand implements CommandExec {
|
|||||||
description = "View your levels!",
|
description = "View your levels!",
|
||||||
channelType = ChannelType.TEXT)
|
channelType = ChannelType.TEXT)
|
||||||
public void execute(GuildMessageReceivedEvent event) {
|
public void execute(GuildMessageReceivedEvent event) {
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
if (!rixaGuild.getLevelsModule().isEnabled()) {
|
if (!((LevelsModule) rixaGuild.getModule("Levels")).isEnabled()) {
|
||||||
new MessageBuilder("Levels are not enabled on this server!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder("Levels are not enabled on this server!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -47,7 +49,7 @@ public class LevelsCommand implements CommandExec {
|
|||||||
|
|
||||||
public MessageBuilder getInfo(RixaGuild rixaGuild, Member member) {
|
public MessageBuilder getInfo(RixaGuild rixaGuild, Member member) {
|
||||||
User author = member.getUser();
|
User author = member.getUser();
|
||||||
UserData data = rixaGuild.getLevelsModule().getUserData(author.getId());
|
UserData data = ((LevelsModule) rixaGuild.getModule("Levels")).getUserData(author.getId());
|
||||||
String query = "SELECT * FROM `levels` WHERE `guild_id` = '" + rixaGuild.getGuild().getId() + "' ORDER BY `experience` DESC";
|
String query = "SELECT * FROM `levels` WHERE `guild_id` = '" + rixaGuild.getGuild().getId() + "' ORDER BY `experience` DESC";
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
|
@ -20,7 +20,9 @@ import me.savvy.rixa.commands.handlers.Command;
|
|||||||
import me.savvy.rixa.commands.handlers.CommandExec;
|
import me.savvy.rixa.commands.handlers.CommandExec;
|
||||||
import me.savvy.rixa.commands.handlers.CommandType;
|
import me.savvy.rixa.commands.handlers.CommandType;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.modules.music.MusicManager;
|
import me.savvy.rixa.modules.music.MusicManager;
|
||||||
|
import me.savvy.rixa.modules.music.MusicModule;
|
||||||
import me.savvy.rixa.modules.music.TrackScheduler;
|
import me.savvy.rixa.modules.music.TrackScheduler;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import me.savvy.rixa.utils.YoutubeSearch;
|
import me.savvy.rixa.utils.YoutubeSearch;
|
||||||
@ -67,13 +69,14 @@ public class MusicCommand implements CommandExec {
|
|||||||
usage = "%pmusic", mainCommand = "music")
|
usage = "%pmusic", mainCommand = "music")
|
||||||
public void execute(GuildMessageReceivedEvent event) {
|
public void execute(GuildMessageReceivedEvent event) {
|
||||||
Guild guild = event.getGuild();
|
Guild guild = event.getGuild();
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(guild);
|
RixaGuild rixaGuild = Guilds.getGuild(guild);
|
||||||
if(!rixaGuild.getMusicModule().isEnabled()) {
|
MusicModule module = ((MusicModule) rixaGuild.getModule("Music"));
|
||||||
|
if(!module.isEnabled()) {
|
||||||
new MessageBuilder("Sorry music is not enabled on `" + guild.getName() + "`!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder("Sorry music is not enabled on `" + guild.getName() + "`!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(rixaGuild.getMusicModule().isRoleRequired()) {
|
if(module.isRoleRequired()) {
|
||||||
Role role = event.getGuild().getRoleById(rixaGuild.getMusicModule().getMusicRole());
|
Role role = event.getGuild().getRoleById(module.getMusicRole());
|
||||||
boolean hasRole = false;
|
boolean hasRole = false;
|
||||||
for (Role roleItem : event.getMember().getRoles()) {
|
for (Role roleItem : event.getMember().getRoles()) {
|
||||||
if (roleItem.getId().equalsIgnoreCase(role.getId())) {
|
if (roleItem.getId().equalsIgnoreCase(role.getId())) {
|
||||||
|
@ -6,8 +6,6 @@ import me.savvy.rixa.utils.MessageBuilder;
|
|||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Timber on 5/23/2017.
|
* Created by Timber on 5/23/2017.
|
||||||
*/
|
*/
|
||||||
|
@ -3,6 +3,7 @@ package me.savvy.rixa.commands.general;
|
|||||||
import me.savvy.rixa.commands.handlers.Command;
|
import me.savvy.rixa.commands.handlers.Command;
|
||||||
import me.savvy.rixa.commands.handlers.CommandExec;
|
import me.savvy.rixa.commands.handlers.CommandExec;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import net.dv8tion.jda.core.EmbedBuilder;
|
import net.dv8tion.jda.core.EmbedBuilder;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
@ -20,7 +21,7 @@ public class ServerInfoCommand implements CommandExec {
|
|||||||
description = "Receive information about the server!",
|
description = "Receive information about the server!",
|
||||||
aliases = "sinfo", mainCommand = "serverinfo")
|
aliases = "sinfo", mainCommand = "serverinfo")
|
||||||
public void execute(GuildMessageReceivedEvent event) {
|
public void execute(GuildMessageReceivedEvent event) {
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
EmbedBuilder messageEmbed = new EmbedBuilder();
|
EmbedBuilder messageEmbed = new EmbedBuilder();
|
||||||
User owner = event.getGuild().getOwner().getUser();
|
User owner = event.getGuild().getOwner().getUser();
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss");
|
||||||
|
@ -5,6 +5,7 @@ import me.savvy.rixa.commands.handlers.CommandExec;
|
|||||||
import me.savvy.rixa.commands.handlers.CommandType;
|
import me.savvy.rixa.commands.handlers.CommandType;
|
||||||
import me.savvy.rixa.commands.handlers.RixaPermission;
|
import me.savvy.rixa.commands.handlers.RixaPermission;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import me.savvy.rixa.utils.Utils;
|
import me.savvy.rixa.utils.Utils;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
@ -28,7 +29,7 @@ public class DeleteMessagesCommand implements CommandExec {
|
|||||||
type = CommandType.MOD,
|
type = CommandType.MOD,
|
||||||
usage = "%pclear")
|
usage = "%pclear")
|
||||||
public void execute(GuildMessageReceivedEvent event) {
|
public void execute(GuildMessageReceivedEvent event) {
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.CLEAR_CHAT)) {
|
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.CLEAR_CHAT)) {
|
||||||
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
return;
|
return;
|
||||||
|
@ -5,6 +5,7 @@ import me.savvy.rixa.commands.handlers.CommandExec;
|
|||||||
import me.savvy.rixa.commands.handlers.CommandType;
|
import me.savvy.rixa.commands.handlers.CommandType;
|
||||||
import me.savvy.rixa.commands.handlers.RixaPermission;
|
import me.savvy.rixa.commands.handlers.RixaPermission;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.entities.Member;
|
import net.dv8tion.jda.core.entities.Member;
|
||||||
@ -25,7 +26,7 @@ public class MuteCommand implements CommandExec {
|
|||||||
type = CommandType.MOD,
|
type = CommandType.MOD,
|
||||||
channelType = ChannelType.TEXT)
|
channelType = ChannelType.TEXT)
|
||||||
public void execute(GuildMessageReceivedEvent event) {
|
public void execute(GuildMessageReceivedEvent event) {
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.MUTE)) {
|
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.MUTE)) {
|
||||||
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
return;
|
return;
|
||||||
|
@ -5,6 +5,7 @@ import me.savvy.rixa.commands.handlers.CommandExec;
|
|||||||
import me.savvy.rixa.commands.handlers.CommandType;
|
import me.savvy.rixa.commands.handlers.CommandType;
|
||||||
import me.savvy.rixa.commands.handlers.RixaPermission;
|
import me.savvy.rixa.commands.handlers.RixaPermission;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import me.savvy.rixa.utils.Utils;
|
import me.savvy.rixa.utils.Utils;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
@ -31,7 +32,7 @@ public class PurgeMessagesCommand implements CommandExec {
|
|||||||
type = CommandType.MOD,
|
type = CommandType.MOD,
|
||||||
usage = "%ppurge")
|
usage = "%ppurge")
|
||||||
public void execute(GuildMessageReceivedEvent event) {
|
public void execute(GuildMessageReceivedEvent event) {
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.CLEAR_CHAT)) {
|
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.CLEAR_CHAT)) {
|
||||||
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
return;
|
return;
|
||||||
|
@ -4,6 +4,7 @@ import me.savvy.rixa.commands.handlers.Command;
|
|||||||
import me.savvy.rixa.commands.handlers.CommandExec;
|
import me.savvy.rixa.commands.handlers.CommandExec;
|
||||||
import me.savvy.rixa.commands.handlers.RixaPermission;
|
import me.savvy.rixa.commands.handlers.RixaPermission;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||||
@ -19,7 +20,7 @@ public class RaidModeCommand implements CommandExec {
|
|||||||
channelType = ChannelType.TEXT,
|
channelType = ChannelType.TEXT,
|
||||||
aliases = {"raidmode", "trm", "toggleraid"})
|
aliases = {"raidmode", "trm", "toggleraid"})
|
||||||
public void execute(GuildMessageReceivedEvent event) {
|
public void execute(GuildMessageReceivedEvent event) {
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.TOGGLE_RAIDMODE)) {
|
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.TOGGLE_RAIDMODE)) {
|
||||||
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
return;
|
return;
|
||||||
|
@ -4,7 +4,6 @@ import me.savvy.rixa.Rixa;
|
|||||||
import me.savvy.rixa.commands.handlers.Command;
|
import me.savvy.rixa.commands.handlers.Command;
|
||||||
import me.savvy.rixa.commands.handlers.CommandExec;
|
import me.savvy.rixa.commands.handlers.CommandExec;
|
||||||
import me.savvy.rixa.commands.handlers.CommandType;
|
import me.savvy.rixa.commands.handlers.CommandType;
|
||||||
import me.savvy.rixa.enums.Result;
|
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.entities.Member;
|
import net.dv8tion.jda.core.entities.Member;
|
||||||
|
@ -2,7 +2,7 @@ package me.savvy.rixa.data.database.sql.other;
|
|||||||
|
|
||||||
public enum DatabaseTables {
|
public enum DatabaseTables {
|
||||||
|
|
||||||
CORE("CREATE TABLE IF NOT EXISTS `core` ( `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `guild_id` varchar(255) NOT NULL, `guild_name` varchar(255) NOT NULL," +
|
CORE("CREATE TABLE IF NOT EXISTS `core` ( `guild_id` varchar(255) NOT NULL PRIMARY KEY, `guild_name` varchar(255) NOT NULL," +
|
||||||
" `description` text, `enlisted` tinyint(1) NOT NULL DEFAULT '0', `icon` varchar(255) DEFAULT NULL, `link` varchar(255) DEFAULT NULL," +
|
" `description` text, `enlisted` tinyint(1) NOT NULL DEFAULT '0', `icon` varchar(255) DEFAULT NULL, `link` varchar(255) DEFAULT NULL," +
|
||||||
" `keywords` text, `creation_date` varchar(255) NOT NULL DEFAULT 'N/A', `guild_region` varchar(255) NOT NULL DEFAULT 'N/A'," +
|
" `keywords` text, `creation_date` varchar(255) NOT NULL DEFAULT 'N/A', `guild_region` varchar(255) NOT NULL DEFAULT 'N/A'," +
|
||||||
" `guild_owner` varchar(255) NOT NULL DEFAULT 'N/A'\n" +
|
" `guild_owner` varchar(255) NOT NULL DEFAULT 'N/A'\n" +
|
||||||
|
@ -2,6 +2,7 @@ package me.savvy.rixa.events;
|
|||||||
|
|
||||||
import me.savvy.rixa.Rixa;
|
import me.savvy.rixa.Rixa;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import net.dv8tion.jda.core.events.ReadyEvent;
|
import net.dv8tion.jda.core.events.ReadyEvent;
|
||||||
import net.dv8tion.jda.core.events.guild.GuildJoinEvent;
|
import net.dv8tion.jda.core.events.guild.GuildJoinEvent;
|
||||||
import net.dv8tion.jda.core.events.guild.GuildLeaveEvent;
|
import net.dv8tion.jda.core.events.guild.GuildLeaveEvent;
|
||||||
@ -29,6 +30,6 @@ public class BotEvent {
|
|||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onQuit(GuildLeaveEvent event) {
|
public void onQuit(GuildLeaveEvent event) {
|
||||||
RixaGuild.removeGuild(RixaGuild.getGuild(event.getGuild()));
|
Guilds.removeGuild(Guilds.getGuild(event.getGuild()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package me.savvy.rixa.events;
|
package me.savvy.rixa.events;
|
||||||
|
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import net.dv8tion.jda.core.Permission;
|
|
||||||
import net.dv8tion.jda.core.entities.Guild;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.Role;
|
import net.dv8tion.jda.core.entities.Role;
|
||||||
import net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent;
|
import net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent;
|
||||||
@ -22,7 +22,7 @@ public class MemberEvent {
|
|||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onMember(GuildMemberJoinEvent event) {
|
public void onMember(GuildMemberJoinEvent event) {
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
|
|
||||||
/* if (rixaGuild.getGuildSettings().isRaidMode()) {
|
/* if (rixaGuild.getGuildSettings().isRaidMode()) {
|
||||||
if(event.getGuild().getSelfMember().hasPermission(Permission.KICK_MEMBERS)) {
|
if(event.getGuild().getSelfMember().hasPermission(Permission.KICK_MEMBERS)) {
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package me.savvy.rixa.events;
|
package me.savvy.rixa.events;
|
||||||
|
|
||||||
import com.google.code.chatterbotapi.ChatterBotFactory;
|
|
||||||
import com.mysql.jdbc.StringUtils;
|
import com.mysql.jdbc.StringUtils;
|
||||||
import me.savvy.rixa.Rixa;
|
import me.savvy.rixa.Rixa;
|
||||||
import me.savvy.rixa.commands.handlers.CommandHandler;
|
import me.savvy.rixa.commands.handlers.CommandHandler;
|
||||||
import me.savvy.rixa.commands.handlers.CommandRegistrar;
|
import me.savvy.rixa.commands.handlers.CommandRegistrar;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
|
import me.savvy.rixa.modules.levels.LevelsModule;
|
||||||
import me.savvy.rixa.modules.reactions.handlers.ReactRegistrar;
|
import me.savvy.rixa.modules.reactions.handlers.ReactRegistrar;
|
||||||
import me.savvy.rixa.modules.reactions.handlers.ReactionManager;
|
import me.savvy.rixa.modules.reactions.handlers.ReactionManager;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
@ -34,7 +35,7 @@ import java.util.regex.Pattern;
|
|||||||
*/
|
*/
|
||||||
public class MessageEvent {
|
public class MessageEvent {
|
||||||
|
|
||||||
private final Pattern INVITE = Pattern.compile("discord(?:\\.gg|app.com\\/invite)\\/([A-Z0-9-]{2,16})",Pattern.CASE_INSENSITIVE);
|
private final Pattern INVITE = Pattern.compile("discord(?:\\.gg|app.com\\/invite)\\/([A-Z0-9-]{2,16})", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@ -43,42 +44,44 @@ public class MessageEvent {
|
|||||||
if (event.getAuthor().isBot()) return;
|
if (event.getAuthor().isBot()) return;
|
||||||
|
|
||||||
if (event.getMessage().getContent().startsWith
|
if (event.getMessage().getContent().startsWith
|
||||||
("@" + event.getGuild().getSelfMember().getEffectiveName())) {
|
("@" + event.getGuild().getSelfMember().getEffectiveName())) {
|
||||||
try {
|
try {
|
||||||
String s = event.getMessage().getContent().replace
|
String s = event.getMessage().getContent().replace
|
||||||
("@" + event.getGuild().getSelfMember().getEffectiveName()+ " ", "");
|
("@" + event.getGuild().getSelfMember().getEffectiveName() + " ", "");
|
||||||
if (s.isEmpty()) return;
|
if (s.isEmpty()) return;
|
||||||
s = Rixa.getChatBotSession().think(s);
|
s = Rixa.getChatBotSession().think(s);
|
||||||
if (s.isEmpty()) return;
|
if (s.isEmpty()) return;
|
||||||
event.getChannel().sendMessage(s).queue();
|
event.getChannel().sendMessage(s).queue();
|
||||||
return;
|
return;
|
||||||
} catch (Exception ex) { ex.printStackTrace(); }
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
|
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
|
||||||
String prefix = rixaGuild
|
String prefix = rixaGuild
|
||||||
.getGuildSettings()
|
.getGuildSettings()
|
||||||
.getPrefix();
|
.getPrefix();
|
||||||
//checkMessage(event.getMessage());
|
//checkMessage(event.getMessage());
|
||||||
if (!event.getMessage().getContent().startsWith(prefix)) {
|
if (!event.getMessage().getContent().startsWith(prefix)) {
|
||||||
if (!(rixaGuild.getLevelsModule().isEnabled())) {
|
if (!(((LevelsModule) rixaGuild.getModule("Levels")).isEnabled())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*if(!event.getAuthor().getId().equalsIgnoreCase("202944101333729280") &&
|
/*if(!event.getAuthor().getId().equalsIgnoreCase("202944101333729280") &&
|
||||||
!event.getAuthor().getId().equalsIgnoreCase("207322957075185665")) {
|
!event.getAuthor().getId().equalsIgnoreCase("207322957075185665")) {
|
||||||
return;
|
return;
|
||||||
}*/
|
}*/
|
||||||
if(rixaGuild.getLevelsModule().getUserData(event.getAuthor().getId()).awardIfCan()) {
|
if (((LevelsModule) rixaGuild.getModule("Levels")).getUserData(event.getAuthor().getId()).awardIfCan()) {
|
||||||
new MessageBuilder(event.getAuthor().getAsMention() + " has leveled up to level " +
|
new MessageBuilder(event.getAuthor().getAsMention() + " has leveled up to level " +
|
||||||
rixaGuild.getLevelsModule().getUserData(event.getAuthor().getId()).getLevel())
|
((LevelsModule) rixaGuild.getModule("Levels")).getUserData(event.getAuthor().getId()).getLevel())
|
||||||
.setColor(event.getMember().getColor()).queue(event.getChannel());
|
.setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] splitContent = event.getMessage().getContent().replace(prefix, "").split(" ");
|
String[] splitContent = event.getMessage().getContent().replace(prefix, "").split(" ");
|
||||||
if(!CommandHandler.hasCommand(splitContent[0])) {
|
if (!CommandHandler.hasCommand(splitContent[0])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CommandRegistrar cmd = CommandHandler.get(splitContent[0]);
|
CommandRegistrar cmd = CommandHandler.get(splitContent[0]);
|
||||||
@ -93,18 +96,19 @@ public class MessageEvent {
|
|||||||
private void checkMessage(Message message) {
|
private void checkMessage(Message message) {
|
||||||
List<String> invites = new ArrayList<>();
|
List<String> invites = new ArrayList<>();
|
||||||
Matcher matcher = INVITE.matcher(message.getRawContent());
|
Matcher matcher = INVITE.matcher(message.getRawContent());
|
||||||
while(matcher.find()) {
|
while (matcher.find()) {
|
||||||
invites.add(matcher.group(1));
|
invites.add(matcher.group(1));
|
||||||
}
|
}
|
||||||
if(invites.size() == 0) {
|
if (invites.size() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(String inviteCode : invites) {
|
for (String inviteCode : invites) {
|
||||||
Invite invite = null;
|
Invite invite = null;
|
||||||
try {
|
try {
|
||||||
invite = Invite.resolve(message.getJDA(), inviteCode).complete();
|
invite = Invite.resolve(message.getJDA(), inviteCode).complete();
|
||||||
} catch(Exception e) {}
|
} catch (Exception e) {
|
||||||
if(invite !=null && !invite.getGuild().getId().equals(message.getGuild().getId())) {
|
}
|
||||||
|
if (invite != null && !invite.getGuild().getId().equals(message.getGuild().getId())) {
|
||||||
new MessageBuilder(String.format("Advertising is not allowed, %s!",
|
new MessageBuilder(String.format("Advertising is not allowed, %s!",
|
||||||
message.getAuthor().getAsMention())).setColor(message.getMember().getColor()).queue(message.getTextChannel());
|
message.getAuthor().getAsMention())).setColor(message.getMember().getColor()).queue(message.getTextChannel());
|
||||||
message.delete().reason("Advertising is not allowed!").queue();
|
message.delete().reason("Advertising is not allowed!").queue();
|
||||||
@ -116,7 +120,7 @@ public class MessageEvent {
|
|||||||
public void onMemberJoin(PrivateMessageReceivedEvent event) {
|
public void onMemberJoin(PrivateMessageReceivedEvent event) {
|
||||||
RixaGuild rixaGuild;
|
RixaGuild rixaGuild;
|
||||||
if (MemberEvent.joinMembers.containsKey(event.getAuthor().getId())) {
|
if (MemberEvent.joinMembers.containsKey(event.getAuthor().getId())) {
|
||||||
rixaGuild = RixaGuild.getGuild(MemberEvent.joinMembers.get(event.getAuthor().getId()));
|
rixaGuild = Guilds.getGuild(MemberEvent.joinMembers.get(event.getAuthor().getId()));
|
||||||
if (event.getMessage().getContent().equalsIgnoreCase("I agree") ||
|
if (event.getMessage().getContent().equalsIgnoreCase("I agree") ||
|
||||||
event.getMessage().getContent().equalsIgnoreCase("I accept")
|
event.getMessage().getContent().equalsIgnoreCase("I accept")
|
||||||
|| event.getMessage().getContent().equalsIgnoreCase("Yes")) {
|
|| event.getMessage().getContent().equalsIgnoreCase("Yes")) {
|
||||||
@ -128,9 +132,9 @@ public class MessageEvent {
|
|||||||
new MessageBuilder(String.format("You have been promoted on %s!", rixaGuild.getGuild().getName()))
|
new MessageBuilder(String.format("You have been promoted on %s!", rixaGuild.getGuild().getName()))
|
||||||
.setColor(rixaGuild.getGuild().getMember(event.getAuthor()).getColor()).send(event.getAuthor());
|
.setColor(rixaGuild.getGuild().getMember(event.getAuthor()).getColor()).send(event.getAuthor());
|
||||||
rixaGuild.getGuildSettings().setLastJoin(System.currentTimeMillis());
|
rixaGuild.getGuildSettings().setLastJoin(System.currentTimeMillis());
|
||||||
} catch(PermissionException ex) {
|
} catch (PermissionException ex) {
|
||||||
new MessageBuilder(String.format("I do not have permission for %s in %s", ex.getPermission().getName(), rixaGuild.getGuild().getName()))
|
new MessageBuilder(String.format("I do not have permission for %s in %s", ex.getPermission().getName(), rixaGuild.getGuild().getName()))
|
||||||
.setColor(Color.RED).send(rixaGuild.getGuild().getOwner().getUser());
|
.setColor(Color.RED).send(rixaGuild.getGuild().getOwner().getUser());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (event.getMessage().getContent().equalsIgnoreCase("I disagree") ||
|
} else if (event.getMessage().getContent().equalsIgnoreCase("I disagree") ||
|
||||||
@ -142,7 +146,7 @@ public class MessageEvent {
|
|||||||
MemberEvent.joinMembers.remove(event.getAuthor().getId());
|
MemberEvent.joinMembers.remove(event.getAuthor().getId());
|
||||||
rixaGuild.getGuild().getController().kick(rixaGuild.getGuild().getMember(event.getAuthor())).complete();
|
rixaGuild.getGuild().getController().kick(rixaGuild.getGuild().getMember(event.getAuthor())).complete();
|
||||||
} catch (PermissionException ex) {
|
} catch (PermissionException ex) {
|
||||||
if(ex.getPermission() == Permission.KICK_MEMBERS) {
|
if (ex.getPermission() == Permission.KICK_MEMBERS) {
|
||||||
new MessageBuilder(String.format("I do not have permission to kick %s from %s", event.getAuthor().getName(), rixaGuild.getGuild().getName()))
|
new MessageBuilder(String.format("I do not have permission to kick %s from %s", event.getAuthor().getName(), rixaGuild.getGuild().getName()))
|
||||||
.setColor(Color.RED).send(rixaGuild.getGuild().getOwner().getUser());
|
.setColor(Color.RED).send(rixaGuild.getGuild().getOwner().getUser());
|
||||||
} else {
|
} else {
|
||||||
@ -152,7 +156,7 @@ public class MessageEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(!event.getAuthor().isBot())
|
if (!event.getAuthor().isBot())
|
||||||
new MessageBuilder("Private messages are currently disabled!").setColor(Color.RED).send(event.getAuthor());
|
new MessageBuilder("Private messages are currently disabled!").setColor(Color.RED).send(event.getAuthor());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,33 +164,33 @@ public class MessageEvent {
|
|||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onReact(MessageReactionAddEvent event) {
|
public void onReact(MessageReactionAddEvent event) {
|
||||||
Message message = event.getChannel().getMessageById(event.getMessageId()).complete();
|
Message message = event.getChannel().getMessageById(event.getMessageId()).complete();
|
||||||
if(message == null || message.getEmbeds().size() != 1) return;
|
if (message == null || message.getEmbeds().size() != 1) return;
|
||||||
MessageEmbed embed = message.getEmbeds().get(0);
|
MessageEmbed embed = message.getEmbeds().get(0);
|
||||||
if(StringUtils.isNullOrEmpty(embed.getTitle())) return;
|
if (StringUtils.isNullOrEmpty(embed.getTitle())) return;
|
||||||
String[] titleSplit = embed.getTitle().split(": ");
|
String[] titleSplit = embed.getTitle().split(": ");
|
||||||
if (titleSplit[0].equalsIgnoreCase("Leaderboard")) return;
|
if (titleSplit[0].equalsIgnoreCase("Leaderboard")) return;
|
||||||
if(!ReactionManager.getReactions().containsKey(titleSplit[0])) return;
|
if (!ReactionManager.getReactions().containsKey(titleSplit[0])) return;
|
||||||
|
|
||||||
ReactRegistrar reactRegistrar = ReactionManager.getReactions().get(titleSplit[0]);
|
ReactRegistrar reactRegistrar = ReactionManager.getReactions().get(titleSplit[0]);
|
||||||
Method m = reactRegistrar.getMethod();
|
Method m = reactRegistrar.getMethod();
|
||||||
try {
|
try {
|
||||||
m.invoke(reactRegistrar.getExecutor(), event);
|
m.invoke(reactRegistrar.getExecutor(), event);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onGuildReact(GuildMessageReactionAddEvent event) {
|
public void onGuildReact(GuildMessageReactionAddEvent event) {
|
||||||
if (event.getGuild() == null) return;
|
if (event.getGuild() == null) return;
|
||||||
if (event.getUser().isBot()) return;
|
if (event.getUser().isBot()) return;
|
||||||
Message message = event.getChannel().getMessageById(event.getMessageId()).complete();
|
Message message = event.getChannel().getMessageById(event.getMessageId()).complete();
|
||||||
if(message == null || message.getEmbeds().size() != 1) return;
|
if (message == null || message.getEmbeds().size() != 1) return;
|
||||||
MessageEmbed embed = message.getEmbeds().get(0);
|
MessageEmbed embed = message.getEmbeds().get(0);
|
||||||
if(StringUtils.isNullOrEmpty(embed.getTitle())) return;
|
if (StringUtils.isNullOrEmpty(embed.getTitle())) return;
|
||||||
String[] titleSplit = embed.getTitle().split(": ");
|
String[] titleSplit = embed.getTitle().split(": ");
|
||||||
System.out.println(Arrays.toString(titleSplit));
|
System.out.println(Arrays.toString(titleSplit));
|
||||||
if(ReactionManager.getReactions().containsKey(titleSplit[0])) {
|
if (ReactionManager.getReactions().containsKey(titleSplit[0])) {
|
||||||
ReactRegistrar reactRegistrar = ReactionManager.getReactions().get(titleSplit[0]);
|
ReactRegistrar reactRegistrar = ReactionManager.getReactions().get(titleSplit[0]);
|
||||||
Method m = reactRegistrar.getMethod();
|
Method m = reactRegistrar.getMethod();
|
||||||
try {
|
try {
|
||||||
|
22
src/main/java/me/savvy/rixa/events/Shutdown.java
Normal file
22
src/main/java/me/savvy/rixa/events/Shutdown.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package me.savvy.rixa.events;
|
||||||
|
|
||||||
|
import me.savvy.rixa.Rixa;
|
||||||
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
|
import net.dv8tion.jda.core.events.ReadyEvent;
|
||||||
|
import net.dv8tion.jda.core.events.ShutdownEvent;
|
||||||
|
import net.dv8tion.jda.core.events.guild.GuildJoinEvent;
|
||||||
|
import net.dv8tion.jda.core.events.guild.GuildLeaveEvent;
|
||||||
|
import net.dv8tion.jda.core.hooks.SubscribeEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Timber on 5/23/2017.
|
||||||
|
*/
|
||||||
|
public class Shutdown {
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onShutdown(ShutdownEvent event) {
|
||||||
|
System.out.println("Test");
|
||||||
|
Rixa.getInstance().close();
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,6 @@ import me.savvy.rixa.utils.MessageBuilder;
|
|||||||
import net.dv8tion.jda.core.EmbedBuilder;
|
import net.dv8tion.jda.core.EmbedBuilder;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -9,9 +9,10 @@ import me.savvy.rixa.Rixa;
|
|||||||
import me.savvy.rixa.commands.handlers.RixaPermission;
|
import me.savvy.rixa.commands.handlers.RixaPermission;
|
||||||
import me.savvy.rixa.enums.Result;
|
import me.savvy.rixa.enums.Result;
|
||||||
import me.savvy.rixa.guild.management.GuildSettings;
|
import me.savvy.rixa.guild.management.GuildSettings;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
|
import me.savvy.rixa.modules.RixaModule;
|
||||||
import me.savvy.rixa.modules.levels.LevelsModule;
|
import me.savvy.rixa.modules.levels.LevelsModule;
|
||||||
import me.savvy.rixa.modules.music.MusicModule;
|
import me.savvy.rixa.modules.music.MusicModule;
|
||||||
import me.savvy.rixa.modules.twitter.TwitterModule;
|
|
||||||
import net.dv8tion.jda.core.entities.Guild;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.Member;
|
import net.dv8tion.jda.core.entities.Member;
|
||||||
import net.dv8tion.jda.core.entities.Role;
|
import net.dv8tion.jda.core.entities.Role;
|
||||||
@ -19,7 +20,10 @@ import net.dv8tion.jda.core.entities.User;
|
|||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Timber on 5/23/2017.
|
* Created by Timber on 5/23/2017.
|
||||||
@ -33,26 +37,20 @@ public class RixaGuild {
|
|||||||
@Setter
|
@Setter
|
||||||
private GuildSettings guildSettings;
|
private GuildSettings guildSettings;
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
|
||||||
private MusicModule musicModule;
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private TwitterModule twitterModule;
|
|
||||||
@Getter
|
|
||||||
private List<String> mutedMembers = new ArrayList<>();
|
private List<String> mutedMembers = new ArrayList<>();
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
private HashMap<String, RixaModule> modules;
|
||||||
private LevelsModule levelsModule;
|
|
||||||
|
|
||||||
public RixaGuild(Guild guild) {
|
public RixaGuild(Guild guild) {
|
||||||
this.guild = guild;
|
this.guild = guild;
|
||||||
|
this.modules = new HashMap<>();
|
||||||
this.db = Rixa.getDatabase();
|
this.db = Rixa.getDatabase();
|
||||||
setMusicModule(new MusicModule(guild));
|
modules.put("Music", new MusicModule());
|
||||||
setLevelsModule(new LevelsModule(this));
|
modules.put("Levels", new LevelsModule());
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void load() {
|
public void load() {
|
||||||
if (!(checkExists())) {
|
if (!(checkExists())) {
|
||||||
Update update = new Update("INSERT INTO `core` (`guild_id`, `guild_name`, `description`, `keywords`) VALUES (?, ?, 'Description not set.', 'No Keywords Found.')");
|
Update update = new Update("INSERT INTO `core` (`guild_id`, `guild_name`, `description`, `keywords`) VALUES (?, ?, 'Description not set.', 'No Keywords Found.')");
|
||||||
update.setString(guild.getId());
|
update.setString(guild.getId());
|
||||||
@ -60,7 +58,7 @@ public class RixaGuild {
|
|||||||
db.send(update);
|
db.send(update);
|
||||||
}
|
}
|
||||||
setGuildSettings(new GuildSettings(this.guild));
|
setGuildSettings(new GuildSettings(this.guild));
|
||||||
addGuild(this);
|
Guilds.addGuild(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuildSettings getGuildSettings() {
|
public GuildSettings getGuildSettings() {
|
||||||
@ -177,28 +175,16 @@ public class RixaGuild {
|
|||||||
mutedMembers.add(user.getId());
|
mutedMembers.add(user.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
public void save() {
|
||||||
private static Map<String, RixaGuild> guilds = new HashMap<>();
|
for (RixaModule module : modules.values()) {
|
||||||
|
if (!module.isEnabled()) {
|
||||||
private static void addGuild(RixaGuild guild) {
|
return;
|
||||||
if (check(guild.getGuild())) return;
|
}
|
||||||
guilds.put(guild.getGuild().getId(), guild);
|
module.save();
|
||||||
}
|
|
||||||
|
|
||||||
public static RixaGuild getGuild(Guild guild) {
|
|
||||||
if (!check(guild)) {
|
|
||||||
addGuild(new RixaGuild(guild));
|
|
||||||
}
|
}
|
||||||
return guilds.get(guild.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeGuild(RixaGuild guild) {
|
public RixaModule getModule(String levels) {
|
||||||
if (!check(guild.getGuild())) return;
|
return this.modules.get(levels);
|
||||||
guilds.remove(guild.getGuild().getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean check(Guild guild) {
|
|
||||||
return guilds.containsKey(guild.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class GuildSettings {
|
|||||||
@Getter
|
@Getter
|
||||||
private boolean enlisted, joinVerification;
|
private boolean enlisted, joinVerification;
|
||||||
@Getter
|
@Getter
|
||||||
private String prefix = "/", defaultRole, muteRole, joinMessage, quitMessage, joinPrivateMessage, description;
|
private String prefix = "/", defaultRole, muteRole, joinMessage, quitMessage, joinPrivateMessage, description, currency;
|
||||||
@Getter
|
@Getter
|
||||||
private TextChannel joinMessageChannel, quitMessageChannel;
|
private TextChannel joinMessageChannel, quitMessageChannel;
|
||||||
@Getter
|
@Getter
|
||||||
@ -48,9 +48,9 @@ public class GuildSettings {
|
|||||||
private void load() throws SQLException {
|
private void load() throws SQLException {
|
||||||
if (!checkExists()) {
|
if (!checkExists()) {
|
||||||
Update update = new Update("INSERT INTO `settings` (`guild_id`, `log_enabled`, `log_channel`, `joinMessage`, `quitMessage`, `greetings`, `farewell`," +
|
Update update = new Update("INSERT INTO `settings` (`guild_id`, `log_enabled`, `log_channel`, `joinMessage`, `quitMessage`, `greetings`, `farewell`," +
|
||||||
" `prefix`, `joinPm`, `joinVerification`, `defaultRole`, `muteRole`)" +
|
" `prefix`, `joinPm`, `joinVerification`, `defaultRole`, `muteRole`, `currency`)" +
|
||||||
" VALUES ('" + guild.getId() + "', '0', 'default_value', 'default_value', 'default_value', 'default_value', 'default_value', '/'," +
|
" VALUES ('" + guild.getId() + "', '0', 'default_value', 'default_value', 'default_value', 'default_value', 'default_value', '/'," +
|
||||||
" 'default', '0', 'default_value', 'default_value');");
|
" 'default', '0', 'default_value', 'default_value', ' tokens');");
|
||||||
Rixa.getDatabase().send(update);
|
Rixa.getDatabase().send(update);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
35
src/main/java/me/savvy/rixa/guild/management/Guilds.java
Normal file
35
src/main/java/me/savvy/rixa/guild/management/Guilds.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package me.savvy.rixa.guild.management;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Guilds {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static Map<String, RixaGuild> guilds = new HashMap<>();
|
||||||
|
|
||||||
|
public static void addGuild(RixaGuild guild) {
|
||||||
|
if (check(guild.getGuild())) return;
|
||||||
|
guilds.put(guild.getGuild().getId(), guild);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RixaGuild getGuild(Guild guild) {
|
||||||
|
if (!check(guild)) {
|
||||||
|
addGuild(new RixaGuild(guild));
|
||||||
|
}
|
||||||
|
return guilds.get(guild.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeGuild(RixaGuild guild) {
|
||||||
|
if (!check(guild.getGuild())) return;
|
||||||
|
guilds.remove(guild.getGuild().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean check(Guild guild) {
|
||||||
|
return guilds.containsKey(guild.getId());
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,8 @@ import me.majrly.database.statements.Query;
|
|||||||
import me.majrly.database.statements.Update;
|
import me.majrly.database.statements.Update;
|
||||||
import me.savvy.rixa.Rixa;
|
import me.savvy.rixa.Rixa;
|
||||||
import me.savvy.rixa.enums.Result;
|
import me.savvy.rixa.enums.Result;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
|
import me.savvy.rixa.modules.levels.LevelsModule;
|
||||||
import net.dv8tion.jda.core.entities.Guild;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ public class UserData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void register(UserData userData) {
|
private void register(UserData userData) {
|
||||||
RixaGuild.getGuild(guild).getLevelsModule().registerUser(userData);
|
((LevelsModule) Guilds.getGuild(guild).getModule("Levels")).registerUser(userData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void load() {
|
private void load() {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package me.savvy.rixa.modules;
|
package me.savvy.rixa.modules;
|
||||||
|
|
||||||
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Timber on 5/23/2017.
|
* Created by Timber on 5/23/2017.
|
||||||
*/
|
*/
|
||||||
@ -10,4 +12,8 @@ public interface RixaModule {
|
|||||||
String getDescription();
|
String getDescription();
|
||||||
|
|
||||||
boolean isEnabled();
|
boolean isEnabled();
|
||||||
|
|
||||||
|
void load(RixaGuild guild);
|
||||||
|
|
||||||
|
void save();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,49 @@
|
|||||||
package me.savvy.rixa.modules.economy;
|
package me.savvy.rixa.modules.economy;
|
||||||
|
|
||||||
public class Economy {
|
import lombok.Getter;
|
||||||
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.modules.RixaModule;
|
||||||
|
import me.savvy.rixa.utils.DatabaseUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Economy implements RixaModule {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private RixaGuild rixaGuild;
|
||||||
|
@Getter
|
||||||
|
private Map<String, EconomyData> userData = new HashMap<>();
|
||||||
|
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Economy";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "Rixa Economy Module";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(RixaGuild rixaGuild) {
|
||||||
|
this.rixaGuild = rixaGuild;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
DatabaseUtils.update("modules", "levels", "guild_id", enabled, rixaGuild.getGuild().getId());
|
||||||
|
}
|
||||||
}
|
}
|
25
src/main/java/me/savvy/rixa/modules/economy/EconomyData.java
Normal file
25
src/main/java/me/savvy/rixa/modules/economy/EconomyData.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package me.savvy.rixa.modules.economy;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
|
import net.dv8tion.jda.core.entities.User;
|
||||||
|
|
||||||
|
public class EconomyData {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private int amount;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private Guild guild;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
|
||||||
|
public EconomyData(User user, Guild guild) {
|
||||||
|
setUser(user);
|
||||||
|
setGuild(guild);
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,11 @@
|
|||||||
package me.savvy.rixa.modules.levels;
|
package me.savvy.rixa.modules.levels;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import me.majrly.database.Database;
|
import me.majrly.database.Database;
|
||||||
import me.majrly.database.statements.Query;
|
import me.majrly.database.statements.Query;
|
||||||
import me.majrly.database.statements.Update;
|
import me.majrly.database.statements.Update;
|
||||||
import me.savvy.rixa.Rixa;
|
import me.savvy.rixa.Rixa;
|
||||||
import me.savvy.rixa.enums.Result;
|
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
import me.savvy.rixa.guild.user.UserData;
|
import me.savvy.rixa.guild.user.UserData;
|
||||||
import me.savvy.rixa.modules.RixaModule;
|
import me.savvy.rixa.modules.RixaModule;
|
||||||
@ -13,7 +13,6 @@ import me.savvy.rixa.utils.DatabaseUtils;
|
|||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
import net.dv8tion.jda.core.entities.Member;
|
import net.dv8tion.jda.core.entities.Member;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -24,18 +23,13 @@ import java.util.*;
|
|||||||
public class LevelsModule implements RixaModule {
|
public class LevelsModule implements RixaModule {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final RixaGuild rixaGuild;
|
private RixaGuild rixaGuild;
|
||||||
@Getter
|
@Getter
|
||||||
private Map<String, UserData> userData = new HashMap<>();
|
private Map<String, UserData> userData = new HashMap<>();
|
||||||
@Getter
|
@Getter
|
||||||
|
@Setter
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
|
||||||
public LevelsModule(RixaGuild rixaGuild) {
|
|
||||||
this.rixaGuild = rixaGuild;
|
|
||||||
enabled = true;
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<UserData> leaderboard(Member member) {
|
private List<UserData> leaderboard(Member member) {
|
||||||
Database db = Rixa.getDatabase();
|
Database db = Rixa.getDatabase();
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@ -50,7 +44,7 @@ public class LevelsModule implements RixaModule {
|
|||||||
try {
|
try {
|
||||||
while (rs != null && rs.next()) {
|
while (rs != null && rs.next()) {
|
||||||
if (member.getGuild().getMemberById(rs.getString("user_id")) == null) continue;
|
if (member.getGuild().getMemberById(rs.getString("user_id")) == null) continue;
|
||||||
UserData userData = rixaGuild.getLevelsModule().getUserData(rs.getString("user_id"));
|
UserData userData = ((LevelsModule) rixaGuild.getModule("Levels")).getUserData(rs.getString("user_id"));
|
||||||
userDataList.add(userData);
|
userDataList.add(userData);
|
||||||
}
|
}
|
||||||
rs.getStatement().close();
|
rs.getStatement().close();
|
||||||
@ -104,6 +98,35 @@ public class LevelsModule implements RixaModule {
|
|||||||
return "Rixa levels module.";
|
return "Rixa levels module.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(RixaGuild rixaGuild) {
|
||||||
|
try {
|
||||||
|
this.rixaGuild = rixaGuild;
|
||||||
|
Query query = new Query("SELECT * FROM `modules` WHERE `guild_id`=?;");
|
||||||
|
query.setString(rixaGuild.getGuild().getId());
|
||||||
|
Optional<?> o = Rixa.getDatabase().send(query);
|
||||||
|
if (!o.isPresent()) return;
|
||||||
|
else if (!(o.get() instanceof ResultSet)) return;
|
||||||
|
ResultSet set = (ResultSet) o.get();
|
||||||
|
if (set.next()) {
|
||||||
|
setEnabled(set.getBoolean("levels"));
|
||||||
|
} else {
|
||||||
|
Update update = new Update("INSERT INTO `modules` (`guild_id`) VALUES (?);");
|
||||||
|
update.setString(rixaGuild.getGuild().getId());
|
||||||
|
Rixa.getDatabase().send(update);
|
||||||
|
setEnabled(true);
|
||||||
|
}
|
||||||
|
set.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() {
|
||||||
|
DatabaseUtils.update("modules", "levels", "guild_id", enabled, rixaGuild.getGuild().getId());
|
||||||
|
}
|
||||||
|
|
||||||
public void registerUser(UserData userData) {
|
public void registerUser(UserData userData) {
|
||||||
if (getUserData().containsKey(userData.getUser().getId())) {
|
if (getUserData().containsKey(userData.getUser().getId())) {
|
||||||
return;
|
return;
|
||||||
@ -124,62 +147,4 @@ public class LevelsModule implements RixaModule {
|
|||||||
(getRixaGuild().getGuild().getJDA().getUserById(key),
|
(getRixaGuild().getGuild().getJDA().getUserById(key),
|
||||||
getRixaGuild().getGuild());
|
getRixaGuild().getGuild());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void load() {
|
|
||||||
if (!(checkExists())) {
|
|
||||||
this.enabled = true;
|
|
||||||
insert();
|
|
||||||
}
|
|
||||||
String query = "SELECT `levels` FROM `modules` WHERE `guild_id` = ?;";
|
|
||||||
PreparedStatement ps;
|
|
||||||
ResultSet rs;
|
|
||||||
try {
|
|
||||||
ps = Rixa.getDatabase().getConnection().get().prepareStatement(query);
|
|
||||||
ps.setString(1, getRixaGuild().getGuild().getId());
|
|
||||||
rs = ps.executeQuery();
|
|
||||||
if (rs.next()) {
|
|
||||||
this.enabled = rs.getBoolean("levels");
|
|
||||||
}
|
|
||||||
ps.close();
|
|
||||||
rs.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkExists() {
|
|
||||||
Result r = Result.FALSE;
|
|
||||||
try {
|
|
||||||
Query query = new Query("SELECT `guild_id` FROM `modules` WHERE `guild_id` = ?;");
|
|
||||||
query.setString(rixaGuild.getGuild().getId());
|
|
||||||
Optional<?> optional = Rixa.getDatabase().send(query);
|
|
||||||
if (!optional.isPresent()) r = Result.ERROR;
|
|
||||||
if (!(optional.get() instanceof ResultSet)) r = Result.ERROR;
|
|
||||||
ResultSet set = (ResultSet) optional.get();
|
|
||||||
if (r != Result.ERROR) {
|
|
||||||
if (set.next()) {
|
|
||||||
r = Result.TRUE;
|
|
||||||
} else {
|
|
||||||
r = Result.FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set.close();
|
|
||||||
return r == Result.TRUE;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void insert() {
|
|
||||||
String query = "INSERT INTO `modules` (`guild_id`) VALUES (?);";
|
|
||||||
Update update = new Update(query);
|
|
||||||
update.setString(rixaGuild.getGuild().getId());
|
|
||||||
Rixa.getDatabase().send(update);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnabled(boolean enabled) {
|
|
||||||
this.enabled = enabled;
|
|
||||||
DatabaseUtils.update("modules", "levels", "guild_id", enabled, rixaGuild.getGuild().getId());
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
package me.savvy.rixa.modules.music;
|
package me.savvy.rixa.modules.music;
|
||||||
|
|
||||||
|
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||||
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
|
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
|
||||||
import net.dv8tion.jda.core.audio.AudioSendHandler;
|
import net.dv8tion.jda.core.audio.AudioSendHandler;
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Timber on 3/13/2017.
|
* Created by Timber on 3/13/2017.
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
package me.savvy.rixa.modules.music;
|
package me.savvy.rixa.modules.music;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import me.majrly.database.Database;
|
import me.majrly.database.Database;
|
||||||
import me.majrly.database.statements.Query;
|
import me.majrly.database.statements.Query;
|
||||||
import me.majrly.database.statements.Update;
|
import me.majrly.database.statements.Update;
|
||||||
import me.savvy.rixa.Rixa;
|
import me.savvy.rixa.Rixa;
|
||||||
import me.savvy.rixa.enums.Result;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
import me.savvy.rixa.modules.RixaModule;
|
import me.savvy.rixa.modules.RixaModule;
|
||||||
import me.savvy.rixa.utils.DatabaseUtils;
|
import me.savvy.rixa.utils.DatabaseUtils;
|
||||||
import net.dv8tion.jda.core.entities.Guild;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -19,31 +19,28 @@ import java.util.Optional;
|
|||||||
* Created by Timber on 5/23/2017.
|
* Created by Timber on 5/23/2017.
|
||||||
*/
|
*/
|
||||||
public class MusicModule implements RixaModule {
|
public class MusicModule implements RixaModule {
|
||||||
|
|
||||||
private Database db;
|
private Database db;
|
||||||
@Getter
|
@Getter
|
||||||
|
@Setter
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
@Getter
|
@Getter
|
||||||
|
@Setter
|
||||||
private String musicRole;
|
private String musicRole;
|
||||||
@Getter
|
@Getter
|
||||||
private Guild guild;
|
private Guild guild;
|
||||||
|
|
||||||
public MusicModule(Guild guild) {
|
@Override
|
||||||
this.guild = guild;
|
public void load(RixaGuild rixaGuild) {
|
||||||
this.enabled = false;
|
|
||||||
this.musicRole = "default_value";
|
|
||||||
db = Rixa.getDatabase();
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void load() {
|
|
||||||
Update music = new Update("CREATE TABLE IF NOT EXISTS `music` (`guild_id` varchar(255) NOT NULL, `music_role` varchar(255) NOT NULL, `enabled` INT(11) NOT NULL, PRIMARY KEY (`guild_id`));");
|
|
||||||
db.send(music);
|
|
||||||
if (!checkExists()) {
|
|
||||||
Update update = new Update("INSERT INTO `music` (`guild_id`, `music_role`, `enabled`)" +
|
|
||||||
" VALUES ('" + guild.getId() + "', 'default_value', '0');");
|
|
||||||
db.send(update);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
this.guild = rixaGuild.getGuild();
|
||||||
|
this.enabled = false;
|
||||||
|
this.musicRole = "default_value";
|
||||||
|
db = Rixa.getDatabase();
|
||||||
|
if (!DatabaseUtils.checkExists("music", guild)) {
|
||||||
|
Update update = new Update("INSERT INTO `music` (`guild_id`, `music_role`, `enabled`) VALUES ('" + guild.getId() + "', 'default_value', '0');");
|
||||||
|
db.send(update);
|
||||||
|
}
|
||||||
Query query = new Query("SELECT * FROM `modules` WHERE `guild_id` = ?");
|
Query query = new Query("SELECT * FROM `modules` WHERE `guild_id` = ?");
|
||||||
query.setString(guild.getId());
|
query.setString(guild.getId());
|
||||||
Optional<?> optional = Rixa.getDatabase().send(query);
|
Optional<?> optional = Rixa.getDatabase().send(query);
|
||||||
@ -51,8 +48,8 @@ public class MusicModule implements RixaModule {
|
|||||||
if (!(optional.get() instanceof ResultSet)) return;
|
if (!(optional.get() instanceof ResultSet)) return;
|
||||||
ResultSet set = (ResultSet) optional.get();
|
ResultSet set = (ResultSet) optional.get();
|
||||||
if (set.next()) {
|
if (set.next()) {
|
||||||
this.musicRole = set.getString("music_role");
|
setMusicRole(set.getString("music_role"));
|
||||||
this.enabled = set.getBoolean("enabled");
|
setEnabled(set.getBoolean("enabled"));
|
||||||
}
|
}
|
||||||
set.close();
|
set.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -60,6 +57,12 @@ public class MusicModule implements RixaModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() {
|
||||||
|
DatabaseUtils.update("music", "enabled", "guild_id", enabled, guild.getId());
|
||||||
|
DatabaseUtils.update("music", "music_role", "guild_id", musicRole, guild.getId());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Music";
|
return "Music";
|
||||||
@ -70,43 +73,7 @@ public class MusicModule implements RixaModule {
|
|||||||
return "Listen to music in your voice channel.";
|
return "Listen to music in your voice channel.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Result setEnabled(boolean val) {
|
|
||||||
this.enabled = val;
|
|
||||||
return DatabaseUtils.update("music", "enabled", "guild_id", val, guild.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRoleRequired() {
|
public boolean isRoleRequired() {
|
||||||
return (!musicRole.equalsIgnoreCase("default_value"));
|
return (musicRole != null && !musicRole.equalsIgnoreCase("default_value"));
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Result setRole(String newRole) {
|
|
||||||
this.musicRole = newRole;
|
|
||||||
return DatabaseUtils.update("music", "music_role", "guild_id", newRole, guild.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean checkExists() {
|
|
||||||
Result r = Result.FALSE;
|
|
||||||
try {
|
|
||||||
Query query = new Query("SELECT `guild_id` FROM `music` WHERE `guild_id` = '" +
|
|
||||||
guild.getId() + "';");
|
|
||||||
Optional<?> optional = Rixa.getDatabase().send(query);
|
|
||||||
if (!optional.isPresent()) r = Result.ERROR;
|
|
||||||
if (!(optional.get() instanceof ResultSet)) r = Result.ERROR;
|
|
||||||
ResultSet set = (ResultSet) optional.get();
|
|
||||||
if (r != Result.ERROR) {
|
|
||||||
if (set.next()) {
|
|
||||||
r = Result.TRUE;
|
|
||||||
} else {
|
|
||||||
r = Result.FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set.close();
|
|
||||||
return r == Result.TRUE;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package me.savvy.rixa.modules.reactions.react;
|
|||||||
|
|
||||||
import me.savvy.rixa.commands.admin.ConfigCommand;
|
import me.savvy.rixa.commands.admin.ConfigCommand;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.modules.reactions.handlers.React;
|
import me.savvy.rixa.modules.reactions.handlers.React;
|
||||||
import me.savvy.rixa.modules.reactions.handlers.ReactHandle;
|
import me.savvy.rixa.modules.reactions.handlers.ReactHandle;
|
||||||
import me.savvy.rixa.utils.MessageBuilder;
|
import me.savvy.rixa.utils.MessageBuilder;
|
||||||
@ -30,7 +31,7 @@ public class ConfigReaction implements React {
|
|||||||
if(guild == null) {
|
if(guild == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(guild);
|
RixaGuild rixaGuild = Guilds.getGuild(guild);
|
||||||
String prefix = rixaGuild.getGuildSettings().getPrefix();
|
String prefix = rixaGuild.getGuildSettings().getPrefix();
|
||||||
MessageBuilder builder = null;
|
MessageBuilder builder = null;
|
||||||
int page = 500;
|
int page = 500;
|
||||||
|
@ -3,7 +3,7 @@ package me.savvy.rixa.modules.reactions.react;
|
|||||||
import me.savvy.rixa.commands.handlers.CommandHandler;
|
import me.savvy.rixa.commands.handlers.CommandHandler;
|
||||||
import me.savvy.rixa.commands.handlers.CommandType;
|
import me.savvy.rixa.commands.handlers.CommandType;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
import me.savvy.rixa.modules.reactions.handlers.React;
|
import me.savvy.rixa.modules.reactions.handlers.React;
|
||||||
import me.savvy.rixa.modules.reactions.handlers.ReactHandle;
|
import me.savvy.rixa.modules.reactions.handlers.ReactHandle;
|
||||||
import net.dv8tion.jda.core.EmbedBuilder;
|
import net.dv8tion.jda.core.EmbedBuilder;
|
||||||
@ -26,7 +26,7 @@ public class HelpReaction implements React {
|
|||||||
}
|
}
|
||||||
Message message = event.getChannel().getMessageById(event.getMessageId()).complete();
|
Message message = event.getChannel().getMessageById(event.getMessageId()).complete();
|
||||||
String title = message.getEmbeds().get(0).getTitle().split(": ")[1];
|
String title = message.getEmbeds().get(0).getTitle().split(": ")[1];
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(event.getJDA().getGuildById(title));
|
RixaGuild rixaGuild = Guilds.getGuild(event.getJDA().getGuildById(title));
|
||||||
String prefix = rixaGuild.getGuildSettings().getPrefix();
|
String prefix = rixaGuild.getGuildSettings().getPrefix();
|
||||||
EmbedBuilder embedBuilder;
|
EmbedBuilder embedBuilder;
|
||||||
try {
|
try {
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
package me.savvy.rixa.modules.reactions.react;
|
package me.savvy.rixa.modules.reactions.react;
|
||||||
|
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
|
import me.savvy.rixa.guild.management.Guilds;
|
||||||
|
import me.savvy.rixa.modules.levels.LevelsModule;
|
||||||
import me.savvy.rixa.modules.reactions.handlers.React;
|
import me.savvy.rixa.modules.reactions.handlers.React;
|
||||||
import me.savvy.rixa.modules.reactions.handlers.ReactHandle;
|
import me.savvy.rixa.modules.reactions.handlers.ReactHandle;
|
||||||
import net.dv8tion.jda.core.MessageBuilder;
|
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
|
||||||
import net.dv8tion.jda.core.entities.Guild;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.Message;
|
import net.dv8tion.jda.core.entities.Message;
|
||||||
import net.dv8tion.jda.core.entities.MessageEmbed;
|
|
||||||
import net.dv8tion.jda.core.events.message.guild.react.GuildMessageReactionAddEvent;
|
import net.dv8tion.jda.core.events.message.guild.react.GuildMessageReactionAddEvent;
|
||||||
import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent;
|
import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent;
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ public class LeaderboardReaction implements React {
|
|||||||
if(guild == null) {
|
if(guild == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RixaGuild rixaGuild = RixaGuild.getGuild(guild);
|
RixaGuild rixaGuild = Guilds.getGuild(guild);
|
||||||
int page = 500;
|
int page = 500;
|
||||||
switch (event.getReaction().getEmote().getName()) {
|
switch (event.getReaction().getEmote().getName()) {
|
||||||
case "\u2B05":// previous
|
case "\u2B05":// previous
|
||||||
@ -38,7 +37,7 @@ public class LeaderboardReaction implements React {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(page != 500) {
|
if(page != 500) {
|
||||||
me.savvy.rixa.utils.MessageBuilder builder = rixaGuild.getLevelsModule().leaderboard
|
me.savvy.rixa.utils.MessageBuilder builder = ((LevelsModule) rixaGuild.getModule("Levels")).leaderboard
|
||||||
(event.getMember(), page);
|
(event.getMember(), page);
|
||||||
if (builder == null) return;
|
if (builder == null) return;
|
||||||
message.editMessage(builder.getBuilder().build()).queue();
|
message.editMessage(builder.getBuilder().build()).queue();
|
||||||
|
@ -4,7 +4,10 @@ import lombok.Getter;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import me.savvy.rixa.guild.RixaGuild;
|
import me.savvy.rixa.guild.RixaGuild;
|
||||||
import me.savvy.rixa.modules.RixaModule;
|
import me.savvy.rixa.modules.RixaModule;
|
||||||
import twitter4j.*;
|
import twitter4j.Twitter;
|
||||||
|
import twitter4j.TwitterFactory;
|
||||||
|
import twitter4j.TwitterStream;
|
||||||
|
import twitter4j.TwitterStreamFactory;
|
||||||
import twitter4j.conf.ConfigurationBuilder;
|
import twitter4j.conf.ConfigurationBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,4 +60,10 @@ public class TwitterModule implements RixaModule {
|
|||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return "Twitter feed, tweet & more.";
|
return "Twitter feed, tweet & more.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(RixaGuild guild) { }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() { }
|
||||||
}
|
}
|
@ -1,8 +1,14 @@
|
|||||||
package me.savvy.rixa.utils;
|
package me.savvy.rixa.utils;
|
||||||
|
|
||||||
|
import me.majrly.database.statements.Query;
|
||||||
import me.majrly.database.statements.Update;
|
import me.majrly.database.statements.Update;
|
||||||
import me.savvy.rixa.Rixa;
|
import me.savvy.rixa.Rixa;
|
||||||
import me.savvy.rixa.enums.Result;
|
import me.savvy.rixa.enums.Result;
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class DatabaseUtils {
|
public class DatabaseUtils {
|
||||||
|
|
||||||
@ -13,4 +19,27 @@ public class DatabaseUtils {
|
|||||||
Rixa.getDatabase().send(update);
|
Rixa.getDatabase().send(update);
|
||||||
return Result.TRUE;
|
return Result.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean checkExists(String table, Guild guild) {
|
||||||
|
Result r = Result.FALSE;
|
||||||
|
try {
|
||||||
|
Query query = new Query("SELECT `guild_id` FROM `" + table + "` WHERE `guild_id` = '" + guild.getId() + "';");
|
||||||
|
Optional<?> optional = Rixa.getDatabase().send(query);
|
||||||
|
if (!optional.isPresent()) r = Result.ERROR;
|
||||||
|
if (!(optional.get() instanceof ResultSet)) r = Result.ERROR;
|
||||||
|
ResultSet set = (ResultSet) optional.get();
|
||||||
|
if (r != Result.ERROR) {
|
||||||
|
if (set.next()) {
|
||||||
|
r = Result.TRUE;
|
||||||
|
} else {
|
||||||
|
r = Result.FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set.close();
|
||||||
|
return r == Result.TRUE;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.out.println("INFO: Failed to check if exists : " + e.getLocalizedMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,7 +2,10 @@ package me.savvy.rixa.utils;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.dv8tion.jda.core.EmbedBuilder;
|
import net.dv8tion.jda.core.EmbedBuilder;
|
||||||
import net.dv8tion.jda.core.entities.*;
|
import net.dv8tion.jda.core.entities.Message;
|
||||||
|
import net.dv8tion.jda.core.entities.MessageEmbed;
|
||||||
|
import net.dv8tion.jda.core.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.core.entities.User;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user