Added RaidMode

This commit is contained in:
Savvy 2017-09-06 16:02:07 -07:00
parent 37b012ffe1
commit 9b8b2f9a92
41 changed files with 883 additions and 587 deletions

View File

@ -1,11 +1,9 @@
<component name="libraryTable">
<library name="Gradle: com.fasterxml.jackson.core:jackson-annotations:2.8.0">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.8.0/45b426f7796b741035581a176744d91090e2e6fb/jackson-annotations-2.8.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.8.0/jackson-annotations-2.8.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.8.0/29a1a95363d497e856c0a7d682e4f7973e334068/jackson-annotations-2.8.0-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -1,11 +1,9 @@
<component name="libraryTable">
<library name="Gradle: com.fasterxml.jackson.core:jackson-core:2.8.5">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.8.5/60d059f5d2930ccd1ef03535b713fd9f933d1ba7/jackson-core-2.8.5.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.8.5/jackson-core-2.8.5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.8.5/14b04ebe5d1d9b54b793f84245d983b4c329634d/jackson-core-2.8.5-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -1,11 +1,9 @@
<component name="libraryTable">
<library name="Gradle: com.fasterxml.jackson.core:jackson-databind:2.8.5">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.8.5/b3035f37e674c04dafe36a660c3815cc59f764e2/jackson-databind-2.8.5.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.8.5/jackson-databind-2.8.5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.8.5/b658c4640ee224391e699ebaea4a3eb1c2ea8239/jackson-databind-2.8.5-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -1,11 +1,9 @@
<component name="libraryTable">
<library name="Gradle: com.sedmelluq:lavaplayer-common:1.0.5">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.sedmelluq/lavaplayer-common/1.0.5/4529d7855a9918dd2cfdef1a030bcf8abbf5bbae/lavaplayer-common-1.0.5.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/sedmelluq/lavaplayer-common/1.0.5/lavaplayer-common-1.0.5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.sedmelluq/lavaplayer-common/1.0.5/abbdf7e043ec24fa7151597d6a6cf44cc8934f71/lavaplayer-common-1.0.5-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -2,11 +2,8 @@
<library name="Gradle: commons-codec:commons-codec:1.9">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/commons-codec/commons-codec/1.9/commons-codec-1.9.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.9/9ce04e34240f674bc72680f8b843b1457383161a/commons-codec-1.9.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.9/3f15fff45d57656685abfee9e8302bf14580044c/commons-codec-1.9-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -2,11 +2,8 @@
<library name="Gradle: commons-logging:commons-logging:1.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.2/commons-logging-1.2.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/ecf26c7507d67782a3bbd148d170b31dfad001aa/commons-logging-1.2-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -2,8 +2,11 @@
<library name="Gradle: mysql:mysql-connector-java:5.1.38">
<CLASSES>
<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>
<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>
</component>

View File

@ -1,11 +1,9 @@
<component name="libraryTable">
<library name="Gradle: net.iharder:base64:2.3.9">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.iharder/base64/2.3.9/6c34d1c85141be8a21b0a957d84359894e2684b7/base64-2.3.9.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/net/iharder/base64/2.3.9/base64-2.3.9.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.iharder/base64/2.3.9/f7aa9fa9bdb0c9d6ade1586c979d631cf71e8645/base64-2.3.9-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -1,11 +1,9 @@
<component name="libraryTable">
<library name="Gradle: net.java.dev.jna:jna:4.4.0">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna/4.4.0/cb208278274bf12ebdb56c61bd7407e6f774d65a/jna-4.4.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/net/java/dev/jna/jna/4.4.0/jna-4.4.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna/4.4.0/9d45d3dc35711eef7267d8b4fc2c0dc482ef9fd2/jna-4.4.0-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -2,11 +2,8 @@
<library name="Gradle: net.sf.trove4j:trove4j:3.0.3">
<CLASSES>
<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>
<JAVADOC />
<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>
<SOURCES />
</library>
</component>

View File

@ -2,11 +2,8 @@
<library name="Gradle: org.apache.commons:commons-collections4:4.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-collections4/4.1/commons-collections4-4.1.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-collections4/4.1/a4cf4688fe1c7e3a63aa636cc96d013af537768e/commons-collections4-4.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-collections4/4.1/f305f3aa45a3b208c013ef92328f8f230329f20e/commons-collections4-4.1-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -2,11 +2,8 @@
<library name="Gradle: org.apache.httpcomponents:httpclient:4.5.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpclient/4.5.2/httpclient-4.5.2.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.5.2/733db77aa8d9b2d68015189df76ab06304406e50/httpclient-4.5.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.5.2/b9f9e3e5255b6ddc3bf21be05428c7a60d00e042/httpclient-4.5.2-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -2,11 +2,8 @@
<library name="Gradle: org.apache.httpcomponents:httpcore:4.4.4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpcore/4.4.4/httpcore-4.4.4.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.4/b31526a230871fbe285fbcbe2813f9c0839ae9b0/httpcore-4.4.4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.4/c5c19e3e6af6b452def290cde12a3ee4c35c893c/httpcore-4.4.4-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -2,11 +2,8 @@
<library name="Gradle: org.json:json:20160810">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/json/json/20160810/json-20160810.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.json/json/20160810/aca5eb39e2a12fddd6c472b240afe9ebea3a6733/json-20160810.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.json/json/20160810/92f4b89bc0bb4c7c3f7b52724568a901b7e0195b/json-20160810-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -1,11 +1,9 @@
<component name="libraryTable">
<library name="Gradle: org.jsoup:jsoup:1.10.1">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jsoup/jsoup/1.10.1/645f1ad2f6f4cbad1cde4c483eae71e4051be6ef/jsoup-1.10.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jsoup/jsoup/1.10.1/jsoup-1.10.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jsoup/jsoup/1.10.1/ce0ad15b1c229332bfa078f58a440403dd4a73e7/jsoup-1.10.1-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -1,11 +1,9 @@
<component name="libraryTable">
<library name="Gradle: org.slf4j:slf4j-api:1.7.22">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.22/a1c83373863cec7ae8d89dc1c5722d8cb6ec0309/slf4j-api-1.7.22.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.22/slf4j-api-1.7.22.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.22/2b9722cdf33bd0b1d1639a98034dde38b156ad34/slf4j-api-1.7.22-sources.jar!/" />
</SOURCES>
<SOURCES />
</library>
</component>

