Merge remote-tracking branch 'origin/master'

This commit is contained in:
Venal 2017-08-15 00:01:48 -04:00
commit 65eb5ddcff
15 changed files with 422 additions and 969 deletions

View File

@ -2,11 +2,8 @@
<library name="Gradle: mysql:mysql-connector-java:5.1.38"> <library name="Gradle: mysql:mysql-connector-java:5.1.38">
<CLASSES> <CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/mysql/mysql-connector-java/5.1.38/dbbd7cd309ce167ec8367de4e41c63c2c8593cc5/mysql-connector-java-5.1.38.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES> <SOURCES />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/mysql/mysql-connector-java/5.1.38/b83cac8c938dfb9b7a8e191e2d482be88eb8280c/mysql-connector-java-5.1.38-sources.jar!/" />
</SOURCES>
</library> </library>
</component> </component>

View File

@ -2,8 +2,11 @@
<library name="Gradle: net.sf.trove4j:trove4j:3.0.3"> <library name="Gradle: net.sf.trove4j:trove4j:3.0.3">
<CLASSES> <CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/sf/trove4j/trove4j/3.0.3/trove4j-3.0.3.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/net/sf/trove4j/trove4j/3.0.3/trove4j-3.0.3.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.sf.trove4j/trove4j/3.0.3/42ccaf4761f0dfdfa805c9e340d99a755907e2dd/trove4j-3.0.3.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES /> <SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.sf.trove4j/trove4j/3.0.3/109c5be93362e6e651e417c51d1863477a22969c/trove4j-3.0.3-sources.jar!/" />
</SOURCES>
</library> </library>
</component> </component>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="Rixa:main" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="1.0" type="JAVA_MODULE" version="4"> <module external.linked.project.id="Rixa:main" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="1.0" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/../../build/classes/main" /> <output url="file://$MODULE_DIR$/../../out/production/classes" />
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$/../../src/main"> <content url="file://$MODULE_DIR$/../../src/main">
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="Rixa:test" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="1.0" type="JAVA_MODULE" version="4"> <module external.linked.project.id="Rixa:test" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="1.0" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output-test url="file://$MODULE_DIR$/../../build/classes/test" /> <output-test url="file://$MODULE_DIR$/../../out/test/classes" />
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$/../../src/test"> <content url="file://$MODULE_DIR$/../../src/test">
<sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" />

File diff suppressed because it is too large Load Diff

View File

@ -103,8 +103,9 @@ public class Rixa {
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(),
register(new React[] {new HelpReaction(), new ConfigReaction()}); new LeaderboardCommand()});
register(new React[] {new HelpReaction(), new ConfigReaction() });
data = new Data(DataType.SQL); data = new Data(DataType.SQL);
} }

View File

@ -0,0 +1,30 @@
package me.savvy.rixa.commands.general;
import me.savvy.rixa.commands.handlers.Command;
import me.savvy.rixa.commands.handlers.CommandExec;
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.Message;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
public class LeaderboardCommand implements CommandExec {
@Override
@Command(mainCommand = "leaderboard",
description = "Check your ping!",
aliases = {"leaderboards", "levels"},
channelType = ChannelType.TEXT)
public void execute(GuildMessageReceivedEvent event) {
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
if (!rixaGuild.getLevelsModule().isEnabled()) {
new MessageBuilder("Levels are not enabled on this server!").setColor(event.getMember().getColor()).queue(event.getChannel());
return;
}
Message message = event.getChannel().sendMessage
(rixaGuild.getLevelsModule().leaderboard
(event.getMember(), 0).getBuilder().build()).complete();
message.addReaction("\u2B05").complete();
message.addReaction("\u27A1").complete();
}
}

View File

