Merge remote-tracking branch 'origin/master'

# Conflicts:
#	.idea/workspace.xml
This commit is contained in:
Venal 2017-08-15 00:01:24 -04:00
commit b2332f3f68
30 changed files with 967 additions and 220 deletions

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,6 @@ import me.savvy.rixa.commands.handlers.CommandExec;
import me.savvy.rixa.commands.handlers.CommandType;
import me.savvy.rixa.commands.handlers.RixaPermission;
import me.savvy.rixa.guild.RixaGuild;
import me.savvy.rixa.guild.RixaGuild;
import me.savvy.rixa.utils.MessageBuilder;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.Member;
@ -88,7 +87,7 @@ public class ConfigCommand implements CommandExec {
}
String message;
if (messages[1].equalsIgnoreCase("joinmessage")) {
message = getMessage(messages, 2);
message = getMessage(messages);
if(event.getMessage().getMentionedChannels().size() > 0) {
for (TextChannel messageChannel : event.getMessage().getMentionedChannels()) {
message = message.replace(messageChannel.getAsMention(), "<#" + messageChannel.getId() + ">");
@ -98,7 +97,7 @@ public class ConfigCommand implements CommandExec {
new MessageBuilder("Successfully set Join Message to\n" + message.replace("{0}", event.getMember().getUser().getName())
.replace("{1}", event.getGuild().getName())).setColor(event.getMember().getColor()).queue(event.getChannel());
} else if (messages[1].equalsIgnoreCase("quitmessage")) {
message = getMessage(messages, 2);
message = getMessage(messages);
if(event.getMessage().getMentionedChannels().size() > 0) {
for (TextChannel messageChannel : event.getMessage().getMentionedChannels()) {
message = message.replace(messageChannel.getAsMention(), "<#" + messageChannel.getId() + ">");
@ -108,7 +107,7 @@ public class ConfigCommand implements CommandExec {
new MessageBuilder("Successfully set Quit Message to\n" + message.replace("{0}", event.getMember().getUser().getName())
.replace("{1}", event.getGuild().getName())).setColor(event.getMember().getColor()).queue(event.getChannel());
} else if (messages[1].equalsIgnoreCase("joinpm")) {
message = getMessage(messages, 2);
message = getMessage(messages);
if(event.getMessage().getMentionedChannels().size() > 0) {
for (TextChannel messageChannel : event.getMessage().getMentionedChannels()) {
message = message.replace(messageChannel.getAsMention(), "<#" + messageChannel.getId() + ">");
@ -118,7 +117,7 @@ public class ConfigCommand implements CommandExec {
new MessageBuilder("Successfully set Private Join Message to\n" + message.replace("{0}", event.getMember().getUser().getName())
.replace("{1}", event.getGuild().getName())).setColor(event.getMember().getColor()).queue(event.getChannel());
} else if (messages[1].equalsIgnoreCase("description")) {
message = getMessage(messages, 2);
message = getMessage(messages);
rixaGuild.getGuildSettings().setDescription(message);
new MessageBuilder("Successfully set Server Description to\n" + message.replace("{0}", event.getMember().getUser().getName())
.replace("{1}", event.getGuild().getName())).setColor(event.getMember().getColor()).queue(event.getChannel());
@ -174,10 +173,10 @@ public class ConfigCommand implements CommandExec {
if (messages[2].equalsIgnoreCase("music")) {
RixaGuild.getGuild(event.getGuild()).getMusicModule().setEnabled(true);
new MessageBuilder("Successfully enabled the music module!").setColor(event.getMember().getColor()).queue(event.getChannel());
} /*else if (messages[2].equalsIgnoreCase("levels")) {
GuildManager.getGuild(event.getGuild().getId()).getLevels().setEnabled(true);
event.getChannel().sendMessage("Successfully enabled the `Levels` module").queue();
}*/ else if (messages[2].equalsIgnoreCase("joinverification")) {
} else if (messages[2].equalsIgnoreCase("levels")) {
RixaGuild.getGuild(event.getGuild()).getLevelsModule().setEnabled(true);
event.getChannel().sendMessage("Successfully enabled the levels module").queue();
} else if (messages[2].equalsIgnoreCase("joinverification")) {
RixaGuild.getGuild(event.getGuild()).getGuildSettings().setJoinVerification(true);
new MessageBuilder("Successfully enabled Join Verification!").setColor(event.getMember().getColor()).queue(event.getChannel());
}
@ -185,10 +184,10 @@ public class ConfigCommand implements CommandExec {
if (messages[2].equalsIgnoreCase("music")) {
RixaGuild.getGuild(event.getGuild()).getMusicModule().setEnabled(false);
new MessageBuilder("Successfully disabled the music module!").setColor(event.getMember().getColor()).queue(event.getChannel());
}/* else if (messages[2].equalsIgnoreCase("levels")) {
GuildManager.getGuild(event.getGuild().getId()).getLevels().setEnabled(false);
event.getChannel().sendMessage("Successfully disabled the `Levels` module").queue();
}*/ else if (messages[2].equalsIgnoreCase("joinverification")) {
} else if (messages[2].equalsIgnoreCase("levels")) {
RixaGuild.getGuild(event.getGuild()).getLevelsModule().setEnabled(false);
event.getChannel().sendMessage("Successfully disabled the levels module").queue();
} else if (messages[2].equalsIgnoreCase("joinverification")) {
RixaGuild.getGuild(event.getGuild()).getGuildSettings().setJoinVerification(false);
new MessageBuilder("Successfully disabled Join Verification!").setColor(event.getMember().getColor()).queue(event.getChannel());
}
@ -274,9 +273,9 @@ public class ConfigCommand implements CommandExec {
return builder.setColor(member.getColor()).setTitle(String.format("Config: %s", member.getGuild().getId()));
}
private String getMessage(String[] messages, int argToBegin) {
private String getMessage(String[] messages) {
StringBuilder builder = new StringBuilder();
for(int i = argToBegin; i < messages.length; i++) {
for(int i = 2; i < messages.length; i++) {
builder.append(messages[i]).append(" ");
}
return builder.toString().trim();

View File

@ -0,0 +1,9 @@
package me.savvy.rixa.commands.admin;
public class LevelsManagementCommand {
// xp give/add <user> <amount>
// xp take/remove <user> <amount>
// xp set <user> <amount>
// xp convert <type> <user/all>
}

View File

@ -28,7 +28,7 @@ public class InfoCommand implements CommandExec {
EmbedBuilder messageEmbed = new EmbedBuilder();
User botOwner = event.getJDA().getUserById("202944101333729280");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss");
Date date1 = new Date(Rixa.getInstance().getTimeUp());
Date date1 = new Date(Rixa.getTimeUp());
Date date2 = new Date();
long difference = date2.getTime() - date1.getTime();
long seconds = difference / 1000;
@ -38,7 +38,7 @@ public class InfoCommand implements CommandExec {
long second = TimeUnit.SECONDS.toSeconds(seconds) - (TimeUnit.SECONDS.toMinutes(seconds) *60);
int guildCount = 0;
int userCount = 0;
for(JDA jda: Rixa.getInstance().getShardsList()) {
for(JDA jda: Rixa.getShardsList()) {
guildCount += jda.getGuilds().size();
userCount += jda.getUsers().size();
}

View File

@ -10,6 +10,7 @@ import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import java.io.IOException;
import java.util.*;
/**
* Created by savit on 7/11/2017.
@ -27,6 +28,11 @@ public class LevelsCommand implements CommandExec {
return;
}
UserData data = rixaGuild.getLevelsModule().getUserData(event.getAuthor().getId());
// Map<UserData, Integer> newMap = new HashMap<>();
// rixaGuild.getLevelsModule().getUserData().forEach((s, userData) -> {
// newMap.put(userData, userData.getExperience());
// });
// sortHashMapByValues(newMap);
new MessageBuilder()
.setAuthor(event.getAuthor().getName(), event.getAuthor().getEffectiveAvatarUrl(), event.getAuthor().getEffectiveAvatarUrl())
.setTitle(event.getAuthor().getName() + "'s level")
@ -39,4 +45,32 @@ public class LevelsCommand implements CommandExec {
.addField("Total Exp", String.valueOf(data.getExperience()), false)
.queue(event.getChannel());
}
public LinkedHashMap<UserData, Integer> sortHashMapByValues(
Map<UserData, Integer> passedMap) {
List<UserData> mapKeys = new ArrayList<>(passedMap.keySet());
List<Integer> mapValues = new ArrayList<>(passedMap.values());
Collections.sort(mapValues);
//Collections.sort(mapKeys);
LinkedHashMap<UserData, Integer> sortedMap =
new LinkedHashMap<>();
for (Integer val : mapValues) {
Iterator<UserData> keyIt = mapKeys.iterator();
while (keyIt.hasNext()) {
UserData key = keyIt.next();
Integer comp1 = passedMap.get(key);
if (comp1.equals(val)) {
keyIt.remove();
sortedMap.put(key, val);
break;
}
}
}
return sortedMap;
}
}

View File

@ -42,7 +42,7 @@ import java.util.logging.Level;
*/
public class MusicCommand implements CommandExec {
public final int DEFAULT_VOLUME = 35; //(0 - 150, where 100 is default max volume)
private final int DEFAULT_VOLUME = 35; //(0 - 150, where 100 is default max volume)
private final AudioPlayerManager playerManager;
private final Map<String, MusicManager> musicManagers;
public MusicCommand() {
@ -92,7 +92,7 @@ public class MusicCommand implements CommandExec {
if(message.length == 1) {
sendHelp();
} else if (message.length == 2) {
if(message[1].equalsIgnoreCase("join")) {
if(message[1].equalsIgnoreCase("join") || message[1].equalsIgnoreCase("summon") ) {
if (event.getMember().getVoiceState().getChannel() == null) {
new MessageBuilder("You must be in a voice channel to summon me!").setColor(event.getMember().getColor()).queue(event.getChannel());
return;
@ -114,16 +114,14 @@ public class MusicCommand implements CommandExec {
new MessageBuilder("The audio queue is empty! Add a track to the queue first!").setColor(event.getMember().getColor()).queue(event.getChannel());
}
} else if (message[1].equalsIgnoreCase("leave")) {
new MessageBuilder("Leaving voice channel.").setColor(event.getMember().getColor()).queue(event.getChannel());
guild.getAudioManager().setSendingHandler(null);
String desc = "";
AudioTrack track = scheduler.nextTrack();
if(track != null) {
new MessageBuilder("The current track has been skipped. Now Playiguild.getAudioManager().closeAudioConnection();\n" +
" } else if(message[1].equalsIgnoreCase(\"skip\")) {ng: " + track.getInfo().title).setColor(event.getMember().getColor()).queue(event.getChannel());
} else {
new MessageBuilder("Track Skipped. Queue Complete").setColor(event.getMember().getColor()).queue(event.getChannel());
desc += "Track skipped. ";
}
new MessageBuilder(desc + " Leaving voice channel...").setColor(event.getMember().getColor()).queue(event.getChannel());
guild.getAudioManager().setSendingHandler(null);
guild.getAudioManager().closeAudioConnection();
} else if(message[1].equalsIgnoreCase("link")) {
if (player.getPlayingTrack() == null) {
new MessageBuilder("There is no track currently playing.").setColor(event.getMember().getColor()).queue(event.getChannel());
@ -217,16 +215,13 @@ public class MusicCommand implements CommandExec {
} else if (message.length == 3) {
if(message[1].equalsIgnoreCase("join")) {
VoiceChannel chan = null;
StringBuilder stringBuilder = new StringBuilder();
for (int i = 2; i != message.length; i++) {
stringBuilder.append(message[i]).append(" ");
}
String channelName = stringBuilder.toString();
String channelName = message[2];//getMessage(message, 2).trim();
if (guild.getVoiceChannelsByName(channelName, true).size() >= 1) {
chan = guild.getVoiceChannelsByName(channelName, true).get(0);
} else {
for (VoiceChannel voiceChannel : guild.getVoiceChannels()) {
if (voiceChannel.getName().contains(channelName) || voiceChannel.getId().equalsIgnoreCase(channelName)) {
if (voiceChannel.getName().contains(channelName) || voiceChannel.getName().equalsIgnoreCase(channelName) ||
voiceChannel.getId().equalsIgnoreCase(channelName)) {
chan = voiceChannel;
break;
}
@ -246,7 +241,18 @@ public class MusicCommand implements CommandExec {
}
}
} else if(message[1].equalsIgnoreCase("play") || message[1].equalsIgnoreCase("playlist")) {
loadAndPlay(mng, event.getChannel(), message[2], false);
if (event.getMember().getVoiceState().getChannel() == null) {
new MessageBuilder("You must be in a voice channel to summon me!").setColor(event.getMember().getColor()).queue(event.getChannel());
return;
}
try {
guild.getAudioManager().openAudioConnection(event.getMember().getVoiceState().getChannel());
loadAndPlay(mng, event.getChannel(), message[2], false);
} catch (PermissionException e) {
if (e.getPermission() == Permission.VOICE_CONNECT) {
new MessageBuilder("I do not have permission to join the requested voice channel.").setColor(event.getMember().getColor()).queue(event.getChannel());
}
}
} else if(message[1].equalsIgnoreCase("vol") || message[1].equalsIgnoreCase("volume")) {
try {
int newVolume = Math.max(10, Math.min(100, Integer.parseInt(message[2])));
@ -258,8 +264,35 @@ public class MusicCommand implements CommandExec {
}
}
} // music youtube <query
if(message.length >= 3) {
if(message[1].equalsIgnoreCase("youtube") || message[1].equalsIgnoreCase("yt") || message[1].equalsIgnoreCase("search")
else if(message.length >= 3) {
if(message[1].equalsIgnoreCase("join")) {
VoiceChannel chan = null;
String channelName = getMessage(message, 2);
if (guild.getVoiceChannelsByName(channelName, true).size() >= 1) {
chan = guild.getVoiceChannelsByName(channelName, true).get(0);
} else {
for (VoiceChannel voiceChannel : guild.getVoiceChannels()) {
if (voiceChannel.getName().contains(channelName) || voiceChannel.getId().equalsIgnoreCase(channelName)
|| voiceChannel.getName().equalsIgnoreCase(channelName)) {
chan = voiceChannel;
break;
}
}
}
if (chan == null) {
new MessageBuilder("Sorry I was unable to find the VoiceChannel: `" + message[2] + "`.").setColor(event.getMember().getColor()).queue(event.getChannel());
} else {
guild.getAudioManager().setSendingHandler(mng.sendHandler);
try {
new MessageBuilder("Entering Voice Channel: " + chan.getName()).setColor(event.getMember().getColor()).queue(event.getChannel());
guild.getAudioManager().openAudioConnection(chan);
} catch (PermissionException e) {
if (e.getPermission() == Permission.VOICE_CONNECT) {
new MessageBuilder("I do not have permission to join the requested voice channel.").setColor(event.getMember().getColor()).queue(event.getChannel());
}
}
}
} else if(message[1].equalsIgnoreCase("youtube") || message[1].equalsIgnoreCase("yt") || message[1].equalsIgnoreCase("search")
|| message[1].equalsIgnoreCase("ytsearch")) {
String search = getMessage(message, 2);
try {

View File

@ -23,7 +23,7 @@ public class UrbanDictionaryCommand implements CommandExec {
channelType = ChannelType.TEXT)
public void execute(GuildMessageReceivedEvent event) {
String[] message = event.getMessage().getContent().split(" ");
String search = getMessage(message, 1);
String search = getMessage(message);
UrbanDictionary ud = null;
try {
ud = new UrbanDictionary(URLEncoder.encode(search, "UTF-8"));
@ -45,9 +45,9 @@ public class UrbanDictionaryCommand implements CommandExec {
.addThumbnail("https://s-media-cache-ak0.pinimg.com/originals/f2/aa/37/f2aa3712516cfd0cf6f215301d87a7c2.jpg").queue(event.getChannel());
}
private String getMessage(String[] messages, int argToBegin) {
private String getMessage(String[] messages) {
StringBuilder builder = new StringBuilder();
for(int i = argToBegin; i < messages.length; i++) {
for(int i = 1; i < messages.length; i++) {
builder.append(messages[i]).append(" ");
}
return builder.toString().trim();

View File

@ -21,7 +21,7 @@ public class YoutubeCommand implements CommandExec {
channelType = ChannelType.TEXT)
public void execute(GuildMessageReceivedEvent event) {
String[] message = event.getMessage().getContent().split(" ");
String search = getMessage(message, 1);
String search = getMessage(message);
try {
YoutubeSearch ytSearch = new YoutubeSearch(search);
new MessageBuilder(ytSearch.getUrl(0))
@ -31,9 +31,9 @@ public class YoutubeCommand implements CommandExec {
}
}
private String getMessage(String[] messages, int argToBegin) {
private String getMessage(String[] messages) {
StringBuilder builder = new StringBuilder() ;
for(int i = argToBegin; i < messages.length; i++) {
for(int i = 1; i < messages.length; i++) {
builder.append(messages[i]).append(" ");
}
return builder.toString().trim();

View File

@ -7,5 +7,5 @@ import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
*/
public interface CommandExec {
public void execute(GuildMessageReceivedEvent event);
void execute(GuildMessageReceivedEvent event);
}

View File

@ -25,6 +25,9 @@ public class CommandHandler {
return true;
} else {
for (CommandRegistrar commandRegistrar : getCommands().values()) {
if (commandRegistrar.getAnnotation().mainCommand().equalsIgnoreCase(s)) {
return true;
}
for (String string : commandRegistrar.getAnnotation().aliases()) {
if (string.equalsIgnoreCase(s)) return true;
}

View File

@ -4,5 +4,5 @@ package me.savvy.rixa.commands.handlers;
* Created by Timber on 5/22/2017.
*/
public enum CommandType {
USER, MOD, ADMIN, BOT_OWNER;
USER, MOD, ADMIN, BOT_OWNER
}

View File

@ -18,7 +18,7 @@ public class Data {
private DatabaseManager db;
public Data(DataType dataType) {
this.dataType = dataType;
this.db = Rixa.getInstance().getDbManager();
this.db = Rixa.getDbManager();
}
public Object get(String key, String value, String objToGet, String table) throws SQLException {
@ -64,7 +64,11 @@ public class Data {
public Result exists(String check) {
switch(dataType) {
case SQL:
return db.checkExists(check);
try {
return db.checkExists(check);
} catch (SQLException e) {
e.printStackTrace();
}
}
return Result.FALSE;
}

View File

@ -6,5 +6,5 @@ package me.savvy.rixa.data.database;
public enum DataType {
SQL,
FLAT_FILE;
FLAT_FILE
}

View File

@ -23,18 +23,12 @@ public class DatabaseManager {
}
public void createTable() {
try {
connection = MYSQL.openConnection();
Rixa.getInstance().getLogger().info("Mysql database connected");
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
checkConnection();
try {
PreparedStatement ps = connection.prepareStatement(
"CREATE TABLE IF NOT EXISTS `core` (`guild_id` varchar(255) NOT NULL, `guild_name` varchar(255) NOT NULL, PRIMARY KEY (`guild_id`));");
ps.executeUpdate();
ps.close();
connection.close();
} catch (SQLException e) {
Rixa.getInstance().getLogger().severe("Could not check if table exists, stopping server.");
e.printStackTrace();
@ -46,6 +40,7 @@ public class DatabaseManager {
try {
if (!MYSQL.checkConnection()) {
connection = MYSQL.openConnection();
Rixa.getInstance().getLogger().info("Mysql database connected");
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
@ -112,12 +107,18 @@ public class DatabaseManager {
public Result checkExists(String string) throws SQLException {
checkConnection();
PreparedStatement preparedStatement = connection.prepareStatement(string);
ResultSet resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
return Result.TRUE;
} else {
return Result.FALSE;
try {
PreparedStatement ps = connection.prepareStatement(string);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
rs.close();
return Result.TRUE;
} else {
rs.close();
return Result.FALSE;
}
} catch (SQLException e) {
return Result.ERROR;
}
}

View File

@ -36,7 +36,7 @@ public abstract class Database {
* @throws ClassNotFoundException
* if the driver cannot be found
*/
public abstract Connection openConnection() throws SQLException,
protected abstract Connection openConnection() throws SQLException,
ClassNotFoundException;
/**
@ -88,9 +88,7 @@ public abstract class Database {
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery(query);
return result;
return statement.executeQuery(query);
}
/**
@ -114,8 +112,6 @@ public abstract class Database {
Statement statement = connection.createStatement();
int result = statement.executeUpdate(query);
return result;
return statement.executeUpdate(query);
}
}

View File

@ -73,7 +73,6 @@ public class MySQL extends Database {
}
Class.forName("com.mysql.jdbc.Driver");
// Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL,
this.user, this.password);
return connection;

View File

@ -3,5 +3,5 @@ package me.savvy.rixa.data.placeholder;
/**
* Created by Timber on 6/4/2017.
*/
public class PlaceHolder {
class PlaceHolder {
}

View File

@ -8,5 +8,5 @@ public enum Result {
SUCCESS,
TRUE,
FALSE,
ERROR;
ERROR
}

View File

@ -36,6 +36,7 @@ public class MessageEvent {
@SubscribeEvent
public void handle(GuildMessageReceivedEvent event) {
if (event.getGuild() == null) return;
if (event.getAuthor().isBot()) return;
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
String prefix = rixaGuild
.getGuildSettings()
@ -45,10 +46,10 @@ public class MessageEvent {
if (!(rixaGuild.getLevelsModule().isEnabled())) {
return;
}
if(!event.getAuthor().getId().equalsIgnoreCase("202944101333729280") &&
/*if(!event.getAuthor().getId().equalsIgnoreCase("202944101333729280") &&
!event.getAuthor().getId().equalsIgnoreCase("207322957075185665")) {
return;
}
}*/
if(rixaGuild.getLevelsModule().getUserData(event.getAuthor().getId()).awardIfCan()) {
new MessageBuilder(event.getAuthor().getAsMention() + " has leveled up to level " +
rixaGuild.getLevelsModule().getUserData(event.getAuthor().getId()).getLevel())

View File

@ -60,7 +60,12 @@ public class RixaGuild {
}
private boolean checkExists() {
Result r = Rixa.getDbManager().checkExists("SELECT `guild_name` FROM `core` WHERE `guild_id` = '" + guild.getId() + "';");
Result r = Result.ERROR;
try {
r = Rixa.getDbManager().checkExists("SELECT `guild_name` FROM `core` WHERE `guild_id` = '" + guild.getId() + "';");
} catch (SQLException e) {
e.printStackTrace();
}
return r == Result.TRUE;
}
@ -141,7 +146,7 @@ public class RixaGuild {
@Getter
private static Map<String, RixaGuild> guilds = new HashMap<>();
public static void addGuild(RixaGuild guild) {
private static void addGuild(RixaGuild guild) {
if(check(guild.getGuild())) return;
guilds.put(guild.getGuild().getId(), guild);
}

View File

@ -34,16 +34,16 @@ public class GuildSettings {
private void load() throws SQLException {
if(!checkExists()) {
Rixa.getInstance().getDbManager().insert("INSERT INTO `settings` (`guild_id`, `log_enabled`, `log_channel`, `joinMessage`, `quitMessage`, `greetings`, `farewell`," +
Rixa.getDbManager().insert("INSERT INTO `settings` (`guild_id`, `log_enabled`, `log_channel`, `joinMessage`, `quitMessage`, `greetings`, `farewell`," +
" `prefix`, `joinPm`, `joinVerification`, `defaultRole`, `muteRole`)" +
" VALUES ('" + guild.getId() + "', '0', 'default_value', 'default_value', 'default_value', 'default_value', 'default_value', '/'," +
" 'default', '0', 'default_value', 'default_value');");
return;
}
PreparedStatement ps = Rixa.getInstance().getDbManager()
PreparedStatement ps = Rixa.getDbManager()
.getConnection().prepareStatement("SELECT * FROM `settings` WHERE `guild_id` = ?");
ps.setString(1, guild.getId());
ResultSet set = Rixa.getInstance().getDbManager().getObject(ps);
ResultSet set = Rixa.getDbManager().getObject(ps);
this.prefix = (set.getString("prefix"));
this.defaultRole = (set.getString("defaultRole"));
this.joinMessage = (set.getString("joinMessage"));
@ -57,16 +57,21 @@ public class GuildSettings {
if(!set.getString("farewell").equalsIgnoreCase("default_value")) {
quitMessageChannel = guild.getTextChannelById(set.getString("farewell"));
}
ps = Rixa.getInstance().getDbManager()
ps = Rixa.getDbManager()
.getConnection().prepareStatement("SELECT * FROM `core` WHERE `guild_id` = ?");
ps.setString(1, guild.getId());
set = Rixa.getInstance().getDbManager().getObject(ps);
set = Rixa.getDbManager().getObject(ps);
this.description = (set.getString("description"));
this.enlisted = (set.getBoolean("enlisted"));
}
private boolean checkExists() {
return Rixa.getInstance().getDbManager().checkExists("SELECT `guild_id` FROM `settings` WHERE `guild_id` = '" + guild.getId() + "'") == Result.TRUE;
try {
return Rixa.getDbManager().checkExists("SELECT `guild_id` FROM `settings` WHERE `guild_id` = '" + guild.getId() + "'") == Result.TRUE;
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
public void unload() {
@ -75,56 +80,56 @@ public class GuildSettings {
public void setJoinMessage(String joinMessage) {
this.joinMessage = joinMessage;
Rixa.getInstance().getData().update("settings", "joinMessage", "guild_id", joinMessage, guild.getId());
Rixa.getData().update("settings", "joinMessage", "guild_id", joinMessage, guild.getId());
}
public void setQuitMessage(String quitMessage) {
this.quitMessage = quitMessage;
Rixa.getInstance().getData().update("settings", "quitMessage", "guild_id", quitMessage, guild.getId());
Rixa.getData().update("settings", "quitMessage", "guild_id", quitMessage, guild.getId());
}
public void setJoinPrivateMessage(String joinPrivateMessage) {
this.joinPrivateMessage = joinPrivateMessage;
Rixa.getInstance().getData().update("settings", "joinPM", "guild_id", joinPrivateMessage, guild.getId());
Rixa.getData().update("settings", "joinPM", "guild_id", joinPrivateMessage, guild.getId());
}
public void setJoinMessageChannel(TextChannel joinMessageChannel) {
this.joinMessageChannel = joinMessageChannel;
Rixa.getInstance().getData().update("settings", "greetings", "guild_id", joinMessageChannel.getId(), guild.getId());
Rixa.getData().update("settings", "greetings", "guild_id", joinMessageChannel.getId(), guild.getId());
}
public void setQuitMessageChannel(TextChannel quitMessageChannel) {
this.quitMessageChannel = quitMessageChannel;
Rixa.getInstance().getData().update("settings", "farewell", "guild_id", quitMessageChannel.getId(), guild.getId());
Rixa.getData().update("settings", "farewell", "guild_id", quitMessageChannel.getId(), guild.getId());
}
public void setDefaultRole(String defaultRole) {
this.defaultRole = defaultRole;
Rixa.getInstance().getData().update("settings", "defaultRole", "guild_id", defaultRole, guild.getId());
Rixa.getData().update("settings", "defaultRole", "guild_id", defaultRole, guild.getId());
}
public void setPrefix(String prefix) {
this.prefix = prefix;
Rixa.getInstance().getData().update("settings", "prefix", "guild_id", prefix, guild.getId());
Rixa.getData().update("settings", "prefix", "guild_id", prefix, guild.getId());
}
public void setDescription(String description) {
this.description = description;
Rixa.getInstance().getData().update("core", "description", "guild_id", description, guild.getId());
Rixa.getData().update("core", "description", "guild_id", description, guild.getId());
}
public void setEnlisted(boolean enlisted) {
this.enlisted = enlisted;
Rixa.getInstance().getData().update("core", "enlisted", "guild_id", enlisted, guild.getId());
Rixa.getData().update("core", "enlisted", "guild_id", enlisted, guild.getId());
}
public void setMuteRole(String muteRole) {
this.muteRole = muteRole;
Rixa.getInstance().getData().update("settings", "muteRole", "guild_id", muteRole, guild.getId());
Rixa.getData().update("settings", "muteRole", "guild_id", muteRole, guild.getId());
}
public void setJoinVerification(boolean joinVerification) {
this.joinVerification = joinVerification;
Rixa.getInstance().getData().update("settings", "joinVerification", "guild_id", joinVerification, guild.getId());
Rixa.getData().update("settings", "joinVerification", "guild_id", joinVerification, guild.getId());
}
}

View File

@ -104,9 +104,15 @@ public class UserData {
private boolean checkExists() {
String query = "SELECT `%s` FROM `%s` WHERE `%s` = '%s' AND `%s` = '%s';";
Result r = Rixa.getDbManager().checkExists(String.format
(query, "user_id", "levels", "guild_id", guild.getId(), "user_id", user.getId()));
Result r;
try {
r = Rixa.getDbManager().checkExists(String.format
(query, "user_id", "levels", "guild_id", guild.getId(), "user_id", user.getId()));
return r == Result.TRUE;
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
private void insert() {
@ -115,7 +121,7 @@ public class UserData {
.insert(String.format(query, "levels", "guild_id", "user_id", "experience", guild.getId(), user.getId(), 0));
}
public void setExperience(int experience) {
private void setExperience(int experience) {
this.experience = experience;
String query = "UPDATE `%s` SET `%s` = '%s' WHERE `%s` = '%s' AND `%s` = '%s';";
try {
@ -129,7 +135,7 @@ public class UserData {
}
}
public int getRandom() {
private int getRandom() {
int i = random.nextInt(25);
return (i > 15 && i < 25 ? i : getRandom());
}

View File

@ -1,10 +1,17 @@
package me.savvy.rixa.modules.levels;
import lombok.Getter;
import lombok.Setter;
import me.savvy.rixa.Rixa;
import me.savvy.rixa.commands.handlers.RixaPermission;
import me.savvy.rixa.enums.Result;
import me.savvy.rixa.guild.RixaGuild;
import me.savvy.rixa.guild.user.UserData;
import me.savvy.rixa.modules.RixaModule;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
@ -20,6 +27,7 @@ public class LevelsModule implements RixaModule {
public LevelsModule(RixaGuild rixaGuild) {
this.rixaGuild = rixaGuild;
enabled = true;
load();
}
@Override
@ -52,4 +60,47 @@ public class LevelsModule implements RixaModule {
(getRixaGuild().getGuild().getJDA().getUserById(key),
getRixaGuild().getGuild());
}
private void load() {
if (!(checkExists())) {
this.enabled = true;
insert();
}
String query = "SELECT `levels` FROM `modules` WHERE `guild_id` = ?;";
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = Rixa.getDbManager().getConnection().prepareStatement(query);
ps.setString(1, getRixaGuild().getGuild().getId());
rs = Rixa.getDbManager().getObject(ps);
this.enabled = rs.getBoolean("levels");
ps.close();
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
private boolean checkExists() {
String query = "SELECT `%s` FROM `%s` WHERE `%s` = '%s';";
Result r = Result.ERROR;
try {
r = Rixa.getDbManager().checkExists(String.format
(query, "guild_id", "modules", "guild_id", rixaGuild.getGuild().getId()));
} catch (SQLException e) {
e.printStackTrace();
}
return r == Result.TRUE;
}
private void insert() {
String query = "INSERT INTO `%s` (`%s`) VALUES ('%s');";
Rixa.getDbManager()
.insert(String.format(query, "modules", "guild_id", rixaGuild.getGuild().getId()));
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
Rixa.getData().update("modules", "enabled", "guild_id", enabled, rixaGuild.getGuild().getId());
}
}

View File

@ -27,7 +27,7 @@ public class MusicModule implements RixaModule {
this.guild = guild;
this.enabled = false;
this.musicRole = "default_value";
db = Rixa.getInstance().getDbManager();
db = Rixa.getDbManager();
load();
}
@ -61,7 +61,7 @@ public class MusicModule implements RixaModule {
public Result setEnabled(boolean val) {
this.enabled = val;
return Rixa.getInstance().getData().update("music", "enabled", "guild_id", val, guild.getId());
return Rixa.getData().update("music", "enabled", "guild_id", val, guild.getId());
}
public boolean isRoleRequired() {
@ -71,12 +71,17 @@ public class MusicModule implements RixaModule {
public Result setRole(String newRole) {
this.musicRole = newRole;
return Rixa.getInstance().getData().update("music", "music_role", "guild_id", newRole, guild.getId());
return Rixa.getData().update("music", "music_role", "guild_id", newRole, guild.getId());
}
public boolean checkExists() {
Result r = Rixa.getInstance().getDbManager().checkExists("SELECT `guild_id` FROM `music` WHERE `guild_id` = '" +
guild.getId() + "';");
Result r = Result.ERROR;
try {
r = Rixa.getDbManager().checkExists("SELECT `guild_id` FROM `music` WHERE `guild_id` = '" +
guild.getId() + "';");
} catch (SQLException e) {
e.printStackTrace();
}
return r == Result.TRUE;
}
}

View File

@ -7,5 +7,5 @@ import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent;
*/
public interface React {
public void reactionTrigger(MessageReactionAddEvent event);
void reactionTrigger(MessageReactionAddEvent event);
}

View File

@ -15,7 +15,6 @@ public class YoutubeSearch {
private static final String API_KEY;
private JSONArray items;
private final String YOUTUBE_WATCH_BASE_URL = "https://www.youtube.com/watch?v=";
static {
API_KEY = "AIzaSyD1wjRGbzKgvjqAU25pREy1dVio9WpcuS0";
@ -83,6 +82,7 @@ public class YoutubeSearch {
}
public String getUrl(int index) {
String YOUTUBE_WATCH_BASE_URL = "https://www.youtube.com/watch?v=";
return YOUTUBE_WATCH_BASE_URL + getVideoId(index);
}