View File

@ -14,6 +14,7 @@
<orderEntry type="library" name="Gradle: com.sedmelluq:lavaplayer:1.2.42" level="project" />
<orderEntry type="library" name="Gradle: org.twitter4j:twitter4j-stream:4.0.6" level="project" />
<orderEntry type="library" name="Gradle: org.projectlombok:lombok:1.16.18" level="project" />
<orderEntry type="library" name="Gradle: ca.pjer:chatter-bot-api:1.4.7" level="project" />
<orderEntry type="library" name="Gradle: org.apache.commons:commons-lang3:3.5" level="project" />
<orderEntry type="library" name="Gradle: org.apache.commons:commons-collections4:4.1" level="project" />
<orderEntry type="library" name="Gradle: org.json:json:20160810" level="project" />

View File

@ -15,6 +15,7 @@
<orderEntry type="library" name="Gradle: com.sedmelluq:lavaplayer:1.2.42" level="project" />
<orderEntry type="library" name="Gradle: org.twitter4j:twitter4j-stream:4.0.6" level="project" />
<orderEntry type="library" name="Gradle: org.projectlombok:lombok:1.16.18" level="project" />
<orderEntry type="library" name="Gradle: ca.pjer:chatter-bot-api:1.4.7" level="project" />
<orderEntry type="library" name="Gradle: org.apache.commons:commons-lang3:3.5" level="project" />
<orderEntry type="library" name="Gradle: org.apache.commons:commons-collections4:4.1" level="project" />
<orderEntry type="library" name="Gradle: org.json:json:20160810" level="project" />

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,7 @@ dependencies {
compile 'org.twitter4j:twitter4j-core:4.0.3'
compile 'org.twitter4j:twitter4j-stream:4.0.6'
compile 'org.projectlombok:lombok:1.16.18'
compile 'ca.pjer:chatter-bot-api:1.4.7'
}
compileJava.options.encoding = 'UTF-8'

View File