@ -1,7 +1,9 @@
package me.savvy.rixa.commands.general; package me.savvy.rixa.commands.general;
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.RixaPermission;
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.utils.MessageBuilder; import me.savvy.rixa.utils.MessageBuilder;
@ -10,6 +12,8 @@ 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.io.IOException; import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*; import java.util.*;
/** /**
@ -23,21 +27,33 @@ public class LevelsCommand implements CommandExec {
channelType = ChannelType.TEXT) channelType = ChannelType.TEXT)
public void execute(GuildMessageReceivedEvent event) { public void execute(GuildMessageReceivedEvent event) {
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild()); RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
if(!rixaGuild.getLevelsModule().isEnabled()) { if (!rixaGuild.getLevelsModule().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;
} }
UserData data = rixaGuild.getLevelsModule().getUserData(event.getAuthor().getId()); UserData data = rixaGuild.getLevelsModule().getUserData(event.getAuthor().getId());
// Map<UserData, Integer> newMap = new HashMap<>(); String query = "SELECT * FROM `levels` WHERE `guild_id` = '" + event.getGuild().getId() + "' ORDER BY `experience` DESC";
// rixaGuild.getLevelsModule().getUserData().forEach((s, userData) -> { ResultSet rs = Rixa.getDbManager().executeQuery(query);
// newMap.put(userData, userData.getExperience()); int rowNumber = 0;
// }); String rank = "Not found.";
// sortHashMapByValues(newMap); try {
rs.beforeFirst();
while (rs.next()) {
rowNumber++;
if (rs.getString("user_id").equalsIgnoreCase(event.getAuthor().getId())) {
rank = String.valueOf(rowNumber);
break;
}
}
rs.close();
} catch(SQLException ignored) {
ignored.printStackTrace();
}
new MessageBuilder() new MessageBuilder()
.setAuthor(event.getAuthor().getName(), event.getAuthor().getEffectiveAvatarUrl(), event.getAuthor().getEffectiveAvatarUrl()) .setAuthor(event.getAuthor().getName(), event.getAuthor().getEffectiveAvatarUrl(), event.getAuthor().getEffectiveAvatarUrl())
.setTitle(event.getAuthor().getName() + "'s level") .setTitle(event.getAuthor().getName() + "'s level")
.setColor(event.getMember().getColor()) .setColor(event.getMember().getColor())
.addField("Rank", "0", true) .addField("Rank", rank, true)
.addField("Level", String.valueOf(data.getLevel()), true) .addField("Level", String.valueOf(data.getLevel()), true)
.addField("Exp Needed", .addField("Exp Needed",
data.getRemainingExperience() + "/" + data.getNeededXP data.getRemainingExperience() + "/" + data.getNeededXP
@ -45,32 +61,4 @@ public class LevelsCommand implements CommandExec {
.addField("Total Exp", String.valueOf(data.getExperience()), false) .addField("Total Exp", String.valueOf(data.getExperience()), false)
.queue(event.getChannel()); .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

@ -12,6 +12,7 @@ import java.time.temporal.ChronoUnit;
* Created by Timber on 5/23/2017. * Created by Timber on 5/23/2017.
*/ */
public class PingCommand implements CommandExec { public class PingCommand implements CommandExec {
@Override @Override
@Command(mainCommand = "ping", @Command(mainCommand = "ping",
description = "Check your ping!", description = "Check your ping!",

View File

@ -92,6 +92,8 @@ public class RixaGuild {
("SELECT `" + permission.toString().toUpperCase() + "` FROM `permissions` WHERE `role_id` = ?"); ("SELECT `" + permission.toString().toUpperCase() + "` FROM `permissions` WHERE `role_id` = ?");
ps.setString(1, role.getId()); ps.setString(1, role.getId());
ResultSet rs = db.getObject(ps); ResultSet rs = db.getObject(ps);
ps.close();
rs.close();
return rs.getBoolean(permission.toString().toUpperCase()); return rs.getBoolean(permission.toString().toUpperCase());
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -8,12 +8,13 @@ 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;
import me.savvy.rixa.utils.MessageBuilder;
import net.dv8tion.jda.core.entities.Member;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.*;
import java.util.Map;
/** /**
* Created by Timber on 5/23/2017. * Created by Timber on 5/23/2017.
@ -30,6 +31,32 @@ public class LevelsModule implements RixaModule {
load(); load();
} }
public MessageBuilder leaderboard(Member member, int page) {
int sizePerPage = 4;
int maxPages = userData.size() / sizePerPage + (userData.size() % sizePerPage > 0 ? 1 : 0);
if(page < 0) {
page = 0;
}
if(page > maxPages - 2) {
page = maxPages - 3;
}
int from = Math.max(0, page * sizePerPage);
int to = Math.min(userData.size(), (page + 2) * sizePerPage);
List<UserData> userList = new ArrayList<>(userData.values()).subList(from, to);
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < userList.size(); i++) {
UserData user = userData.get(i);
stringBuilder.append(i)
.append(1).append(" ").append(user.getUser().getName())
.append("#").append(user.getUser().getDiscriminator())
.append(" (Lvl. ").append(user.getLevel()).append(")")
.append("\n");
}
MessageBuilder builder = new MessageBuilder(stringBuilder.toString());
builder.footer("Page: (" + page + " / " + (maxPages - 2) + ")", member.getGuild().getIconUrl());
return builder.setColor(member.getColor()).setTitle(String.format("Leaderboard: %s", member.getGuild().getName()));
}
@Override @Override
public String getName() { public String getName() {
return "Levels"; return "Levels";
@ -101,6 +128,6 @@ public class LevelsModule implements RixaModule {
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
this.enabled = enabled; this.enabled = enabled;
Rixa.getData().update("modules", "enabled", "guild_id", enabled, rixaGuild.getGuild().getId()); Rixa.getData().update("modules", "levels", "guild_id", enabled, rixaGuild.getGuild().getId());
} }
} }