Added Music, Permissions, MuteCommand, Configuration Command and more!
This commit is contained in:
parent
6bbc3f80a3
commit
e5c86f1a7f
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,11 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: com.mashape.unirest:unirest-java:1.4.9">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.mashape.unirest/unirest-java/1.4.9/778cffcba803dc7d43932266aef4c91f5b6b4dd0/unirest-java-1.4.9.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/com/mashape/unirest/unirest-java/1.4.9/unirest-java-1.4.9.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.mashape.unirest/unirest-java/1.4.9/fc3504b646ef187849da8caa2e4e9c1b962b5caf/unirest-java-1.4.9-sources.jar!/" />
|
||||
</SOURCES>
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
@ -1,11 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: commons-codec:commons-codec:1.9">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.9/9ce04e34240f674bc72680f8b843b1457383161a/commons-codec-1.9.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/commons-codec/commons-codec/1.9/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>
|
@ -1,11 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: commons-logging:commons-logging:1.2">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.2/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>
|
@ -1,11 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: mysql:mysql-connector-java:5.1.38">
|
||||
<CLASSES>
|
||||
<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!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<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>
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
@ -1,11 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: net.dv8tion:JDA:3.1.0_204">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.dv8tion/JDA/3.1.0_204/83ac4888994b40f8348cec788eb2df41d47595a4/JDA-3.1.0_204.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.dv8tion/JDA/3.1.0_204/5ed099d94a78d6c02a389bad2e37d2765e76c447/JDA-3.1.0_204-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -1,11 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: org.apache.commons:commons-collections4:4.1">
|
||||
<CLASSES>
|
||||
<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!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-collections4/4.1/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>
|
@ -1,11 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: org.apache.commons:commons-lang3:3.5">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.5/6c6c702c89bfff3cd9e80b04d668c5e190d588c6/commons-lang3-3.5.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.5/f7d878153e86a1cdddf6b37850e00a9f8bff726f/commons-lang3-3.5-sources.jar!/" />
|
||||
</SOURCES>
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
@ -1,11 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: org.apache.httpcomponents:httpasyncclient:4.1.1">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpasyncclient/4.1.1/dd624f5a0ff43eb5cdf828d9739d3177ee00a5a9/httpasyncclient-4.1.1.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpasyncclient/4.1.1/httpasyncclient-4.1.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpasyncclient/4.1.1/548f9cae59a0d01571ac39f714f19682cb68c481/httpasyncclient-4.1.1-sources.jar!/" />
|
||||
</SOURCES>
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
@ -1,11 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: org.apache.httpcomponents:httpclient:4.5.2">
|
||||
<CLASSES>
|
||||
<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!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpclient/4.5.2/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>
|
@ -1,11 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: org.apache.httpcomponents:httpcore:4.4.4">
|
||||
<CLASSES>
|
||||
<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!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpcore/4.4.4/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>
|
@ -1,11 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: org.apache.httpcomponents:httpcore-nio:4.4.4">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore-nio/4.4.4/16badfc2d99db264c486ba8c57ae577301a58bd9/httpcore-nio-4.4.4.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpcore-nio/4.4.4/httpcore-nio-4.4.4.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore-nio/4.4.4/816d16779b3058b1454908757fbc9ec8d233d7ba/httpcore-nio-4.4.4-sources.jar!/" />
|
||||
</SOURCES>
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
@ -1,11 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: org.apache.httpcomponents:httpmime:4.5.2">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.5.2/22b4c53dd9b6761024258de8f9240c3dce6ea368/httpmime-4.5.2.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpmime/4.5.2/httpmime-4.5.2.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.5.2/ca23fd61a082eab682fc0ffd29e37d09eab07180/httpmime-4.5.2-sources.jar!/" />
|
||||
</SOURCES>
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
@ -1,11 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: org.json:json:20160810">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.json/json/20160810/aca5eb39e2a12fddd6c472b240afe9ebea3a6733/json-20160810.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/json/json/20160810/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>
|
@ -9,9 +9,11 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Gradle: net.dv8tion:JDA:3.1.0_204" level="project" />
|
||||
<orderEntry type="library" name="Gradle: net.dv8tion:JDA:3.1.1_212" level="project" />
|
||||
<orderEntry type="library" name="Gradle: mysql:mysql-connector-java:5.1.38" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.sedmelluq:lavaplayer:1.2.39" level="project" />
|
||||
<orderEntry type="library" name="Gradle: edu.cmu.sphinx:sphinx4-core:5prealpha-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Gradle: edu.cmu.sphinx:sphinx4-data:5prealpha-SNAPSHOT" 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" />
|
||||
@ -27,6 +29,7 @@
|
||||
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-databind:2.8.5" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.jsoup:jsoup:1.10.1" level="project" />
|
||||
<orderEntry type="library" name="Gradle: net.iharder:base64:2.3.9" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.apache.commons:commons-math3:3.2" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.apache.httpcomponents:httpasyncclient:4.1.1" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.apache.httpcomponents:httpmime:4.5.2" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
|
||||
|
@ -10,9 +10,11 @@
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="Rixa_main" />
|
||||
<orderEntry type="library" name="Gradle: net.dv8tion:JDA:3.1.0_204" level="project" />
|
||||
<orderEntry type="library" name="Gradle: net.dv8tion:JDA:3.1.1_212" level="project" />
|
||||
<orderEntry type="library" name="Gradle: mysql:mysql-connector-java:5.1.38" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.sedmelluq:lavaplayer:1.2.39" level="project" />
|
||||
<orderEntry type="library" name="Gradle: edu.cmu.sphinx:sphinx4-core:5prealpha-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Gradle: edu.cmu.sphinx:sphinx4-data:5prealpha-SNAPSHOT" 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" />
|
||||
@ -28,6 +30,7 @@
|
||||
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-databind:2.8.5" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.jsoup:jsoup:1.10.1" level="project" />
|
||||
<orderEntry type="library" name="Gradle: net.iharder:base64:2.3.9" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.apache.commons:commons-math3:3.2" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.apache.httpcomponents:httpasyncclient:4.1.1" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.apache.httpcomponents:httpmime:4.5.2" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
|
||||
|
1072
.idea/workspace.xml
1072
.idea/workspace.xml
File diff suppressed because it is too large
Load Diff
@ -18,13 +18,17 @@ jar {
|
||||
sourceCompatibility = 1.8
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'net.dv8tion:JDA:3.1.0_204'
|
||||
compile 'net.dv8tion:JDA:3.1.1_212'
|
||||
compile 'mysql:mysql-connector-java:5.1.38'
|
||||
compile 'com.sedmelluq:lavaplayer:1.2.39'
|
||||
compile group: 'edu.cmu.sphinx', name: 'sphinx4-core', version:'5prealpha-SNAPSHOT'
|
||||
compile group: 'edu.cmu.sphinx', name: 'sphinx4-data', version:'5prealpha-SNAPSHOT'
|
||||
}
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
|
@ -1,13 +1,12 @@
|
||||
package me.savvy.rixa;
|
||||
|
||||
import me.savvy.rixa.commands.admin.BatchMoveCommand;
|
||||
import me.savvy.rixa.commands.general.HelpCommand;
|
||||
import me.savvy.rixa.commands.general.InfoCommand;
|
||||
import me.savvy.rixa.commands.general.PingCommand;
|
||||
import me.savvy.rixa.commands.general.ServerInfoCommand;
|
||||
import me.savvy.rixa.commands.admin.ConfigCommand;
|
||||
import me.savvy.rixa.commands.general.*;
|
||||
import me.savvy.rixa.commands.handlers.CommandExec;
|
||||
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.data.database.Data;
|
||||
import me.savvy.rixa.data.database.DataType;
|
||||
@ -84,7 +83,8 @@ public class Rixa {
|
||||
register(new CommandExec[] {
|
||||
new InfoCommand(), new ServerInfoCommand(), new HelpCommand(),
|
||||
new DeleteMessagesCommand(), new PingCommand(), new PurgeMessagesCommand(),
|
||||
new BatchMoveCommand() });
|
||||
new BatchMoveCommand(), new MuteCommand(), new MusicCommand(),
|
||||
new ConfigCommand()});
|
||||
ReactionManager.registerReaction(new HelpReaction());
|
||||
data = new Data(DataType.SQL);
|
||||
}
|
||||
@ -126,4 +126,8 @@ public class Rixa {
|
||||
public Logger getLogger() {
|
||||
return Logger.getLogger("Rixa");
|
||||
}
|
||||
|
||||
public ConfigManager getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class BatchMoveCommand implements CommandExec {
|
||||
channelType = ChannelType.TEXT)
|
||||
public void execute(GuildMessageReceivedEvent event) {
|
||||
RixaGuild rixaGuild = RixaManager.getGuild(event.getGuild());
|
||||
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.CLEAR_CHAT)) {
|
||||
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.BATCH_MOVE)) {
|
||||
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
|
241
src/main/java/me/savvy/rixa/commands/admin/ConfigCommand.java
Normal file
241
src/main/java/me/savvy/rixa/commands/admin/ConfigCommand.java
Normal file
@ -0,0 +1,241 @@
|
||||
package me.savvy.rixa.commands.admin;
|
||||
|
||||
import me.savvy.rixa.commands.handlers.Command;
|
||||
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.RixaManager;
|
||||
import me.savvy.rixa.utils.MessageBuilder;
|
||||
import net.dv8tion.jda.core.entities.ChannelType;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.entities.Role;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Timber on 6/6/2017.
|
||||
*/
|
||||
public class ConfigCommand implements CommandExec {
|
||||
|
||||
private List<String> config;
|
||||
public ConfigCommand() {
|
||||
config = Arrays.asList(
|
||||
"%pconfig set greetings ; Set channel where greeting messages are announced!",
|
||||
"%pconfig set farewell ; Set channel where farewell messages are announced!",
|
||||
"%pconfig set prefix <prefix> ; Set Rixa's command prefix!",
|
||||
"%pconfig set defaultRole <role> ; Set role to be assigned when a user joins the server!",
|
||||
"%pconfig set muteRole <role> ; Set role to be assigned when a user is muted!",
|
||||
"%pconfig set musicRole <musicRole> ; Set role required to use the music functions! (Not required)",
|
||||
"%pconfig joinMessage <joinMessage> ; Set the greetings message for when a user joins the server!",
|
||||
"%pconfig quitMessage <quitMessage> ; Set the quit message for when a user leaves the server!",
|
||||
"%pconfig joinPm <joinPm> ; Set the message to be private messaged when a user joins!",
|
||||
"%pconfig addPerm <role> <permission> ; Give a role permission to access a command!",
|
||||
"%pconfig removePerm <role> <permission> ; Remove a role's permission to access a command!",
|
||||
"%pconfig enable <module> ; Enabled a Rixa Module!",
|
||||
"%pconfig disable <module> ; Disable a Rixa Module!");
|
||||
}
|
||||
@Override
|
||||
@Command(mainCommand = "config",
|
||||
aliases = {},
|
||||
description = "Configure Rixa to your liking!",
|
||||
type = CommandType.ADMIN,
|
||||
channelType = ChannelType.TEXT)
|
||||
public void execute(GuildMessageReceivedEvent event) {
|
||||
RixaGuild rixaGuild = RixaManager.getGuild(event.getGuild());
|
||||
if (!rixaGuild.hasPermission(event.getMember(), RixaPermission.ACCESS_CONFIG)) {
|
||||
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.")
|
||||
.setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
String[] messages = event.getMessage().getContent().split(" ");
|
||||
if(messages.length == 2) {
|
||||
int page = 0;
|
||||
try {
|
||||
try {
|
||||
page = Integer.parseInt(messages[1]);
|
||||
sendHelp(event.getMember(), page, rixaGuild.getGuildSettings().getPrefix());
|
||||
} catch(NumberFormatException ex) {
|
||||
sendHelp(event.getMember(), page, rixaGuild.getGuildSettings().getPrefix());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} catch (IllegalArgumentException ex){
|
||||
sendHelp(event.getMember(), page, rixaGuild.getGuildSettings().getPrefix());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}else if (messages.length < 3) {
|
||||
sendHelp(event.getMember(), 0, rixaGuild.getGuildSettings().getPrefix());
|
||||
return;
|
||||
}
|
||||
String message;
|
||||
if (messages[1].equalsIgnoreCase("joinmessage")) {
|
||||
message = getMessage(messages, 2);
|
||||
rixaGuild.getGuildSettings().setJoinMessage(message);
|
||||
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);
|
||||
rixaGuild.getGuildSettings().setQuitMessage(message);
|
||||
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);
|
||||
rixaGuild.getGuildSettings().setJoinPrivateMessage(message);
|
||||
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("set")) {
|
||||
if (messages[2].equalsIgnoreCase("greetings")) {
|
||||
rixaGuild.getGuildSettings().setJoinMessageChannel(event.getChannel());
|
||||
new MessageBuilder("Successfully updated Greetings channel!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else if (messages[2].equalsIgnoreCase("farewell")) {
|
||||
rixaGuild.getGuildSettings().setQuitMessageChannel(event.getChannel());
|
||||
new MessageBuilder("Successfully updated Farewell channel!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} /*else if(messages[2].equalsIgnoreCase("logchannel")) {
|
||||
rixaGuild.getGuildSettings().setLogChannel(event.getChannel());
|
||||
event.getChannel().sendMessage("Successfully updated `Log Channel`").queue();
|
||||
|
||||
break;
|
||||
}*/ else if (messages[2].equalsIgnoreCase("prefix")) {
|
||||
String pref = messages[3];
|
||||
if (pref.length() > 3) {
|
||||
new MessageBuilder("Command prefix can only be 1 to 3 characters long!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
rixaGuild.getGuildSettings().setPrefix(pref);
|
||||
new MessageBuilder("Successfully updated command prefix!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else if (messages[2].equalsIgnoreCase("defaultRole")) {
|
||||
if (event.getMessage().getMentionedRoles().size() < 1) {
|
||||
new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + messages[0] + " set defaultRole <role>].\nMake sure to mention the role!")
|
||||
.setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
Role role = event.getMessage().getMentionedRoles().get(0);
|
||||
rixaGuild.getGuildSettings().setDefaultRole(role.getId());
|
||||
new MessageBuilder("Successfully set default role to " + role.getName() + "!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else if (messages[2].equalsIgnoreCase("muteRole")) {
|
||||
if (event.getMessage().getMentionedRoles().size() < 1) {
|
||||
new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + messages[0] + " set muteRole <role>].")
|
||||
.setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
Role role = event.getMessage().getMentionedRoles().get(0);
|
||||
rixaGuild.getGuildSettings().setMuteRole(role.getId());
|
||||
new MessageBuilder("Successfully set mute role to " + role.getName() + "!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else if (messages[2].equalsIgnoreCase("musicRole")) {
|
||||
if (event.getMessage().getMentionedRoles().size() < 1) {
|
||||
new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + messages[0] + " set musicRole <role>].")
|
||||
.setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
Role role = event.getMessage().getMentionedRoles().get(0);
|
||||
rixaGuild.getMusicModule().setRole(role.getId());
|
||||
new MessageBuilder("Successfully set music role to " + role.getName() + "!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
}
|
||||
} else if (messages[1].equalsIgnoreCase("enable")) {
|
||||
if (messages[2].equalsIgnoreCase("music")) {
|
||||
RixaManager.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")) {
|
||||
RixaManager.getGuild(event.getGuild()).getGuildSettings().setJoinVerification(true);
|
||||
new MessageBuilder("Successfully enabled Join Verification!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
}
|
||||
} else if (messages[1].equalsIgnoreCase("disable")) {
|
||||
if (messages[2].equalsIgnoreCase("music")) {
|
||||
RixaManager.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")) {
|
||||
RixaManager.getGuild(event.getGuild()).getGuildSettings().setJoinVerification(false);
|
||||
new MessageBuilder("Successfully disabled Join Verification!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
}
|
||||
} else if (messages[1].equalsIgnoreCase("addperm") || messages[1].equalsIgnoreCase("addpermission") || messages[1].equalsIgnoreCase("aperm")) {
|
||||
String permission = "notFound";
|
||||
for (String string : messages) {
|
||||
if (EnumUtils.isValidEnum(RixaPermission.class, string.toUpperCase())) {
|
||||
permission = string.toUpperCase();
|
||||
}
|
||||
}
|
||||
if (permission.equalsIgnoreCase("notFound")) {
|
||||
new MessageBuilder("Sorry that permission does not exist!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getMessage().getMentionedRoles().size() == 0) {
|
||||
new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + messages[0] + " addPerm <role> <permission>].")
|
||||
.setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
RixaPermission perm = RixaPermission.valueOf(permission.toUpperCase());
|
||||
Role role = event.getMessage().getMentionedRoles().get(0);
|
||||
if (rixaGuild.hasPermission(role, perm)) {
|
||||
new MessageBuilder("That role already has this permission!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
rixaGuild.setPermission(role, perm, true);
|
||||
new MessageBuilder("Successfully given the role " + role.getName() + " the permission " + perm.name() + "!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else if (messages[1].equalsIgnoreCase("removeperm")
|
||||
|| messages[1].equalsIgnoreCase("removepermission")
|
||||
|| messages[1].equalsIgnoreCase("rperm")
|
||||
|| messages[1].equalsIgnoreCase("delperm")) {
|
||||
String permission = "notFound";
|
||||
for (String string : messages) {
|
||||
if (EnumUtils.isValidEnum(RixaPermission.class, string.toUpperCase())) {
|
||||
permission = string.toUpperCase();
|
||||
}
|
||||
}
|
||||
if (permission.equalsIgnoreCase("notFound")) {
|
||||
new MessageBuilder("Sorry that permission does not exist!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
RixaPermission perm = RixaPermission.valueOf(permission.toUpperCase());
|
||||
if (event.getMessage().getMentionedRoles().size() == 0) {
|
||||
new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + messages[0] + " removePerm <role> <permission>].")
|
||||
.setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
Role role = event.getMessage().getMentionedRoles().get(0);
|
||||
if (!rixaGuild.hasPermission(role, perm)) {
|
||||
new MessageBuilder("That role doesn't have this permission!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
rixaGuild.setPermission(role, perm, false);
|
||||
new MessageBuilder("Successfully removed the permission " + perm.name() + " from the role " + role.getName() + "!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else {
|
||||
int page = 0;
|
||||
sendHelp(event.getMember(), page, rixaGuild.getGuildSettings().getPrefix());
|
||||
}
|
||||
}
|
||||
|
||||
private void sendHelp(Member member, int page, String prefix) {
|
||||
int sizePerPage = 4;
|
||||
int maxPages = config.size() / sizePerPage + (config.size() % sizePerPage > 0 ? 1 : 0);
|
||||
int from = Math.max(0, (page + 1 )* sizePerPage);
|
||||
int to = Math.min(config.size(), (page + 2) * sizePerPage);
|
||||
List<String> configList = config.subList(from, to);
|
||||
MessageBuilder builder = new MessageBuilder("\u2699" + " **Config**" +
|
||||
"\n" +
|
||||
"Click the back or forward reactions to switch between pages.");
|
||||
configList.forEach(object -> {
|
||||
builder.addField(object.split(" ; ")[0].replace("%p", prefix), object.split(" ; ")[1], true);
|
||||
});
|
||||
builder.footer("Page: (" + page + " / " + (maxPages - 2) + ")", member.getGuild().getIconUrl());
|
||||
builder.setColor(member.getColor()).sendUser(member.getUser()).setTitle("Config").addReaction("\u2B05").addReaction("\u27A1");
|
||||
}
|
||||
|
||||
private String getMessage(String[] messages, int argToBegin) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for(int i = argToBegin; i < messages.length; i++) {
|
||||
builder.append(messages[i]).append(" ");
|
||||
}
|
||||
return builder.toString().trim();
|
||||
}
|
||||
}
|
@ -17,8 +17,7 @@ public class HelpCommand implements CommandExec {
|
||||
|
||||
@Command(usage = "%phelp",
|
||||
channelType = ChannelType.TEXT,
|
||||
description = "Receive information about the server!",
|
||||
aliases = "", mainCommand = "help")
|
||||
description = "Receive information about the server!", mainCommand = "help", aliases = "h")
|
||||
public void execute(GuildMessageReceivedEvent event) {
|
||||
try {
|
||||
event.getMessage().delete().complete();
|
||||
|
@ -42,7 +42,7 @@ public class InfoCommand implements CommandExec {
|
||||
"roles on user join, music module, levels, and more. Rixa was created to bring ease and simplicity to managing discord" +
|
||||
" servers, it has since then grown into much more than just a bot used for moderation.")
|
||||
.addField("Created", event.getJDA().getSelfUser().getCreationTime().format(formatter), true)
|
||||
.addField("Bot Uptime ", "Online For: " + day + " days " + hours + " hours " + minute + " minutes " + second + " seconds.", true)
|
||||
.addField("Bot Uptime ", "Uptime: " + day + " days " + hours + " hours " + minute + " minutes " + second + " seconds.", true)
|
||||
.addField("Total Guilds", event.getJDA().getGuilds().size() + "", true)
|
||||
.addField("Total Users", event.getJDA().getUsers().size() + "", true)
|
||||
.addField("Rixa Developer", botOwner.getName() + "#" + botOwner.getDiscriminator(), true)
|
||||
|
322
src/main/java/me/savvy/rixa/commands/general/MusicCommand.java
Normal file
322
src/main/java/me/savvy/rixa/commands/general/MusicCommand.java
Normal file
@ -0,0 +1,322 @@
|
||||
package me.savvy.rixa.commands.general;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
||||
import com.sedmelluq.discord.lavaplayer.source.bandcamp.BandcampAudioSourceManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.beam.BeamAudioSourceManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.http.HttpAudioSourceManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.local.LocalAudioSourceManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.soundcloud.SoundCloudAudioSourceManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.twitch.TwitchStreamAudioSourceManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.vimeo.VimeoAudioSourceManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager;
|
||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import me.savvy.rixa.commands.handlers.Command;
|
||||
import me.savvy.rixa.commands.handlers.CommandExec;
|
||||
import me.savvy.rixa.commands.handlers.CommandType;
|
||||
import me.savvy.rixa.guild.RixaGuild;
|
||||
import me.savvy.rixa.guild.RixaManager;
|
||||
import me.savvy.rixa.modules.music.MusicManager;
|
||||
import me.savvy.rixa.modules.music.TrackScheduler;
|
||||
import me.savvy.rixa.utils.MessageBuilder;
|
||||
import net.dv8tion.jda.core.Permission;
|
||||
import net.dv8tion.jda.core.entities.*;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.exceptions.PermissionException;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Created by Timber on 6/6/2017.
|
||||
*/
|
||||
public class MusicCommand implements CommandExec {
|
||||
|
||||
public 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() {
|
||||
java.util.logging.Logger.getLogger("org.apache.http.client.protocol.ResponseProcessCookies").setLevel(Level.OFF);
|
||||
this.playerManager = new DefaultAudioPlayerManager();
|
||||
AudioSourceManagers.registerRemoteSources(playerManager);
|
||||
playerManager.registerSourceManager(new YoutubeAudioSourceManager());
|
||||
playerManager.registerSourceManager(new SoundCloudAudioSourceManager());
|
||||
playerManager.registerSourceManager(new BandcampAudioSourceManager());
|
||||
playerManager.registerSourceManager(new VimeoAudioSourceManager());
|
||||
playerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
|
||||
playerManager.registerSourceManager(new HttpAudioSourceManager());
|
||||
playerManager.registerSourceManager(new LocalAudioSourceManager());
|
||||
playerManager.registerSourceManager(new BeamAudioSourceManager());
|
||||
musicManagers = new HashMap<>();
|
||||
}
|
||||
|
||||
@Command(aliases = {},
|
||||
description = "Play music in your voice chat.",
|
||||
type = CommandType.USER,
|
||||
channelType = ChannelType.TEXT,
|
||||
usage = "%pmusic", mainCommand = "music")
|
||||
public void execute(GuildMessageReceivedEvent event) {
|
||||
Guild guild = event.getGuild();
|
||||
RixaGuild rixaGuild = RixaManager.getGuild(guild);
|
||||
if(!rixaGuild.getMusicModule().isEnabled()) {
|
||||
new MessageBuilder("Sorry music is not enabled on `" + guild.getName() + "`!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
if(rixaGuild.getMusicModule().isRoleRequired()) {
|
||||
Role role = event.getGuild().getRoleById(rixaGuild.getMusicModule().getMusicRole());
|
||||
if(!event.getMember().getRoles().contains(role)) {
|
||||
new MessageBuilder("You must have the " + role.getName() + " role to use the music module.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
}
|
||||
String[] message = event.getMessage().getContent().split(" ");
|
||||
MusicManager mng = getMusicManager(guild);
|
||||
AudioPlayer player = mng.player;
|
||||
TrackScheduler scheduler = mng.scheduler;
|
||||
// music join <channel>
|
||||
if(message.length == 1) {
|
||||
sendHelp();
|
||||
} else if (message.length == 2) {
|
||||
if(message[1].equalsIgnoreCase("join")) {
|
||||
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());
|
||||
} 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("play")) {
|
||||
if (player.isPaused()) {
|
||||
player.setPaused(false);
|
||||
new MessageBuilder("MusicPlayer resumed track: " + player.getPlayingTrack().getInfo().title).setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else if (player.getPlayingTrack() != null) {
|
||||
new MessageBuilder("MusicPlayer already playing track: " + player.getPlayingTrack().getInfo().title).setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else if (scheduler.queue.isEmpty()) {
|
||||
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("skip")) {
|
||||
AudioTrack track = scheduler.nextTrack();
|
||||
if(track != null) {
|
||||
new MessageBuilder("The current track has been skipped. Now Playing: " + track.getInfo().title).setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else {
|
||||
new MessageBuilder("Track Skipped. Queue Complete").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
}
|
||||
} 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());
|
||||
return;
|
||||
}
|
||||
new MessageBuilder("Track Name: " + player.getPlayingTrack().getInfo().title + "\n Track Link: " +
|
||||
player.getPlayingTrack().getInfo().uri).setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else if(message[1].equalsIgnoreCase("pause")) {
|
||||
if (player.getPlayingTrack() == null) {
|
||||
new MessageBuilder("There is no track currently playing.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
player.setPaused(!player.isPaused());
|
||||
if (player.isPaused()) {
|
||||
new MessageBuilder("The music player has been paused.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else {
|
||||
new MessageBuilder("There music player has resumed playing.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
}
|
||||
} else if(message[1].equalsIgnoreCase("stop")) {
|
||||
scheduler.queue.clear();
|
||||
player.stopTrack();
|
||||
player.setPaused(false);
|
||||
new MessageBuilder("The music player has been stopped and queue has been cleared.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else if(message[1].equalsIgnoreCase("vol") || message[1].equalsIgnoreCase("volume")) {
|
||||
new MessageBuilder("Music player volume is currently at: " + player.getVolume()).setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else if(message[1].equalsIgnoreCase("restart")) {
|
||||
AudioTrack track = player.getPlayingTrack();
|
||||
if (track == null) {
|
||||
track = scheduler.lastTrack;
|
||||
}
|
||||
if (track != null) {
|
||||
new MessageBuilder("Restarting Track: " + track.getInfo().title).setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
event.getChannel().sendMessage("Restarting track: " + track.getInfo().title).queue();
|
||||
player.playTrack(track.makeClone());
|
||||
} else {
|
||||
new MessageBuilder("No track has been previously played.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
}
|
||||
} 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) {
|
||||
String title = currentTrack.getInfo().title;
|
||||
String position = getTimestamp(currentTrack.getPosition());
|
||||
String duration = getTimestamp(currentTrack.getDuration());
|
||||
new MessageBuilder(String.format("Now Playing: %s [%s / %s]", title, position, duration)).setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else {
|
||||
new MessageBuilder("The music player is not playing anything!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
}
|
||||
} else if(message[1].equalsIgnoreCase("list")) {
|
||||
Queue<AudioTrack> queue = scheduler.queue;
|
||||
synchronized (queue) {
|
||||
if (queue.isEmpty()) {
|
||||
new MessageBuilder("The queue is currently empty!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else {
|
||||
int trackCount = 0;
|
||||
long queueLength = 0;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Current Queue Entries: ").append(queue.size()).append("\n\n");
|
||||
for (AudioTrack track : queue) {
|
||||
queueLength += track.getDuration();
|
||||
if (trackCount < 10) {
|
||||
sb.append("`[").append(getTimestamp(track.getDuration())).append("]` ");
|
||||
sb.append(track.getInfo().title).append("\n");
|
||||
trackCount++;
|
||||
}
|
||||
}
|
||||
sb.append("\n").append("Total Queue Time Length: ").append(getTimestamp(queueLength));
|
||||
new MessageBuilder(sb.toString().trim()).setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
event.getChannel().sendMessage(sb.toString()).queue();
|
||||
}
|
||||
}
|
||||
} else if(message[1].equalsIgnoreCase("shuffle")) {
|
||||
if (scheduler.queue.isEmpty()) {
|
||||
new MessageBuilder("The queue is currently empty!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
scheduler.shuffle();
|
||||
new MessageBuilder("The queue has been shuffled!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
}
|
||||
} else if (message.length == 3) {
|
||||
if(message[1].equalsIgnoreCase("join")) {
|
||||
VoiceChannel chan = null;
|
||||
if (guild.getVoiceChannelsByName(message[2], true).size() >= 1) {
|
||||
chan = guild.getVoiceChannelsByName(message[2], true).get(0);
|
||||
} else {
|
||||
for (VoiceChannel voiceChannel : guild.getVoiceChannels()) {
|
||||
if (voiceChannel.getName().contains(message[2]) || voiceChannel.getId().equalsIgnoreCase(message[2])) {
|
||||
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("play") || message[1].equalsIgnoreCase("pplay")) {
|
||||
loadAndPlay(mng, event.getChannel(), message[2], false);
|
||||
} else if(message[1].equalsIgnoreCase("vol") || message[1].equalsIgnoreCase("volume")) {
|
||||
try {
|
||||
int newVolume = Math.max(10, Math.min(100, Integer.parseInt(message[2])));
|
||||
int oldVolume = player.getVolume();
|
||||
player.setVolume(newVolume);
|
||||
new MessageBuilder("Music player volume changed from " + oldVolume + " to " + newVolume).setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadAndPlay(MusicManager mng, final TextChannel channel, final String trackUrl, final boolean addPlaylist) {
|
||||
playerManager.loadItemOrdered(mng, trackUrl, new AudioLoadResultHandler() {
|
||||
@Override
|
||||
public void trackLoaded(AudioTrack track) {
|
||||
String msg = "Adding to queue: " + track.getInfo().title;
|
||||
mng.scheduler.queue(track);
|
||||
new MessageBuilder(msg).setColor(Color.decode("#4CC276")).queue(channel);
|
||||
channel.sendMessage(msg).queue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playlistLoaded(AudioPlaylist playlist) {
|
||||
AudioTrack firstTrack = playlist.getSelectedTrack();
|
||||
List<AudioTrack> tracks = playlist.getTracks();
|
||||
|
||||
if (firstTrack == null) {
|
||||
firstTrack = playlist.getTracks().get(0);
|
||||
}
|
||||
|
||||
if (addPlaylist) {
|
||||
new MessageBuilder("Adding (" + playlist.getTracks().size() +") tracks to queue from playlist: " + playlist.getName()).setColor(Color.decode("#4CC276")).queue(channel);
|
||||
tracks.forEach(mng.scheduler::queue);
|
||||
} else {
|
||||
new MessageBuilder("Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")").setColor(Color.decode("#4CC276")).queue(channel);
|
||||
mng.scheduler.queue(firstTrack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noMatches() {
|
||||
new MessageBuilder("Nothing found by " + trackUrl).setColor(Color.decode("#4CC276")).queue(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFailed(FriendlyException exception) {
|
||||
new MessageBuilder("Could not play: " + exception.getMessage()).setColor(Color.decode("#4CC276")).queue(channel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private MusicManager getMusicManager(Guild guild) {
|
||||
String guildId = guild.getId();
|
||||
MusicManager mng = musicManagers.get(guildId);
|
||||
if (mng == null)
|
||||
{
|
||||
synchronized (musicManagers)
|
||||
{
|
||||
mng = musicManagers.get(guildId);
|
||||
if (mng == null)
|
||||
{
|
||||
mng = new MusicManager(playerManager);
|
||||
mng.player.setVolume(DEFAULT_VOLUME);
|
||||
musicManagers.put(guildId, mng);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mng;
|
||||
}
|
||||
|
||||
private static String getTimestamp(long milliseconds) {
|
||||
int seconds = (int) (milliseconds / 1000) % 60 ;
|
||||
int minutes = (int) ((milliseconds / (1000 * 60)) % 60);
|
||||
int hours = (int) ((milliseconds / (1000 * 60 * 60)) % 24);
|
||||
|
||||
if (hours > 0)
|
||||
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
|
||||
else
|
||||
return String.format("%02d:%02d", minutes, seconds);
|
||||
}
|
||||
|
||||
private void sendHelp() {
|
||||
}
|
||||
}
|
@ -12,10 +12,11 @@ import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
public class PingCommand implements CommandExec {
|
||||
@Override
|
||||
@Command(mainCommand = "ping",
|
||||
aliases = "",
|
||||
description = "Check your ping!",
|
||||
channelType = ChannelType.TEXT)
|
||||
public void execute(GuildMessageReceivedEvent event) {
|
||||
new MessageBuilder("Pong!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
new MessageBuilder("Pong!").setColor(event.getMember().getColor()).complete(event.getChannel());
|
||||
/*RixaAudioReceiveHandler handle = new RixaAudioReceiveHandler();
|
||||
handle.start(event.getGuild(), event.getMember().getVoiceState().getChannel());*/
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ 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.guild.RixaManager;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.entities.ChannelType;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
@ -19,12 +21,13 @@ public class ServerInfoCommand implements CommandExec {
|
||||
description = "Receive information about the server!",
|
||||
aliases = "sinfo", mainCommand = "serverinfo")
|
||||
public void execute(GuildMessageReceivedEvent event) {
|
||||
RixaGuild rixaGuild = RixaManager.getGuild(event.getGuild());
|
||||
EmbedBuilder messageEmbed = new EmbedBuilder();
|
||||
User owner = event.getGuild().getOwner().getUser();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss");
|
||||
messageEmbed
|
||||
.setTitle(event.getGuild().getName(), "http://rixa.io/servers/" + event.getGuild().getId())
|
||||
.setDescription("Description")
|
||||
.setDescription(rixaGuild.getGuildSettings().getDescription())
|
||||
.addField("Created", event.getGuild().getCreationTime().format(formatter), true)
|
||||
.addField("Region", event.getGuild().getRegion().toString(), true)
|
||||
.addField("Users", String.valueOf(event.getGuild().getMembers().size()), true)
|
||||
|
@ -16,7 +16,7 @@ public @interface Command {
|
||||
|
||||
String mainCommand();
|
||||
|
||||
String[] aliases();
|
||||
String[] aliases() default {};
|
||||
|
||||
String description() default "";
|
||||
|
||||
|
@ -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
|
||||
MUTE, ADD_ROLE, REMOVE_ROLE, CLEAR_CHAT, ACCESS_CONFIG, PM_MESSAGE, KICK_MEMBER, BAN_MEMBER, BATCH_MOVE
|
||||
|
||||
}
|
||||
|
68
src/main/java/me/savvy/rixa/commands/mod/MuteCommand.java
Normal file
68
src/main/java/me/savvy/rixa/commands/mod/MuteCommand.java
Normal file
@ -0,0 +1,68 @@
|
||||
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.CommandType;
|
||||
import me.savvy.rixa.commands.handlers.RixaPermission;
|
||||
import me.savvy.rixa.guild.RixaGuild;
|
||||
import me.savvy.rixa.guild.RixaManager;
|
||||
import me.savvy.rixa.utils.MessageBuilder;
|
||||
import net.dv8tion.jda.core.entities.ChannelType;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.entities.Role;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.exceptions.PermissionException;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Created by Timber on 6/5/2017.
|
||||
*/
|
||||
public class MuteCommand implements CommandExec {
|
||||
@Override
|
||||
@Command(mainCommand = "mute",
|
||||
aliases = "",
|
||||
description = "Mute a member.",
|
||||
type = CommandType.MOD,
|
||||
channelType = ChannelType.TEXT)
|
||||
public void execute(GuildMessageReceivedEvent event) {
|
||||
RixaGuild rixaGuild = RixaManager.getGuild(event.getGuild());
|
||||
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.MUTE)) {
|
||||
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
|
||||
if(rixaGuild.getGuildSettings().getMuteRole() == null || rixaGuild.getGuildSettings().getMuteRole().equalsIgnoreCase("default_value")) {
|
||||
new MessageBuilder(event.getMember().getAsMention() + ", could not find appropriate role for muting!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
Role muteRole = event.getGuild().getRoleById(rixaGuild.getGuildSettings().getMuteRole());
|
||||
if(muteRole == null) {
|
||||
new MessageBuilder(event.getMember().getAsMention() + ", could not find appropriate role for muting!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
|
||||
String[] messages = event.getMessage().getContent().split(" ");
|
||||
if(event.getMessage().getMentionedUsers().size() < 1) {
|
||||
new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + messages[0] + " <user>].").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
for(User user: event.getMessage().getMentionedUsers()) {
|
||||
Member muted = rixaGuild.getGuild().getMember(user);
|
||||
if (rixaGuild.isUserMuted(muted.getUser())) {
|
||||
rixaGuild.getGuild().getController().removeRolesFromMember(muted, Collections.singleton(muteRole)).queue();
|
||||
rixaGuild.unmuteMember(muted.getUser());
|
||||
new MessageBuilder("Successfully unmuted `" + muted.getEffectiveName() + "`.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
} else {
|
||||
rixaGuild.getGuild().getController().addRolesToMember(muted, Collections.singleton(muteRole)).queue();
|
||||
rixaGuild.muteMember(muted.getUser());
|
||||
new MessageBuilder("Successfully muted `" + muted.getEffectiveName() + "`.").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
}
|
||||
}
|
||||
} catch (PermissionException ex) {
|
||||
new MessageBuilder(event.getMember().getAsMention() + ", sorry I do not have permission for this!").setColor(event.getMember().getColor()).queue(event.getChannel());
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package me.savvy.rixa.data.database;
|
||||
|
||||
import me.savvy.rixa.Rixa;
|
||||
import me.savvy.rixa.data.database.sql.DatabaseManager;
|
||||
import me.savvy.rixa.enums.Result;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
@ -23,7 +24,7 @@ public class Data {
|
||||
public Object get(String key, String value, String objToGet, String table) throws SQLException {
|
||||
switch (dataType) {
|
||||
case SQL:
|
||||
// SELECT guild FROM table WHERE key = value.
|
||||
// SELECT objToGet FROM table WHERE key = value.
|
||||
PreparedStatement ps =
|
||||
db.getConnection().prepareStatement("SELECT `" + objToGet + "` FROM `" + table + "` WHERE `" + key + "` = ?");
|
||||
ps.setString(1, value);
|
||||
@ -35,14 +36,23 @@ public class Data {
|
||||
|
||||
public void put(String key, String value) {
|
||||
switch (dataType) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void update(String key, String value) {
|
||||
public Result update(String table, String setting, String key, Object placeholder, Object placeholder2) {
|
||||
switch (dataType) {
|
||||
|
||||
case SQL:
|
||||
try {
|
||||
PreparedStatement ps = db.getConnection().prepareStatement("UPDATE `" + table +"` SET `" + setting + "` = ? WHERE `" + key + "` = ?;");
|
||||
ps.setObject(1, placeholder);
|
||||
ps.setObject(2, placeholder2);
|
||||
return db.executeUpdate(ps);
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
return Result.ERROR;
|
||||
}
|
||||
}
|
||||
return Result.FALSE;
|
||||
}
|
||||
|
||||
public void delete(String key, String value) {
|
||||
@ -50,4 +60,12 @@ public class Data {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Result exists(String check) {
|
||||
switch(dataType) {
|
||||
case SQL:
|
||||
return db.checkExists(check);
|
||||
}
|
||||
return Result.FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,9 @@ import me.savvy.rixa.data.thunderbolt.exceptions.FileLoadException;
|
||||
import me.savvy.rixa.data.thunderbolt.io.ThunderFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -32,6 +34,7 @@ public class ConfigManager {
|
||||
}
|
||||
|
||||
private void addDefaults() throws IOException {
|
||||
List<String> botAdmins = new ArrayList<>();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("hostName", "localhost");
|
||||
map.put("password", "password");
|
||||
@ -39,7 +42,10 @@ public class ConfigManager {
|
||||
map.put("userName", "rixa_users");
|
||||
map.put("portNumber", "3306");
|
||||
tf.set("sql", map);
|
||||
|
||||
botAdmins.add("YOUR_USER_ID_HERE");
|
||||
botAdmins.add("OTHER_ADMINS");
|
||||
botAdmins.add("REMOVE_IF_YOU_DONT_WANT");
|
||||
tf.set("botAdmins", botAdmins);
|
||||
tf.set("secretToken", "YOUR_TOKEN_HERE");
|
||||
tf.set("botGame", "Rixa 2.0 | http://rixa.io/invite");
|
||||
tf.save();
|
||||
|
@ -1,9 +1,17 @@
|
||||
package me.savvy.rixa.guild;
|
||||
|
||||
import me.savvy.rixa.Rixa;
|
||||
import me.savvy.rixa.commands.handlers.RixaPermission;
|
||||
import me.savvy.rixa.data.database.sql.DatabaseManager;
|
||||
import me.savvy.rixa.guild.management.GuildSettings;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import me.savvy.rixa.modules.music.MusicModule;
|
||||
import net.dv8tion.jda.core.entities.*;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Timber on 5/23/2017.
|
||||
@ -11,10 +19,15 @@ import net.dv8tion.jda.core.entities.Member;
|
||||
public class RixaGuild {
|
||||
|
||||
private Guild guild;
|
||||
private DatabaseManager db;
|
||||
private GuildSettings guildSettings;
|
||||
private MusicModule musicModule;
|
||||
private List<String> mutedMembers = new ArrayList<>();
|
||||
|
||||
public RixaGuild(Guild guild) {
|
||||
this.guild = guild;
|
||||
this.db = Rixa.getInstance().getDbManager();
|
||||
setMusicModule(new MusicModule(guild));
|
||||
load();
|
||||
}
|
||||
|
||||
@ -29,7 +42,7 @@ public class RixaGuild {
|
||||
}
|
||||
|
||||
public void setGuildSettings(GuildSettings guildSettings) {
|
||||
this.guildSettings = guildSettings;
|
||||
this.guildSettings = guildSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,7 +56,84 @@ public class RixaGuild {
|
||||
return guild;
|
||||
}
|
||||
|
||||
public boolean hasPermission(Member member, RixaPermission clearChat) {
|
||||
return member.getUser().getId().equalsIgnoreCase("202944101333729280");
|
||||
public boolean hasPermission(Member member, RixaPermission permission) {
|
||||
if(Rixa.getInstance().getConfig().getConfig().getStringList("botAdmins").contains(member.getUser().getId()) ||
|
||||
member.getUser().getId().equals(guild.getOwner().getUser().getId())) {
|
||||
return true;
|
||||
}
|
||||
for(Role role: member.getRoles()) {
|
||||
if(hasPermission(role, permission)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasPermission(Role role, RixaPermission permission) {
|
||||
if(!permissionExists(role)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
PreparedStatement ps =
|
||||
db.getConnection().prepareStatement
|
||||
("SELECT `" + permission.toString().toUpperCase() + "` FROM `permissions` WHERE `role_id` = ?");
|
||||
ps.setString(1, role.getId());
|
||||
ResultSet rs = db.getObject(ps);
|
||||
return rs.getBoolean(permission.toString().toUpperCase());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setPermission(Role role, RixaPermission permission, boolean value) {
|
||||
if(!permissionExists(role)) {
|
||||
db
|
||||
.insert("INSERT INTO `permissions` " +
|
||||
"(`role_id`, `guild_id`, `MUTE`, `ADD_ROLE`, `REMOVE_ROLE`, `CLEAR_CHAT`, " +
|
||||
"`ACCESS_CONFIG`, `PM_MESSAGE`, `KICK_MEMBER`, `BAN_MEMBER`)" +
|
||||
" VALUES ('" + role.getId() + "', '" + guild.getId() + "', '0', '0', '0', '0', '0', '0', '0', '0');");
|
||||
}
|
||||
try {
|
||||
PreparedStatement ps = db.getConnection().prepareStatement
|
||||
("UPDATE `permissions` SET `" + permission.toString().toUpperCase() + "` = ? WHERE `guild_id` = ? AND `role_id` = ?;");
|
||||
ps.setBoolean(1, value);
|
||||
ps.setString(2, guild.getId());
|
||||
ps.setString(3, role.getId());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean permissionExists(Role role) {
|
||||
ResultSet rs = db.executeQuery
|
||||
("SELECT `" + RixaPermission.values()[0] + "` FROM `permissions` WHERE `guild_id` = '" + guild.getId() + "' AND `role_id` = '" + role.getId() + "'");
|
||||
try {
|
||||
return rs.next();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUserMuted(User user) {
|
||||
return mutedMembers.contains(user.getId());
|
||||
}
|
||||
|
||||
public void unmuteMember(User user) {
|
||||
mutedMembers.remove(user.getId());
|
||||
}
|
||||
|
||||
public void muteMember(User user) {
|
||||
if(!isUserMuted(user))
|
||||
mutedMembers.add(user.getId());
|
||||
}
|
||||
|
||||
public MusicModule getMusicModule() {
|
||||
return musicModule;
|
||||
}
|
||||
|
||||
public void setMusicModule(MusicModule musicModule) {
|
||||
this.musicModule = musicModule;
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ import java.sql.SQLException;
|
||||
public class GuildSettings {
|
||||
|
||||
private Guild guild;
|
||||
private boolean enlisted;
|
||||
private String prefix = ".", defaultRole, joinMessage, quitMessage, joinPrivateMessage, description;
|
||||
private boolean enlisted, joinVerification;
|
||||
private String prefix = "/", defaultRole, muteRole, joinMessage, quitMessage, joinPrivateMessage, description;
|
||||
private TextChannel joinMessageChannel, quitMessageChannel;
|
||||
|
||||
public GuildSettings(Guild guild) {
|
||||
@ -37,6 +37,8 @@ public class GuildSettings {
|
||||
setJoinMessage(set.getString("joinMessage"));
|
||||
setQuitMessage(set.getString("quitMessage"));
|
||||
setJoinPrivateMessage(set.getString("joinPM"));
|
||||
setMuteRole(set.getString("muteRole"));
|
||||
setJoinVerification(set.getBoolean("joinVerification"));
|
||||
setDescription((String)Rixa.getInstance().getData().get("guild_id", guild.getId(), "description", "core"));
|
||||
setEnlisted((boolean) Rixa.getInstance().getData().get("guild_id", guild.getId(), "enlisted", "core"));
|
||||
}
|
||||
@ -120,4 +122,20 @@ public class GuildSettings {
|
||||
public void setEnlisted(boolean enlisted) {
|
||||
this.enlisted = enlisted;
|
||||
}
|
||||
|
||||
public String getMuteRole() {
|
||||
return muteRole;
|
||||
}
|
||||
|
||||
public void setMuteRole(String muteRole) {
|
||||
this.muteRole = muteRole;
|
||||
}
|
||||
|
||||
public boolean isJoinVerification() {
|
||||
return joinVerification;
|
||||
}
|
||||
|
||||
public void setJoinVerification(boolean joinVerification) {
|
||||
this.joinVerification = joinVerification;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
package me.savvy.rixa.modules.audio;
|
||||
|
||||
import net.dv8tion.jda.core.audio.AudioReceiveHandler;
|
||||
import net.dv8tion.jda.core.audio.CombinedAudio;
|
||||
import net.dv8tion.jda.core.audio.UserAudio;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.VoiceChannel;
|
||||
import net.dv8tion.jda.core.managers.AudioManager;
|
||||
|
||||
/**
|
||||
* Created by Timber on 6/5/2017.
|
||||
*/
|
||||
public class RixaAudioReceiveHandler implements AudioReceiveHandler {
|
||||
|
||||
private Guild guild;
|
||||
|
||||
public void start(Guild guild, VoiceChannel channel){
|
||||
this.guild = guild;
|
||||
AudioManager manager = guild.getAudioManager();
|
||||
manager.openAudioConnection(channel);
|
||||
manager.setReceivingHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveCombined() {
|
||||
//Lets JDA know that it's OK to send audio to this class
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveUser() {
|
||||
//Lets JDA know that it's OK to send audio to this class
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCombinedAudio(CombinedAudio audio) {
|
||||
//This will give you audio from all users, packet by packet.
|
||||
//You can do with this whatever you want, pass it onto a sending handler, write it to a file etc
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUserAudio(UserAudio audio) {
|
||||
//This will give you audio from a single user, packet by packet
|
||||
guild.getTextChannelById("301790750327308290").sendMessage(audio.getUser().getAsMention() + " is talking").queue();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package me.savvy.rixa.modules.music;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
|
||||
import net.dv8tion.jda.core.audio.AudioSendHandler;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
|
||||
/**
|
||||
* Created by Timber on 3/13/2017.
|
||||
*/
|
||||
public class AudioPlayerSendHandler implements AudioSendHandler {
|
||||
private final AudioPlayer audioPlayer;
|
||||
private AudioFrame lastFrame;
|
||||
|
||||
/**
|
||||
* @param audioPlayer Audio player to wrap.
|
||||
*/
|
||||
public AudioPlayerSendHandler(AudioPlayer audioPlayer) {
|
||||
this.audioPlayer = audioPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvide() {
|
||||
if (lastFrame == null) {
|
||||
lastFrame = audioPlayer.provide();
|
||||
}
|
||||
return lastFrame != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] provide20MsAudio()
|
||||
{
|
||||
if (lastFrame == null)
|
||||
{
|
||||
lastFrame = audioPlayer.provide();
|
||||
}
|
||||
|
||||
byte[] data = lastFrame != null ? lastFrame.data : null;
|
||||
lastFrame = null;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpus()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
33
src/main/java/me/savvy/rixa/modules/music/MusicManager.java
Normal file
33
src/main/java/me/savvy/rixa/modules/music/MusicManager.java
Normal file
@ -0,0 +1,33 @@
|
||||
package me.savvy.rixa.modules.music;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
|
||||
/**
|
||||
* Created by Timber on 3/13/2017.
|
||||
*/
|
||||
public class MusicManager {
|
||||
/**
|
||||
* Audio player for the guild.
|
||||
*/
|
||||
public final AudioPlayer player;
|
||||
/**
|
||||
* Track scheduler for the player.
|
||||
*/
|
||||
public final TrackScheduler scheduler;
|
||||
/**
|
||||
* Wrapper around AudioPlayer to use it as an AudioSendHandler.
|
||||
*/
|
||||
public final AudioPlayerSendHandler sendHandler;
|
||||
|
||||
/**
|
||||
* Creates a player and a track scheduler.
|
||||
* @param manager Audio player manager to use for creating the player.
|
||||
*/
|
||||
public MusicManager(AudioPlayerManager manager) {
|
||||
player = manager.createPlayer();
|
||||
scheduler = new TrackScheduler(player);
|
||||
sendHandler = new AudioPlayerSendHandler(player);
|
||||
player.addListener(scheduler);
|
||||
}
|
||||
}
|
@ -1,11 +1,51 @@
|
||||
package me.savvy.rixa.modules.music;
|
||||
|
||||
import me.savvy.rixa.Rixa;
|
||||
import me.savvy.rixa.data.database.sql.DatabaseManager;
|
||||
import me.savvy.rixa.enums.Result;
|
||||
import me.savvy.rixa.modules.RixaModule;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by Timber on 5/23/2017.
|
||||
*/
|
||||
public class MusicModule implements RixaModule {
|
||||
private DatabaseManager db;
|
||||
private boolean enabled;
|
||||
private String musicRole;
|
||||
private Guild guild;
|
||||
|
||||
public MusicModule(Guild guild) {
|
||||
this.guild = guild;
|
||||
this.enabled = false;
|
||||
this.musicRole = "default_value";
|
||||
db = Rixa.getInstance().getDbManager();
|
||||
load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
System.out.println("Testing " + guild.getName());
|
||||
if(!checkExists()) {
|
||||
db.insert("INSERT INTO `music` (`guild_id`, `music_role`, `enabled`)" +
|
||||
" VALUES ('" + guild.getId() + "', 'default_value', '0');");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
PreparedStatement ps = db.getConnection().prepareStatement
|
||||
("SELECT * FROM `music` WHERE `guild_id` = ?;");
|
||||
ps.setString(1, guild.getId());
|
||||
ResultSet rs = db.getObject(ps);
|
||||
this.musicRole = rs.getString("music_role");
|
||||
this.enabled = rs.getBoolean("enabled");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Music";
|
||||
@ -13,11 +53,37 @@ public class MusicModule implements RixaModule {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "";
|
||||
return "Listen to music in your voice channel.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return false;
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public Result setEnabled(boolean val) {
|
||||
this.enabled = val;
|
||||
return Rixa.getInstance().getData().update("music", "enabled", "guild_id", val, guild.getId());
|
||||
}
|
||||
|
||||
public boolean isRoleRequired() {
|
||||
return (musicRole.equalsIgnoreCase("default_value") && guild.getRolesByName(musicRole, true).size() > 0);
|
||||
}
|
||||
|
||||
public String getMusicRole() {
|
||||
return musicRole;
|
||||
}
|
||||
|
||||
public Result setRole(String newRole) {
|
||||
this.musicRole = newRole;
|
||||
return Rixa.getInstance().getData().update("music", "music_role", "guild_id", newRole, guild.getId());
|
||||
}
|
||||
|
||||
public Guild getGuild() {
|
||||
return guild;
|
||||
}
|
||||
|
||||
public boolean checkExists() {
|
||||
return Rixa.getInstance().getData().exists("SELECT `enabled` FROM `music` WHERE `guild_id` = '" + guild.getId() + "'") == Result.TRUE;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,83 @@
|
||||
package me.savvy.rixa.modules.music;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* Created by Timber on 6/13/2017.
|
||||
*/
|
||||
public class TrackScheduler extends AudioEventAdapter {
|
||||
private boolean repeating = false;
|
||||
final AudioPlayer player;
|
||||
public final Queue<AudioTrack> queue;
|
||||
public AudioTrack lastTrack;
|
||||
|
||||
/**
|
||||
* @param player The audio player this scheduler uses
|
||||
*/
|
||||
public TrackScheduler(AudioPlayer player) {
|
||||
this.player = player;
|
||||
this.queue = new LinkedList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the next track to queue or play right away if nothing is in the queue.
|
||||
*
|
||||
* @param track The track to play or add to queue.
|
||||
*/
|
||||
public void queue(AudioTrack track)
|
||||
{
|
||||
|
||||
// Calling startTrack with the noInterrupt set to true will start the track only if nothing is currently playing. If
|
||||
// something is playing, it returns false and does nothing. In that case the player was already playing so this
|
||||
// track goes to the queue instead.
|
||||
if (!player.startTrack(track, true))
|
||||
{
|
||||
queue.offer(track);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the next track, stopping the current one if it is playing.
|
||||
*/
|
||||
public AudioTrack nextTrack()
|
||||
{
|
||||
// Start the next track, regardless of if something is already playing or not. In case queue was empty, we are
|
||||
// giving null to startTrack, which is a valid argument and will simply stop the player.
|
||||
AudioTrack track = queue.poll();
|
||||
player.startTrack(track, false);
|
||||
return track;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
|
||||
this.lastTrack = track;
|
||||
// Only start the next track if the end reason is suitable for it (FINISHED or LOAD_FAILED)
|
||||
if (endReason.mayStartNext) {
|
||||
if (repeating)
|
||||
player.startTrack(lastTrack.makeClone(), false);
|
||||
else
|
||||
nextTrack();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isRepeating() {
|
||||
return repeating;
|
||||
}
|
||||
|
||||
public void setRepeating(boolean repeating) {
|
||||
this.repeating = repeating;
|
||||
}
|
||||
|
||||
public void shuffle() {
|
||||
Collections.shuffle((List<?>) queue);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package me.savvy.rixa.modules.reactions.react;
|
||||
|
||||
import me.savvy.rixa.modules.reactions.handlers.React;
|
||||
import me.savvy.rixa.modules.reactions.handlers.ReactHandle;
|
||||
import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent;
|
||||
|
||||
/**
|
||||
* Created by Timber on 6/9/2017.
|
||||
*/
|
||||
public class ConfigReaction implements React {
|
||||
|
||||
@Override
|
||||
@ReactHandle(title = "Config", description = "Configuration Menu for Rixa")
|
||||
public void reactionTrigger(MessageReactionAddEvent event) {
|
||||
}
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
package me.savvy.rixa.utils;
|
||||
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.core.entities.TextChannel;
|
||||
import net.dv8tion.jda.core.entities.*;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@ -11,6 +10,8 @@ import java.awt.*;
|
||||
*/
|
||||
public class MessageBuilder {
|
||||
|
||||
private Message message;
|
||||
|
||||
private EmbedBuilder builder;
|
||||
public MessageBuilder(String description) {
|
||||
this.builder = new EmbedBuilder().setDescription(description);
|
||||
@ -48,7 +49,29 @@ public class MessageBuilder {
|
||||
channel.sendMessage(builder.build()).complete();
|
||||
}
|
||||
|
||||
public void send(User member) {
|
||||
member.openPrivateChannel().complete().sendMessage(builder.build()).queue();
|
||||
}
|
||||
|
||||
public MessageBuilder sendUser(User member) {
|
||||
this.message = member.openPrivateChannel().complete().sendMessage(builder.build()).complete();
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageBuilder addReaction(String reaction) {
|
||||
if(message == null) {
|
||||
throw new NullPointerException("Message must not be null!");
|
||||
}
|
||||
message.addReaction(reaction).complete();
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageEmbed build() {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public MessageBuilder footer(String s, String iconURL) {
|
||||
builder.setFooter(s, iconURL);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user