@ -1,5 +1,9 @@
package me.savvy.rixa;
import com.google.code.chatterbotapi.ChatterBot;
import com.google.code.chatterbotapi.ChatterBotFactory;
import com.google.code.chatterbotapi.ChatterBotSession;
import com.google.code.chatterbotapi.ChatterBotType;
import lombok.Getter;
import lombok.Setter;
import me.savvy.rixa.commands.admin.*;
@ -9,6 +13,7 @@ import me.savvy.rixa.commands.handlers.CommandHandler;
import me.savvy.rixa.commands.mod.DeleteMessagesCommand;
import me.savvy.rixa.commands.mod.MuteCommand;
import me.savvy.rixa.commands.mod.PurgeMessagesCommand;
import me.savvy.rixa.commands.mod.RaidModeCommand;
import me.savvy.rixa.data.database.Data;
import me.savvy.rixa.data.database.DataType;
import me.savvy.rixa.data.database.sql.DatabaseManager;
@ -22,6 +27,7 @@ import me.savvy.rixa.modules.reactions.handlers.React;
import me.savvy.rixa.modules.reactions.handlers.ReactionManager;
import me.savvy.rixa.modules.reactions.react.ConfigReaction;
import me.savvy.rixa.modules.reactions.react.HelpReaction;
import me.savvy.rixa.modules.reactions.react.LeaderboardReaction;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
@ -36,6 +42,8 @@ import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.logging.Logger;
/**
@ -55,8 +63,13 @@ public class Rixa {
private static ConfigManager config;
@Getter @Setter
private static DatabaseManager dbManager;
private static ChatterBotFactory factory;
private static ChatterBotSession chatBotSession;
private static ChatterBot chatBot;
@Getter @Setter
private LanguageManager languageManager;
@Getter @Setter
private ScheduledExecutorService executorService;
// String search = event.getMessage().getContent().substring(event.getMessage().getContent().indexOf(" ") + 1);
public static void main(String[] args) {
instance = new Rixa();
@ -67,6 +80,7 @@ public class Rixa {
}
private static void load() {
getInstance().setExecutorService(Executors.newSingleThreadScheduledExecutor());
dbManager = new DatabaseManager(
String.valueOf(config.getJsonObject().getJSONObject("sql").getString("hostName")),
String.valueOf(config.getJsonObject().getJSONObject("sql").getString("portNumber")),
@ -104,9 +118,16 @@ public class Rixa {
new BatchMoveCommand(), new MuteCommand(), new MusicCommand(),
new ConfigCommand(), new UrbanDictionaryCommand(), new YoutubeCommand(),
new AddRoleCommand(), new RemoveRoleCommand(), new LevelsCommand(),
new LeaderboardCommand()});
register(new React[] {new HelpReaction(), new ConfigReaction() });
new LeaderboardCommand(), new RaidModeCommand()});
register(new React[] {new HelpReaction(), new ConfigReaction(), new LeaderboardReaction() });
data = new Data(DataType.SQL);
try {
factory = new ChatterBotFactory();
chatBot = factory.create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477");
chatBotSession = chatBot.createSession();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void register(CommandExec commandExecs[]) {
@ -121,6 +142,10 @@ public class Rixa {
}
}
public static ChatterBotSession getChatBotSession() {
return chatBotSession;
}
public Logger getLogger() {
return Logger.getLogger("Rixa");
}

View File

@ -190,6 +190,10 @@ public class ConfigCommand implements CommandExec {
} 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());
} else if (messages[2].equalsIgnoreCase("joinmessage")) {
RixaGuild.getGuild(event.getGuild()).getGuildSettings().setJoinMessageChannel("default_value");
} else if (messages[2].equalsIgnoreCase("quitmessage")) {
RixaGuild.getGuild(event.getGuild()).getGuildSettings().setQuitMessageChannel("default_value");
}
} else if (messages[1].equalsIgnoreCase("addperm") || messages[1].equalsIgnoreCase("addpermission") || messages[1].equalsIgnoreCase("aperm")) {
String permission = "notFound";

View File

@ -6,10 +6,14 @@ import me.savvy.rixa.commands.handlers.CommandExec;
import me.savvy.rixa.commands.handlers.CommandType;
import net.dv8tion.jda.core.EmbedBuilder;
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.Member;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.concurrent.TimeUnit;
@ -26,34 +30,67 @@ public class InfoCommand implements CommandExec {
usage = "%pinfo", mainCommand = "info")
public void execute(GuildMessageReceivedEvent event) {
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.getTimeUp());
Date date2 = new Date();
long difference = date2.getTime() - date1.getTime();
long seconds = difference / 1000;
int day = (int)TimeUnit.SECONDS.toDays(seconds);
long hours = TimeUnit.SECONDS.toHours(seconds) - (day *24);
long minute = TimeUnit.SECONDS.toMinutes(seconds) - (TimeUnit.SECONDS.toHours(seconds)* 60);
long second = TimeUnit.SECONDS.toSeconds(seconds) - (TimeUnit.SECONDS.toMinutes(seconds) *60);
int guildCount = 0;
int userCount = 0;
for(JDA jda: Rixa.getShardsList()) {
guildCount += jda.getGuilds().size();
userCount += jda.getUsers().size();
}
messageEmbed
.setTitle("Rixa Discord Bot", "http://rixa.io/")
.setDescription("Rixa is a user-friendly, multi-purpose bot currently in development which is capable of being customized to your Discord server needs. " +
"Rixa is complete with a dashboard, user profile, server statistics system, and many more features such as assigning roles on user join, music module, " +
"levels, and more. Rixa was created to bring ease and simplicity to managing Discord servers, and has since grown into much more than just a bot used for " +
"moderation.")
.addField("Created", event.getJDA().getSelfUser().getCreationTime().format(formatter), true)
.addField("Bot Uptime ", "Uptime: " + day + " days " + hours + " hours " + minute + " minutes " + second + " seconds.", true)
.addField("Total Guilds", String.valueOf(guildCount), true)
.addField("Total Users", String.valueOf(userCount), true)
.addField("Rixa Developer", botOwner.getName() + "#" + botOwner.getDiscriminator(), true)
.setFooter("Requested by " + event.getAuthor().getName() + "#" + event.getAuthor().getDiscriminator(), event.getAuthor().getAvatarUrl());
event.getChannel().sendMessage(messageEmbed.build()).queue();
String[] messages = event.getMessage().getContent().split(" ");
if(messages.length == 1) {
User botOwner = event.getJDA().getUserById("202944101333729280");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss");
Date date1 = new Date(Rixa.getTimeUp());
Date date2 = new Date();
long difference = date2.getTime() - date1.getTime();
long seconds = difference / 1000;
int day = (int) TimeUnit.SECONDS.toDays(seconds);
long hours = TimeUnit.SECONDS.toHours(seconds) - (day * 24);
long minute = TimeUnit.SECONDS.toMinutes(seconds) - (TimeUnit.SECONDS.toHours(seconds) * 60);
long second = TimeUnit.SECONDS.toSeconds(seconds) - (TimeUnit.SECONDS.toMinutes(seconds) * 60);
int guildCount = 0;
int userCount = 0;
for (JDA jda : Rixa.getShardsList()) {
guildCount += jda.getGuilds().size();
userCount += jda.getUsers().size();
}
messageEmbed
.setTitle("Rixa Discord Bot", "http://rixa.io/")
.setDescription("Rixa is a user-friendly, multi-purpose bot currently in development which is capable of being customized to your Discord server needs. " +
"Rixa is complete with a dashboard, user profile, server statistics system, and many more features such as assigning roles on user join, music module, " +
"levels, and more. Rixa was created to bring ease and simplicity to managing Discord servers, and has since grown into much more than just a bot used for " +
"moderation.")
.addField("Created", event.getJDA().getSelfUser().getCreationTime().format(formatter), true)
.addField("Bot Uptime ", "Uptime: " + day + " days " + hours + " hours " + minute + " minutes " + second + " seconds.", true)
.addField("Total Guilds", String.valueOf(guildCount), true)
.addField("Total Users", String.valueOf(userCount), true)
.addField("Rixa Developer", botOwner.getName() + "#" + botOwner.getDiscriminator(), true)
.setFooter("Requested by " + event.getAuthor().getName() + "#" + event.getAuthor().getDiscriminator(), event.getAuthor().getAvatarUrl());
event.getChannel().sendMessage(messageEmbed.build()).queue();
} else if(messages.length >= 2) {
if(event.getMessage().getMentionedUsers().size() != 1) {
return;
}
User user = event.getMessage().getMentionedUsers().get(0);
Member member = event.getGuild().getMember(user);
OffsetDateTime time = user.getCreationTime();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM/dd/yyyy HH:mm:ss");
EmbedBuilder eb = new EmbedBuilder();
if(member.getGame() != null) {
eb.setDescription("Playing **" + member.getGame().getName() + "**");
}
eb.setAuthor("User Information: " + user.getName(), null, user.getAvatarUrl());
eb.setColor(member.getColor());
eb.setThumbnail(user.getAvatarUrl());
eb.addField("User", user.getAsMention(), true)
.addField("ID", user.getId(), true)
.addField("Roles", String.valueOf(member.getRoles().size()), true)
.addField("Status", member.getOnlineStatus().name(), true)
.addField("Mutual Guilds", String.valueOf(user.getMutualGuilds().size()), true);
if(member.getNickname() != null) {
eb.addField("Nickname", member.getNickname(), true);
}
eb.addField("Created", time.format(formatter), true)
.addField("Joined", member.getJoinDate().format(formatter), true);
MessageEmbed embed = eb.build();
event.getChannel().sendMessage(embed).complete();
}
}
}

View File

@ -23,7 +23,7 @@ public class LeaderboardCommand implements CommandExec {
}
Message message = event.getChannel().sendMessage
(rixaGuild.getLevelsModule().leaderboard
(event.getMember(), 0).getBuilder().build()).complete();
(event.getMember(), 1).getBuilder().build()).complete();
message.addReaction("\u2B05").complete();
message.addReaction("\u27A1").complete();
}

View File

@ -3,18 +3,16 @@ package me.savvy.rixa.commands.general;
import me.savvy.rixa.Rixa;
import me.savvy.rixa.commands.handlers.Command;
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.user.UserData;
import me.savvy.rixa.utils.MessageBuilder;
import me.savvy.rixa.utils.YoutubeSearch;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
/**
* Created by savit on 7/11/2017.
@ -31,8 +29,26 @@ public class LevelsCommand implements CommandExec {
new MessageBuilder("Levels are not enabled on this server!").setColor(event.getMember().getColor()).queue(event.getChannel());
return;
}
UserData data = rixaGuild.getLevelsModule().getUserData(event.getAuthor().getId());
String query = "SELECT * FROM `levels` WHERE `guild_id` = '" + event.getGuild().getId() + "' ORDER BY `experience` DESC";
if (event.getMessage().getContent().split(" ").length == 2) {
if(event.getMessage().getMentionedUsers().size() < 1) {
new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + rixaGuild.getGuildSettings().getPrefix() + "rank <user>].").setColor(event.getMember().getColor()).queue(event.getChannel());
return;
}
if (event.getGuild().getMember(event.getMessage().getMentionedUsers().get(0)) == null) {
new MessageBuilder(event.getMember().getAsMention() + ", couldn't find user.").setColor(event.getMember().getColor()).queue(event.getChannel());
return;
}
getInfo(rixaGuild, event.getGuild().getMember(event.getMessage().getMentionedUsers().get(0))).queue(event.getChannel());
return;
}
getInfo(rixaGuild, event.getMember()).queue(event.getChannel());
}
public MessageBuilder getInfo(RixaGuild rixaGuild, Member member) {
User author = member.getUser();
UserData data = rixaGuild.getLevelsModule().getUserData(author.getId());
String query = "SELECT * FROM `levels` WHERE `guild_id` = '" + rixaGuild.getGuild().getId() + "' ORDER BY `experience` DESC";
ResultSet rs = Rixa.getDbManager().executeQuery(query);
int rowNumber = 0;
String rank = "Not found.";
@ -40,7 +56,7 @@ public class LevelsCommand implements CommandExec {
rs.beforeFirst();
while (rs.next()) {
rowNumber++;
if (rs.getString("user_id").equalsIgnoreCase(event.getAuthor().getId())) {
if (rs.getString("user_id").equalsIgnoreCase(author.getId())) {
rank = String.valueOf(rowNumber);
break;
}
@ -49,16 +65,15 @@ public class LevelsCommand implements CommandExec {
} catch(SQLException ignored) {
ignored.printStackTrace();
}
new MessageBuilder()
.setAuthor(event.getAuthor().getName(), event.getAuthor().getEffectiveAvatarUrl(), event.getAuthor().getEffectiveAvatarUrl())
.setTitle(event.getAuthor().getName() + "'s level")
.setColor(event.getMember().getColor())
return new MessageBuilder()
.setAuthor(author.getName(), author.getEffectiveAvatarUrl(), author.getEffectiveAvatarUrl())
.setTitle(author.getName() + "'s level")
.setColor(member.getColor())
.addField("Rank", rank, true)
.addField("Level", String.valueOf(data.getLevel()), true)
.addField("Exp Needed",
data.getRemainingExperience() + "/" + data.getNeededXP
(data.getLevelFromExperience(data.getExperience())).intValue(), false)
.addField("Total Exp", String.valueOf(data.getExperience()), false)
.queue(event.getChannel());
.addField("Total Exp", String.valueOf(data.getExperience()), true);
}
}

View File

@ -24,6 +24,7 @@ import me.savvy.rixa.modules.music.MusicManager;
import me.savvy.rixa.modules.music.TrackScheduler;
import me.savvy.rixa.utils.MessageBuilder;
import me.savvy.rixa.utils.YoutubeSearch;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.*;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
@ -90,7 +91,7 @@ public class MusicCommand implements CommandExec {
TrackScheduler scheduler = mng.scheduler;
// music join <channel>
if(message.length == 1) {
sendHelp();
sendHelp(event.getGuild().getId(), rixaGuild.getGuildSettings().getPrefix(), event.getAuthor(), event.getChannel());
} else if (message.length == 2) {
if(message[1].equalsIgnoreCase("join") || message[1].equalsIgnoreCase("summon") ) {
if (event.getMember().getVoiceState().getChannel() == null) {
@ -104,7 +105,20 @@ public class MusicCommand implements CommandExec {
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("play")) {
} else if (message[1].equalsIgnoreCase("reset")) {
synchronized (musicManagers) {
scheduler.queue.clear();
player.destroy();
guild.getAudioManager().setSendingHandler(null);
musicManagers.remove(guild.getId());
}
mng = getMusicManager(guild);
guild.getAudioManager().setSendingHandler(mng.sendHandler);
new MessageBuilder("The player has been completely reset!").setColor(event.getMember().getColor()).queue(event.getChannel());
} else if (message[1].equalsIgnoreCase("skip")) {
scheduler.nextTrack();
new MessageBuilder("Successfully skipped current track.").setColor(event.getMember().getColor()).queue(event.getChannel());
} else if(message[1].equalsIgnoreCase("play") || message[1].equalsIgnoreCase("resume")) {
if (player.isPaused()) {
player.setPaused(false);
new MessageBuilder("MusicPlayer resumed track: " + player.getPlayingTrack().getInfo().title).setColor(event.getMember().getColor()).queue(event.getChannel());
@ -119,7 +133,7 @@ public class MusicCommand implements CommandExec {
if(track != null) {
desc += "Track skipped. ";
}
new MessageBuilder(desc + " Leaving voice channel...").setColor(event.getMember().getColor()).queue(event.getChannel());
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")) {
@ -162,17 +176,6 @@ public class MusicCommand implements CommandExec {
} else if(message[1].equalsIgnoreCase("repeat")) {
scheduler.setRepeating(!scheduler.isRepeating());
new MessageBuilder("Repeat on music play has been " + (scheduler.isRepeating() ? "enabled" : "disabled")).setColor(event.getMember().getColor()).queue(event.getChannel());
} else if(message[1].equalsIgnoreCase("restart")) {
synchronized (musicManagers) {
scheduler.queue.clear();
player.destroy();
guild.getAudioManager().setSendingHandler(null);
musicManagers.remove(guild.getId());
}
mng = getMusicManager(guild);
guild.getAudioManager().setSendingHandler(mng.sendHandler);
new MessageBuilder("The music player has been reset!").setColor(event.getMember().getColor()).queue(event.getChannel());
} else if(message[1].equalsIgnoreCase("np") || message[1].equalsIgnoreCase("nowplaying")) {
AudioTrack currentTrack = player.getPlayingTrack();
if (currentTrack != null) {
@ -183,7 +186,7 @@ public class MusicCommand implements CommandExec {
} else {
new MessageBuilder("The music player is not playing anything!").setColor(event.getMember().getColor()).queue(event.getChannel());
}
} else if(message[1].equalsIgnoreCase("list")) {
} else if(message[1].equalsIgnoreCase("list") || message[1].equalsIgnoreCase("queue") || message[1].equalsIgnoreCase("q")) {
Queue<AudioTrack> queue = scheduler.queue;
synchronized (queue) {
if (queue.isEmpty()) {
@ -212,6 +215,8 @@ public class MusicCommand implements CommandExec {
}
scheduler.shuffle();
new MessageBuilder("The queue has been shuffled!").setColor(event.getMember().getColor()).queue(event.getChannel());
} else {
sendHelp(event.getGuild().getId(), rixaGuild.getGuildSettings().getPrefix(), event.getAuthor(), event.getChannel());
}
} else if (message.length == 3) {
if(message[1].equalsIgnoreCase("join")) {
@ -241,14 +246,16 @@ public class MusicCommand implements CommandExec {
}
}
}
} else if(message[1].equalsIgnoreCase("play") || message[1].equalsIgnoreCase("playlist")) {
} else if(message[1].equalsIgnoreCase("play") || message[1].equalsIgnoreCase("playlist") || message[1].equalsIgnoreCase("pplay")) {
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);
loadAndPlay(mng, event.getChannel(), message[2], (message[2].toLowerCase().contains("playlist")
|| message[1].equalsIgnoreCase("playlist")
|| message[1].equalsIgnoreCase("pplay")));
} 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());
@ -263,6 +270,8 @@ public class MusicCommand implements CommandExec {
} catch (NumberFormatException e) {
new MessageBuilder(message[2] + " is not a valid integer. Try a number between 10 and 100.").setColor(event.getMember().getColor()).queue(event.getChannel());
}
} else {
sendHelp(event.getGuild().getId(), rixaGuild.getGuildSettings().getPrefix(), event.getAuthor(), event.getChannel());
}
} // music youtube <query
else if(message.length >= 3) {
@ -302,7 +311,11 @@ public class MusicCommand implements CommandExec {
} catch (IOException e) {
e.printStackTrace();
}
} else {
sendHelp(event.getGuild().getId(), rixaGuild.getGuildSettings().getPrefix(), event.getAuthor(), event.getChannel());
}
} else {
sendHelp(event.getGuild().getId(), rixaGuild.getGuildSettings().getPrefix(), event.getAuthor(), event.getChannel());
}
}
@ -375,9 +388,6 @@ public class MusicCommand implements CommandExec {
return String.format("%02d:%02d", minutes, seconds);
}
private void sendHelp() {
}
private String getMessage(String[] messages, int argToBegin) {
StringBuilder builder = new StringBuilder();
for(int i = argToBegin; i < messages.length; i++) {
@ -385,4 +395,33 @@ public class MusicCommand implements CommandExec {
}
return builder.toString().trim();
}
private void sendHelp(String title, String prefix, User user, TextChannel textChannel) {
EmbedBuilder embedBuilder = new EmbedBuilder();
String stringBuilder = "\u2753" +
" **Music Commands Help**" +
"\n" +
"Click a number below for information about other commands.";
embedBuilder.setTitle(String.format("Help: %s", title));
embedBuilder.setDescription(stringBuilder);
embedBuilder.addField(prefix + "music join [name]", "Joins a voice channel that has the provided name", false)
.addField(prefix + "music join [id]", "Joins a voice channel based on the provided id.", false)
.addField(prefix + "music leave", "Leaves the voice channel that the bot is currently in.", false)
.addField(prefix + "music play", "Plays songs from the current queue. Starts playing again if it was previously paused", false)
.addField(prefix + "music play [url]", "Adds a new song to the queue and starts playing if it wasn't playing already", false)
.addField(prefix + "music playlist", "Adds a playlist to the queue and starts playing if not already playing", false)
.addField(prefix + "music pause", "Pauses audio playback", false)
.addField(prefix + "music stop", "Completely stops audio playback, skipping the current song.", false)
.addField(prefix + "music skip", "Skips the current song, automatically starting the next", false)
.addField(prefix + "music nowplaying", "Prints information about the currently playing song (title, current time)", false)
.addField(prefix + "music np", "Alias for nowplaying", false)
.addField(prefix + "music list", "Lists the songs in the queue", false)
.addField(prefix + "music volume [vol]", "Sets the volume of the MusicPlayer [10 - 100]", false)
.addField(prefix + "music restart", "Restarts the current song or restarts the previous song if there is no current song playing.", false)
.addField(prefix + "music repeat", "Makes the player repeat the currently playing song", false)
.addField(prefix + "music reset", "Completely resets the player, fixing all errors and clearing the queue.", false)
.addField(prefix + "music shuffle", "Shuffle current music queue.", false);
user.openPrivateChannel().complete().sendMessage(embedBuilder.build()).queue();
new MessageBuilder(user.getAsMention() + ", help menu delivered in private messages.").setColor(Color.decode("#4CC276")).queue(textChannel);
}
}

View File

@ -23,30 +23,32 @@ public class CommandHandler {
public static boolean hasCommand(String s) {
if(getCommands().containsKey(s)) {
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;
}
}
return false;
}
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;
}
}
return false;
}
public static CommandRegistrar get(String s) {
if(getCommands().containsKey(s)) {
return getCommands().get(s);
} else {
for (CommandRegistrar commandRegistrar : getCommands().values()) {
for (String string : commandRegistrar.getAnnotation().aliases()) {
if (string.equalsIgnoreCase(s)) return commandRegistrar;
}
}
return null;
}
for (CommandRegistrar commandRegistrar : getCommands().values()) {
if (commandRegistrar.getAnnotation().mainCommand().equalsIgnoreCase(s)) {
return commandRegistrar;
}
for (String string : commandRegistrar.getAnnotation().aliases()) {
if (string.equalsIgnoreCase(s)) return commandRegistrar;
}
}
return null;
}
public static Map<String, CommandRegistrar> getCommands() {

View File

@ -5,6 +5,6 @@ package me.savvy.rixa.commands.handlers;
*/
public enum RixaPermission {
MUTE, ADD_ROLE, REMOVE_ROLE, CLEAR_CHAT, ACCESS_CONFIG, PM_MESSAGE, KICK_MEMBER, BAN_MEMBER, BATCH_MOVE
MUTE, ADD_ROLE, REMOVE_ROLE, CLEAR_CHAT, ACCESS_CONFIG, PM_MESSAGE, KICK_MEMBER, BAN_MEMBER, BATCH_MOVE, TOGGLE_RAIDMODE
}

View File

@ -0,0 +1,35 @@
package me.savvy.rixa.commands.mod;
import me.savvy.rixa.commands.handlers.Command;
import me.savvy.rixa.commands.handlers.CommandExec;
import me.savvy.rixa.commands.handlers.RixaPermission;
import me.savvy.rixa.guild.RixaGuild;
import me.savvy.rixa.utils.MessageBuilder;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
/**
* Created by Timber on 5/23/2017.
*/
public class RaidModeCommand implements CommandExec {
@Override
@Command(mainCommand = "toggleraidmode",
description = "Toggle Raid Mode!",
channelType = ChannelType.TEXT,
aliases = {"raidmode", "trm", "toggleraid"})
public void execute(GuildMessageReceivedEvent event) {
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
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());
return;
}
if (!(rixaGuild.getGuildSettings().isRaidMode())) {
rixaGuild.getGuildSettings().startRaidMode();
new MessageBuilder(event.getMember().getAsMention() + ", successfully turned raid mode on").setColor(event.getMember().getColor()).queue(event.getChannel());
return;
}
rixaGuild.getGuildSettings().endRaidMode();
new MessageBuilder(event.getMember().getAsMention() + ", successfully turned raid mode off.").setColor(event.getMember().getColor()).queue(event.getChannel());
}
}

View File

@ -2,6 +2,7 @@ package me.savvy.rixa.events;
import me.savvy.rixa.guild.RixaGuild;
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.Role;
import net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent;
@ -22,6 +23,14 @@ public class MemberEvent {
@SubscribeEvent
public void onMember(GuildMemberJoinEvent event) {
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
/* if (rixaGuild.getGuildSettings().isRaidMode()) {
if(event.getGuild().getSelfMember().hasPermission(Permission.KICK_MEMBERS)) {
new MessageBuilder("Sorry " + event.getGuild().getName() + " currently has raid mode enabled. Please rejoin at a later time. Sorry!").send(event.getUser());
event.getGuild().getController().kick(event.getMember()).reason("Raid-Mode").queue();
}
return;
}*/
if(rixaGuild.getGuildSettings().getJoinMessageChannel() != null) {
try {
new MessageBuilder(rixaGuild.getGuildSettings().getJoinMessage()
@ -42,12 +51,14 @@ public class MemberEvent {
try {
Role role = event.getGuild().getRoleById(rixaGuild.getGuildSettings().getDefaultRole());
event.getGuild().getController().addRolesToMember(event.getMember(), Collections.singleton(role)).complete();
rixaGuild.getGuildSettings().setLastJoin(System.currentTimeMillis());
} catch(PermissionException ex) {
new MessageBuilder(String.format("I do not have permission for %s in %s", ex.getPermission().getName(), rixaGuild.getGuild().getName()))
.setColor(event.getMember().getColor()).send(rixaGuild.getGuild().getOwner().getUser());
return;
}
}
if(rixaGuild.getGuildSettings().getJoinPrivateMessage().equalsIgnoreCase("default")) {
return;
}

View File

@ -1,6 +1,8 @@
package me.savvy.rixa.events;
import com.google.code.chatterbotapi.ChatterBotFactory;
import com.mysql.jdbc.StringUtils;
import me.savvy.rixa.Rixa;
import me.savvy.rixa.commands.handlers.CommandHandler;
import me.savvy.rixa.commands.handlers.CommandRegistrar;
import me.savvy.rixa.guild.RixaGuild;
@ -12,6 +14,7 @@ import net.dv8tion.jda.core.entities.Invite;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.core.events.message.guild.react.GuildMessageReactionAddEvent;
import net.dv8tion.jda.core.events.message.priv.PrivateMessageReceivedEvent;
import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent;
import net.dv8tion.jda.core.exceptions.PermissionException;
@ -20,6 +23,7 @@ import net.dv8tion.jda.core.hooks.SubscribeEvent;
import java.awt.*;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
@ -37,6 +41,21 @@ public class MessageEvent {
public void handle(GuildMessageReceivedEvent event) {
if (event.getGuild() == null) return;
if (event.getAuthor().isBot()) return;
if (event.getMessage().getContent().startsWith
("@" + event.getGuild().getSelfMember().getEffectiveName())) {
try {
String s = event.getMessage().getContent().replace
("@" + event.getGuild().getSelfMember().getEffectiveName()+ " ", "");
if (s.isEmpty()) return;
s = Rixa.getChatBotSession().think(s);
if (s.isEmpty()) return;
event.getChannel().sendMessage(s).queue();
return;
} catch (Exception ex) { ex.printStackTrace(); }
}
RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild());
String prefix = rixaGuild
.getGuildSettings()
@ -60,7 +79,8 @@ public class MessageEvent {
String[] splitContent = event.getMessage().getContent().replace(prefix, "").split(" ");
if(!CommandHandler.hasCommand(splitContent[0])) {
return; }
return;
}
CommandRegistrar cmd = CommandHandler.get(splitContent[0]);
Method m = cmd.getMethod();
try {
@ -107,6 +127,7 @@ public class MessageEvent {
.getMember(event.getAuthor()), Collections.singleton(rixaGuild.getGuild().getRoleById(rixaGuild.getGuildSettings().getDefaultRole()))).complete();
new MessageBuilder(String.format("You have been promoted on %s!", rixaGuild.getGuild().getName()))
.setColor(rixaGuild.getGuild().getMember(event.getAuthor()).getColor()).send(event.getAuthor());
rixaGuild.getGuildSettings().setLastJoin(System.currentTimeMillis());
} catch(PermissionException ex) {
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());
@ -143,14 +164,36 @@ public class MessageEvent {
MessageEmbed embed = message.getEmbeds().get(0);
if(StringUtils.isNullOrEmpty(embed.getTitle())) return;
String[] titleSplit = embed.getTitle().split(": ");
if(ReactionManager.getReactions().containsKey(titleSplit[0])) {
ReactRegistrar reactRegistrar = ReactionManager.getReactions().get(titleSplit[0]);
Method m = reactRegistrar.getMethod();
try {
m.invoke(reactRegistrar.getExecutor(), event);
} catch (Exception e) {
e.printStackTrace();
}
}
if (titleSplit[0].equalsIgnoreCase("Leaderboard")) return;
if(!ReactionManager.getReactions().containsKey(titleSplit[0])) return;
ReactRegistrar reactRegistrar = ReactionManager.getReactions().get(titleSplit[0]);
Method m = reactRegistrar.getMethod();
try {
m.invoke(reactRegistrar.getExecutor(), event);
} catch (Exception e) {
e.printStackTrace();
}
}
@SubscribeEvent
public void onGuildReact(GuildMessageReactionAddEvent event) {
if (event.getGuild() == null) return;
if (event.getUser().isBot()) return;
Message message = event.getChannel().getMessageById(event.getMessageId()).complete();
if(message == null || message.getEmbeds().size() != 1) return;
MessageEmbed embed = message.getEmbeds().get(0);
if(StringUtils.isNullOrEmpty(embed.getTitle())) return;
String[] titleSplit = embed.getTitle().split(": ");
System.out.println(Arrays.toString(titleSplit));
if(ReactionManager.getReactions().containsKey(titleSplit[0])) {
ReactRegistrar reactRegistrar = ReactionManager.getReactions().get(titleSplit[0]);
Method m = reactRegistrar.getMethod();
try {
m.invoke(reactRegistrar.getExecutor(), event);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

View File

@ -1,6 +1,7 @@
package me.savvy.rixa.guild.management;
import lombok.Getter;
import lombok.Setter;
import me.savvy.rixa.Rixa;
import me.savvy.rixa.enums.Result;
import net.dv8tion.jda.core.entities.Guild;
@ -9,6 +10,9 @@ import net.dv8tion.jda.core.entities.TextChannel;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.TimerTask;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* Created by Timber on 5/23/2017.
@ -22,6 +26,9 @@ public class GuildSettings {
private String prefix = "/", defaultRole, muteRole, joinMessage, quitMessage, joinPrivateMessage, description;
@Getter
private TextChannel joinMessageChannel, quitMessageChannel;
@Getter @Setter Guild.VerificationLevel defaultVerificationLevel;
@Getter @Setter long lastJoin;
private boolean raidMode;
public GuildSettings(Guild guild) {
this.guild = guild;
@ -63,6 +70,7 @@ public class GuildSettings {
set = Rixa.getDbManager().getObject(ps);
this.description = (set.getString("description"));
this.enlisted = (set.getBoolean("enlisted"));
this.raidMode = false;
}
private boolean checkExists() {
@ -92,16 +100,26 @@ public class GuildSettings {
this.joinPrivateMessage = joinPrivateMessage;
Rixa.getData().update("settings", "joinPM", "guild_id", joinPrivateMessage, guild.getId());
}
public void setJoinMessageChannel(TextChannel joinMessageChannel) {
this.joinMessageChannel = joinMessageChannel;
Rixa.getData().update("settings", "greetings", "guild_id", joinMessageChannel.getId(), guild.getId());
}
public void setJoinMessageChannel(String joinMessageChannel) {
if (joinMessageChannel.equalsIgnoreCase("default_value"))this.joinMessageChannel = null;
Rixa.getData().update("settings", "greetings", "guild_id", joinMessageChannel, guild.getId());
}
public void setQuitMessageChannel(TextChannel quitMessageChannel) {
this.quitMessageChannel = quitMessageChannel;
Rixa.getData().update("settings", "farewell", "guild_id", quitMessageChannel.getId(), guild.getId());
}
public void setQuitMessageChannel(String quitMessageChannel) {
if (quitMessageChannel.equalsIgnoreCase("default_value"))this.quitMessageChannel = null;
Rixa.getData().update("settings", "greetings", "guild_id", quitMessageChannel, guild.getId());
}
public void setDefaultRole(String defaultRole) {
this.defaultRole = defaultRole;
@ -132,4 +150,34 @@ public class GuildSettings {
this.joinVerification = joinVerification;
Rixa.getData().update("settings", "joinVerification", "guild_id", joinVerification, guild.getId());
}
}
public void startRaidMode() {
this.raidMode = true;
setDefaultVerificationLevel(guild.getVerificationLevel());
guild.getManager().setVerificationLevel(Guild.VerificationLevel.HIGH).queue();
raidModeScheduler();
}
public void endRaidMode() {
this.raidMode = false;
guild.getManager().setVerificationLevel(getDefaultVerificationLevel()).queue();
setDefaultVerificationLevel(null);
}
public void raidModeScheduler() {
ScheduledExecutorService scheduler = Rixa.getInstance().getExecutorService();
scheduler.scheduleWithFixedDelay(new TimerTask() {
@Override
public void run() {
if (isRaidMode()) {
endRaidMode();
}
this.cancel();
}
}, 0, 5, TimeUnit.MINUTES);
}
public boolean isRaidMode() {
return raidMode;
}
}

View File

@ -43,8 +43,8 @@ public class UserData {
return;
}
String query = "SELECT * FROM `%s` WHERE `%s` = '%s' AND `%s` = '%s';";
PreparedStatement ps = null;
ResultSet rs = null;
PreparedStatement ps;
ResultSet rs;
try {
ps = Rixa.getDbManager().getConnection().prepareStatement(String.format
(query, "levels", "guild_id",
@ -107,7 +107,9 @@ public class UserData {
Result r;
try {
r = Rixa.getDbManager().checkExists(String.format
(query, "user_id", "levels", "guild_id", guild.getId(), "user_id", user.getId()));
(query, "user_id", "levels", "guild_id",
guild.getId(), "user_id",
user.getId()));
return r == Result.TRUE;
} catch (SQLException e) {
e.printStackTrace();
@ -118,7 +120,8 @@ public class UserData {
private void insert() {
String query = "INSERT INTO `%s` (`%s`,`%s`,`%s`) VALUES ('%s', '%s', '%s');";
Rixa.getDbManager()
.insert(String.format(query, "levels", "guild_id", "user_id", "experience", guild.getId(), user.getId(), 0));
.insert(String.format(query, "levels", "guild_id", "user_id", "experience",
guild.getId(), user.getId(), "0"));
}
private void setExperience(int experience) {

View File

@ -1,9 +1,8 @@
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.data.database.sql.DatabaseManager;
import me.savvy.rixa.enums.Result;
import me.savvy.rixa.guild.RixaGuild;
import me.savvy.rixa.guild.user.UserData;
@ -31,29 +30,57 @@ public class LevelsModule implements RixaModule {
load();
}
private List<UserData> leaderboard(Member member) {
DatabaseManager db = Rixa.getDbManager();
ResultSet rs = db.executeQuery(String.format
("SELECT * FROM `levels` WHERE `guild_id` = '%s' ORDER BY `experience` DESC;", member.getGuild().getId()));
List<UserData> userDataList = new LinkedList<>();
try {
while (rs.next()) {
if (member.getGuild().getMemberById(rs.getString("user_id")) == null) continue;
UserData userData = rixaGuild.getLevelsModule().getUserData(rs.getString("user_id"));
userDataList.add(userData);
}
rs.getStatement().close();
rs.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
return userDataList;
}
public MessageBuilder leaderboard(Member member, int page) {
int sizePerPage = 4;
int sizePerPage = 10;
if(page < 1) {
page = 1;
}
List<UserData> userData = leaderboard(member);
int maxPages = userData.size() / sizePerPage + (userData.size() % sizePerPage > 0 ? 1 : 0);
if(page < 0) {
page = 0;
if (page > maxPages) {
return null;
}
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);
/*int from = Math.max(0, page * sizePerPage);
int to = Math.min(userData.size(), (page + 2) * sizePerPage);*/
int start = Math.min(Math.max(sizePerPage * (page - 1), 0), userData.size());
int end = Math.min(Math.max(sizePerPage * page, start), userData.size());
List<UserData> userList = userData.subList(start, end);
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())
UserData user = userList.get(i);
if (user == null) continue;
stringBuilder
.append("`")
.append( i + start + 1/*(page > 1) ? ((i + 1) * 10) : i + 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());
builder.footer("Page: (" + page + " / " + maxPages + ")", member.getGuild().getIconUrl());
return builder.setColor(member.getColor()).setTitle(String.format("Leaderboard: %s", member.getGuild().getName()));
}

View File

@ -1,5 +1,6 @@
package me.savvy.rixa.modules.reactions.handlers;
import net.dv8tion.jda.core.events.message.guild.react.GuildMessageReactionAddEvent;
import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent;
/**
@ -8,4 +9,6 @@ import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent;
public interface React {
void reactionTrigger(MessageReactionAddEvent event);
default void reactionGuildTrigger(GuildMessageReactionAddEvent event) { }
}

View File

@ -85,7 +85,8 @@ public class HelpReaction implements React {
.addField(prefix + "music volume [vol]", "Sets the volume of the MusicPlayer [10 - 100]", false)
.addField(prefix + "music restart", "Restarts the current song or restarts the previous song if there is no current song playing.", false)
.addField(prefix + "music repeat", "Makes the player repeat the currently playing song", false)
.addField(prefix + "music reset", "Completely resets the player, fixing all errors and clearing the queue.", false);
.addField(prefix + "music reset", "Completely resets the player, fixing all errors and clearing the queue.", false)
.addField(prefix + "music shuffle", "Shuffle current music queue.", false);
message.editMessage(embedBuilder.build()).queue();
break;
}

View File

@ -0,0 +1,47 @@
package me.savvy.rixa.modules.reactions.react;
import me.savvy.rixa.guild.RixaGuild;
import me.savvy.rixa.modules.reactions.handlers.React;
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.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.react.MessageReactionAddEvent;
/**
* Created by Timber on 6/9/2017.
*/
public class LeaderboardReaction implements React {
@Override
public void reactionTrigger(MessageReactionAddEvent event) { }
@Override
@ReactHandle(title = "Leaderboard", description = "Leaderboard for levels")
public void reactionGuildTrigger(GuildMessageReactionAddEvent event) {
Message message = event.getChannel().getMessageById(event.getMessageId()).complete();
Guild guild = event.getGuild();
if(guild == null) {
return;
}
RixaGuild rixaGuild = RixaGuild.getGuild(guild);
int page = 500;
switch (event.getReaction().getEmote().getName()) {
case "\u2B05":// previous
page = Integer.parseInt(message.getEmbeds().get(0).getFooter().getText().split(" /")[0].replace("Page: (", "")) - 1;
break;
case "\u27A1":// next
page = Integer.parseInt(message.getEmbeds().get(0).getFooter().getText().split(" /")[0].replace("Page: (", "")) + 1;
break;
}
if(page != 500) {
me.savvy.rixa.utils.MessageBuilder builder = rixaGuild.getLevelsModule().leaderboard
(event.getMember(), page);
if (builder == null) return;
message.editMessage(builder.getBuilder().build()).queue();
}
}
}