Implemented MuteCommand, default role is now applied when user joins

This commit is contained in:
Savvy 2018-02-21 13:53:52 -05:00
parent cfe7ec22e2
commit bbd09c7972
5 changed files with 571 additions and 486 deletions

237
pom.xml
View File

@ -1,122 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.rixa</groupId>
<artifactId>Rixa</artifactId>
<version>3.0-SNAPSHOT</version>
<groupId>io.rixa</groupId>
<artifactId>Rixa</artifactId>
<version>3.0-SNAPSHOT</version>
<repositories>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
<repositories>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
<repository>
<id>onarandombox</id>
<url>http://repo.onarandombox.com/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.9.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ca.pjer</groupId>
<artifactId>chatter-bot-api</artifactId>
<version>1.4.7</version>
<scope>compile</scope>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.9.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ca.pjer</groupId>
<artifactId>chatter-bot-api</artifactId>
<version>1.4.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.dumptruckman</groupId>
<artifactId>taskmin</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
<build>
<finalName>${project.name}-Build-${project.version}-SNAPSHOT</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<build>
<finalName>${project.name}-Build-${project.version}-SNAPSHOT</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>io.rixa.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</execution>
</executions>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>io.rixa.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -10,26 +10,28 @@ import io.rixa.bot.user.RixaUser;
import io.rixa.bot.user.manager.UserManager;
import io.rixa.bot.utils.DiscordUtils;
import io.rixa.bot.utils.MessageFactory;
import net.dv8tion.jda.core.entities.*;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.entities.TextChannel;
import org.apache.commons.lang3.StringUtils;
public class ConfigCommand extends Command {
private Pagination pagination;
public ConfigCommand(String command, RixaPermission rixaPermission, String description) {
super(command, rixaPermission, description);
private Pagination pagination;
pagination = new Pagination(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)",
public ConfigCommand(String command, RixaPermission rixaPermission, String description) {
super(command, rixaPermission, description);
pagination = new Pagination(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 set twitterCKey <key> ; Set Twitter Consumer Key!",
"%pconfig set twitterCSecret <key> ; Set Twitter Consumer Secret!",
@ -37,241 +39,253 @@ public class ConfigCommand extends Command {
"%pconfig set twitterASecret <key> ; Set Twitter Access Secret!",
"%config set twitterChannel ; Set the channel for Twitter feed updates!",*/
"%pconfig set joinMessage <joinMessage> ; Set the greetings message for when a user joins the server!",
"%pconfig set quitMessage <quitMessage> ; Set the quit message for when a user leaves the server!",
"%pconfig set joinPm <joinPm> ; Set the message to be private messaged when a user joins!",
"%pconfig set description <description> ; Set your server description!",
"%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!"
), 6);
}
"%pconfig set joinMessage <joinMessage> ; Set the greetings message for when a user joins the server!",
"%pconfig set quitMessage <quitMessage> ; Set the quit message for when a user leaves the server!",
"%pconfig set joinPm <joinPm> ; Set the message to be private messaged when a user joins!",
"%pconfig set description <description> ; Set your server description!",
"%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!"
), 6);
}
@Override
public void execute(String commandLabel, Guild guild, Member member, TextChannel channel, String[] args) {
RixaGuild rixaGuild = GuildManager.getInstance().getGuild(guild);
if (args.length == 2) {
switch (args[0].toLowerCase()) {
case "set":
if (args[1].equalsIgnoreCase("greetings")) {
rixaGuild.getSettings().setGreetings(channel);
MessageFactory.create(channel.getAsMention()).setAuthor("Updated Greetings Channel",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
return;
} else if (args[1].equalsIgnoreCase("farewell")) {
rixaGuild.getSettings().setFarewell(channel);
MessageFactory.create(channel.getAsMention()).setAuthor("Updated Farewell Channel",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
return;
}
}
}
if (args.length < 2) {
sendHelp(member, 1, rixaGuild.getSettings().getPrefix());
@Override
public void execute(String commandLabel, Guild guild, Member member, TextChannel channel,
String[] args) {
RixaGuild rixaGuild = GuildManager.getInstance().getGuild(guild);
if (args.length == 2) {
switch (args[0].toLowerCase()) {
case "set":
if (args[1].equalsIgnoreCase("greetings")) {
rixaGuild.getSettings().setGreetings(channel);
MessageFactory.create(channel.getAsMention()).setAuthor("Updated Greetings Channel",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
return;
}
String string = join(args, 2, args.length);
Role role;
switch (args[0].toLowerCase()) {
case "set":
if (args[1].equalsIgnoreCase("muteRole") ||
args[1].equalsIgnoreCase("musicRole") ||
args[1].equalsIgnoreCase("defaultRole")) {
role = DiscordUtils.searchFirstRole(guild, string);
if (role == null) {
MessageFactory.create("Sorry I could not find that role!")
.setColor(member.getColor()).setTimestamp().queue(channel);
// Role not found
return;
}
switch(args[1].toLowerCase()) {
case "muterole":
rixaGuild.getSettings().setMuteRole(role);
break;
case "musicrole":
((MusicModule) rixaGuild.getModule("Music")).setMusicRole(role);
break;
case "defaultrole":
rixaGuild.getSettings().setDefaultRole(role);
break;
}
// Role set
MessageFactory.create(role.getAsMention()).setAuthor("Updated Role",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("joinMessage")) {
rixaGuild.getSettings().setJoinMessage(string);
MessageFactory.create(string).setAuthor("Updated Join Message",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("quitMessage")) {
rixaGuild.getSettings().setQuitMessage(string);
MessageFactory.create(string).setAuthor("Updated Quit Message",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("joinPm")) {
rixaGuild.getSettings().setJoinPrivateMessage(string);
MessageFactory.create(string).setAuthor("Updated Join Private Message",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("description")) {
rixaGuild.setDescription(string);
MessageFactory.create(string).setAuthor("Updated Guild Server Description",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("prefix")) {
rixaGuild.getSettings().setPrefix(string);
MessageFactory.create(string).setAuthor("Updated Command Prefix",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else {
sendHelp(member, 1, rixaGuild.getSettings().getPrefix());
return;
}
break;
case "enable":
if (rixaGuild.isRegistered(args[1].toLowerCase())) {
rixaGuild.getModule(args[1].toLowerCase()).setEnabled(true);
MessageFactory.create(args[1].toLowerCase()).setAuthor("Module Enabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("joinVerification")) {
rixaGuild.getSettings().setJoinVerification(true);
MessageFactory.create(args[1].toLowerCase()).setAuthor("Module Enabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else {
MessageFactory.create(args[1].toLowerCase()).setAuthor("Module Not Found",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
}
break;
case "disable":
if (rixaGuild.isRegistered(args[1])) {
rixaGuild.getModule(args[1]).setEnabled(false);
MessageFactory.create(args[1]).setAuthor("Module Disabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("joinMessage")) {
rixaGuild.getSettings().setJoinMessage("default_value");
MessageFactory.create(args[1]).setAuthor("Module Disabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("quitMessage")) {
rixaGuild.getSettings().setQuitMessage("default_value");
MessageFactory.create(args[1]).setAuthor("Module Disabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("joinPrivateMessage")) {
rixaGuild.getSettings().setJoinPrivateMessage("default");
MessageFactory.create(args[1]).setAuthor("Module Disabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("joinVerification")) {
rixaGuild.getSettings().setJoinVerification(false);
MessageFactory.create(args[1].toLowerCase()).setAuthor("Module Disabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else {
MessageFactory.create(args[1].toLowerCase()).setAuthor("Module Not Found",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
}
break;
case "addperm":
case "aperm":
case "addpermission":
case "addperms":
case "addpermissions":
RixaPermission permission = searchPerms(args);
if (permission == null) {
MessageFactory.create("That permission does not exist!").setColor(member.getColor()).queue(channel);
return;
}
if (args[1].equalsIgnoreCase("role")) {
role = DiscordUtils.searchFirstRole(guild, string);
if (role == null) {
MessageFactory.create("That role does not exist!").setColor(member.getColor()).queue(channel);
return;
}
rixaGuild.addPermission(role.getId(), permission);
MessageFactory.create("Role: " + role.getAsMention() + " | Permission: " +
permission.toString()).setAuthor("Permission Given",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
return;
}
if (args[1].equalsIgnoreCase("user")) {
List<Member> targets = DiscordUtils.memberSearch(guild, string, false);
if (targets.isEmpty()) {
MessageFactory.create("Could not find that user!").setColor(member.getColor()).queue(channel);
return;
}
RixaUser targetUser = UserManager.getInstance().getUser(targets.get(0).getUser());
targetUser.addPermission(guild.getId(), permission);
MessageFactory.create("User: " + targetUser.getUser().getAsMention() + " | Permission: " +
permission.toString()).setAuthor("Permission Given",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
return;
}
MessageFactory.create("Incorrect Usage! Try " + commandLabel + " addPerm <user/role> <permission>!").setColor(member.getColor())
.queue(channel);
break;
case "removeperm":
case "rperm":
case "removepermissions":
case "removeperms":
permission = searchPerms(args);
if (permission == null) {
MessageFactory.create("That permission does not exist!").setColor(member.getColor()).queue(channel);
return;
}
if (args[1].equalsIgnoreCase("role")) {
role = DiscordUtils.searchFirstRole(guild, string);
if (role == null) {
MessageFactory.create("That role does not exist!").setColor(member.getColor()).queue(channel);
return;
}
rixaGuild.removePermission(role.getId(), permission);
MessageFactory.create("Role: " + role.getAsMention() + " | Permission: " +
permission.toString()).setAuthor("Permission Revoked",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
return;
}
if (args[1].equalsIgnoreCase("user")) {
List<Member> targets = DiscordUtils.memberSearch(guild, string, false);
if (targets.isEmpty()) {
MessageFactory.create("Could not find that user!").setColor(member.getColor()).queue(channel);
return;
}
RixaUser targetUser = UserManager.getInstance().getUser(targets.get(0).getUser());
targetUser.removePermission(guild.getId(), permission);
MessageFactory.create("Role: " + targetUser.getUser().getAsMention() + " | Permission: " +
permission.toString()).setAuthor("Permission Revoked",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
return;
}
MessageFactory.create("Incorrect Usage! Try " + commandLabel + " addPerm <user/role> <permission>!").setColor(member.getColor())
.queue(channel);
break;
default:
sendHelp(member, 1, rixaGuild.getSettings().getPrefix());
break;
}
} else if (args[1].equalsIgnoreCase("farewell")) {
rixaGuild.getSettings().setFarewell(channel);
MessageFactory.create(channel.getAsMention()).setAuthor("Updated Farewell Channel",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
return;
}
}
}
if (args.length < 2) {
sendHelp(member, 1, rixaGuild.getSettings().getPrefix());
return;
}
String string = join(args, 2, args.length);
Role role;
switch (args[0].toLowerCase()) {
case "set":
if (args[1].equalsIgnoreCase("muteRole") ||
args[1].equalsIgnoreCase("musicRole") ||
args[1].equalsIgnoreCase("defaultRole")) {
role = DiscordUtils.searchFirstRole(guild, string);
if (role == null) {
MessageFactory.create("Sorry I could not find that role!")
.setColor(member.getColor()).setTimestamp().queue(channel);
// Role not found
return;
}
switch (args[1].toLowerCase()) {
case "muterole":
rixaGuild.getSettings().setMuteRole(role);
break;
case "musicrole":
((MusicModule) rixaGuild.getModule("Music")).setMusicRole(role);
break;
case "defaultrole":
rixaGuild.getSettings().setDefaultRole(role);
break;
}
// Role set
MessageFactory.create(role.getAsMention()).setAuthor("Updated Role",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("joinMessage")) {
rixaGuild.getSettings().setJoinMessage(string);
MessageFactory.create(string).setAuthor("Updated Join Message",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("quitMessage")) {
rixaGuild.getSettings().setQuitMessage(string);
MessageFactory.create(string).setAuthor("Updated Quit Message",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("joinPm")) {
rixaGuild.getSettings().setJoinPrivateMessage(string);
MessageFactory.create(string).setAuthor("Updated Join Private Message",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("description")) {
rixaGuild.setDescription(string);
MessageFactory.create(string).setAuthor("Updated Guild Server Description",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("prefix")) {
rixaGuild.getSettings().setPrefix(string);
MessageFactory.create(string).setAuthor("Updated Command Prefix",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else {
sendHelp(member, 1, rixaGuild.getSettings().getPrefix());
return;
}
break;
case "enable":
if (rixaGuild.isRegistered(args[1].toLowerCase())) {
rixaGuild.getModule(args[1].toLowerCase()).setEnabled(true);
MessageFactory.create(args[1].toLowerCase()).setAuthor("Module Enabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("joinVerification")) {
rixaGuild.getSettings().setJoinVerification(true);
MessageFactory.create(args[1].toLowerCase()).setAuthor("Module Enabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else {
MessageFactory.create(args[1].toLowerCase()).setAuthor("Module Not Found",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
}
break;
case "disable":
if (rixaGuild.isRegistered(args[1])) {
rixaGuild.getModule(args[1]).setEnabled(false);
MessageFactory.create(args[1]).setAuthor("Module Disabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("joinMessage")) {
rixaGuild.getSettings().setJoinMessage("default_value");
MessageFactory.create(args[1]).setAuthor("Module Disabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("quitMessage")) {
rixaGuild.getSettings().setQuitMessage("default_value");
MessageFactory.create(args[1]).setAuthor("Module Disabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("joinPrivateMessage")) {
rixaGuild.getSettings().setJoinPrivateMessage("default");
MessageFactory.create(args[1]).setAuthor("Module Disabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else if (args[1].equalsIgnoreCase("joinVerification")) {
rixaGuild.getSettings().setJoinVerification(false);
MessageFactory.create(args[1].toLowerCase()).setAuthor("Module Disabled",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} else {
MessageFactory.create(args[1].toLowerCase()).setAuthor("Module Not Found",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
}
break;
case "addperm":
case "aperm":
case "addpermission":
case "addperms":
case "addpermissions":
RixaPermission permission = searchPerms(args);
if (permission == null) {
MessageFactory.create("That permission does not exist!").setColor(member.getColor())
.queue(channel);
return;
}
if (args[1].equalsIgnoreCase("role")) {
role = DiscordUtils.searchFirstRole(guild, string);
if (role == null) {
MessageFactory.create("That role does not exist!").setColor(member.getColor())
.queue(channel);
return;
}
rixaGuild.addPermission(role.getId(), permission);
MessageFactory.create("Role: " + role.getAsMention() + " | Permission: " +
permission.toString()).setAuthor("Permission Given",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
return;
}
if (args[1].equalsIgnoreCase("user")) {
List<Member> targets = DiscordUtils.memberSearch(guild, string, false);
if (targets.isEmpty()) {
MessageFactory.create("Could not find that user!").setColor(member.getColor())
.queue(channel);
return;
}
RixaUser targetUser = UserManager.getInstance().getUser(targets.get(0).getUser());
targetUser.addPermission(guild.getId(), permission);
MessageFactory.create("User: " + targetUser.getUser().getAsMention() + " | Permission: " +
permission.toString()).setAuthor("Permission Given",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
return;
}
MessageFactory
.create("Incorrect Usage! Try " + commandLabel + " addPerm <user/role> <permission>!")
.setColor(member.getColor())
.queue(channel);
break;
case "removeperm":
case "rperm":
case "removepermissions":
case "removeperms":
permission = searchPerms(args);
if (permission == null) {
MessageFactory.create("That permission does not exist!").setColor(member.getColor())
.queue(channel);
return;
}
if (args[1].equalsIgnoreCase("role")) {
role = DiscordUtils.searchFirstRole(guild, string);
if (role == null) {
MessageFactory.create("That role does not exist!").setColor(member.getColor())
.queue(channel);
return;
}
rixaGuild.removePermission(role.getId(), permission);
MessageFactory.create("Role: " + role.getAsMention() + " | Permission: " +
permission.toString()).setAuthor("Permission Revoked",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
return;
}
if (args[1].equalsIgnoreCase("user")) {
List<Member> targets = DiscordUtils.memberSearch(guild, string, false);
if (targets.isEmpty()) {
MessageFactory.create("Could not find that user!").setColor(member.getColor())
.queue(channel);
return;
}
RixaUser targetUser = UserManager.getInstance().getUser(targets.get(0).getUser());
targetUser.removePermission(guild.getId(), permission);
MessageFactory.create("Role: " + targetUser.getUser().getAsMention() + " | Permission: " +
permission.toString()).setAuthor("Permission Revoked",
guild.getIconUrl()).setColor(member.getColor()).queue(channel);
return;
}
MessageFactory
.create("Incorrect Usage! Try " + commandLabel + " addPerm <user/role> <permission>!")
.setColor(member.getColor())
.queue(channel);
break;
default:
sendHelp(member, 1, rixaGuild.getSettings().getPrefix());
break;
}
}
private void sendHelp(Member member, int page, String prefix) {
List<Object> objects = pagination.getPage(page);
MessageFactory messageFactory = MessageFactory.create("\u2699" + " **Config**" +
"\nClick the back or forward reactions to switch between pages.")
.setTitle(String.format("Config: %s", member.getGuild().getId()));
objects.forEach(obj -> {
String object = obj.toString();
messageFactory.addField(object.split(" ; ")[0].replace("%p", prefix),
object.split(" ; ")[1], false);
});
messageFactory.footer("Page: (" + page + " / " + (pagination.getMaxPage()) + ")", member.getGuild().getIconUrl())
private void sendHelp(Member member, int page, String prefix) {
List<Object> objects = pagination.getPage(page);
MessageFactory messageFactory = MessageFactory.create("\u2699" + " **Config**" +
"\nClick the back or forward reactions to switch between pages.")
.setTitle(String.format("Config: %s", member.getGuild().getId()));
objects.forEach(obj -> {
String object = obj.toString();
messageFactory.addField(object.split(" ; ")[0].replace("%p", prefix),
object.split(" ; ")[1], false);
});
messageFactory.footer("Page: (" + page + " / " + (pagination.getMaxPage()) + ")",
member.getGuild().getIconUrl())
.setColor(member.getColor()).selfDestruct(0).send(member.getUser(), success ->
success.addReaction("\u2B05").queue(v -> success.addReaction("\u27A1").queue()));
}
success.addReaction("\u2B05").queue(v -> success.addReaction("\u27A1").queue()));
}
private RixaPermission searchPerms(String[] args) {
for (String stringInArgs : args) {
for (RixaPermission rixaPermission : RixaPermission.values()) {
if (stringInArgs.equalsIgnoreCase(rixaPermission.toString())) {
return rixaPermission;
}
}
private RixaPermission searchPerms(String[] args) {
for (String stringInArgs : args) {
for (RixaPermission rixaPermission : RixaPermission.values()) {
if (stringInArgs.equalsIgnoreCase(rixaPermission.toString())) {
return rixaPermission;
}
return null;
}
}
return null;
}
private String join(Object[] obj, int startIndex, int endIndex) {
return StringUtils.join(obj, " ", startIndex, endIndex);
}
private String join(Object[] obj, int startIndex, int endIndex) {
return StringUtils.join(obj, " ", startIndex, endIndex);
}
}

View File

@ -1,47 +1,98 @@
package io.rixa.bot.commands.cmds.moderator;
import com.dumptruckman.taskmin.Task;
import com.dumptruckman.taskmin.TaskManager;
import io.rixa.bot.commands.Command;
import io.rixa.bot.commands.perms.RixaPermission;
import io.rixa.bot.guild.RixaGuild;
import io.rixa.bot.guild.manager.GuildManager;
import io.rixa.bot.utils.DiscordUtils;
import io.rixa.bot.utils.MessageFactory;
import io.rixa.bot.utils.Utils;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;
public class MuteCommand extends Command {
private RixaPermission rixaPermission;
public MuteCommand(String command, RixaPermission rixaPermission, String description) {
super(command, rixaPermission, description);
this.rixaPermission = rixaPermission;
private RixaPermission rixaPermission;
private TaskManager taskManager;
public MuteCommand(String command, RixaPermission rixaPermission, String description) {
super(command, rixaPermission, description);
this.rixaPermission = rixaPermission;
this.taskManager = TaskManager.createBasicTaskManager();
}
@Override
public void execute(String commandLabel, Guild guild, Member member, TextChannel channel,
String[] args) {
RixaGuild rixaGuild = GuildManager.getInstance().getGuild(guild);
String argumentString = String.join(" ", args);
Object[] objArray = DiscordUtils.memberSearchArray(guild, argumentString, false);
if (objArray.length == 0) {
MessageFactory.create("Could not find member!").setColor(member.getColor()).queue(channel);
return;
}
Member targetMember = (Member) objArray[1];
String targetMemberName = String.valueOf(objArray[0]);
if (targetMember == null) {
MessageFactory.create("Could not find member!").setColor(member.getColor()).queue(channel);
return;
}
argumentString = argumentString.replaceFirst(targetMemberName, "").trim();
args = argumentString.split(" ");
if (args[0].length() == 0) {
// Incorrect Usage
return;
}
String time = args[0].trim();
argumentString = String.join(" ", args).replaceFirst(time, "");
if (argumentString.length() > 255) {
MessageFactory.create(
"Sorry your `reason` exceeds the maximum character length of 255!")
.setColor(member.getColor()).queue(channel);
return;
}
@Override
public void execute(String commandLabel, Guild guild, Member member, TextChannel channel, String[] args) {
// RixaGuild rixaGuild = GuildManager.getInstance().getGuild(guild);
String argumentString = String.join(" ", args);
Object[] objArray = DiscordUtils.memberSearchArray(guild, argumentString, false);
if (objArray.length == 0) {
MessageFactory.create("Could not find member!").setColor(member.getColor()).queue(channel);
return;
}
Member targetMember = (Member) objArray[1];
String targetMemberName = String.valueOf(objArray[0]);
if (targetMember == null) {
MessageFactory.create("Could not find member!").setColor(member.getColor()).queue(channel);
return;
}
argumentString = argumentString.replaceFirst(targetMemberName, "").trim();
args = argumentString.split(" ");
if (args[0].length() == 0) {
// Incorrect Usage
return;
}
String time = args[0].trim();
argumentString = String.join(" ", args).replaceFirst(time, "");
long milliseconds = Utils.toMilliSec(time);
MessageFactory.create("Duration: " + time + "\nReason: " + argumentString + "\nDuration in Milliseconds: " + milliseconds)
.queue(channel);
}
long milliseconds = Utils.toMilliSec(time);
String reason = argumentString;
guild.getController().addRolesToMember(targetMember, rixaGuild.getSettings().getMuteRole())
.queue(onSuccess -> MessageFactory.create(String.format(
"Temporarily muted %s for %s\n Reason: %s",
this.getUser(targetMember.getUser()),
this.getTime(milliseconds),
reason))
.setColor(member.getColor()).setTimestamp().queue(channel),
onFailure -> MessageFactory.create(
"Could not successfully mute user `" + targetMember.getUser().getName() + "#"
+ targetMember.getUser()
.getDiscriminator() + "`. Reason: " + onFailure.getMessage())
.setColor(member.getColor()).setTimestamp().queue(channel));
this.taskManager
.addTask(Task.builder(() ->
guild.getController()
.removeRolesFromMember(targetMember, rixaGuild.getSettings().getMuteRole()).queue())
.executeAt(LocalDateTime.now().plus(milliseconds, ChronoUnit.MILLIS)));
}
private String getTime(long milliseconds) {
long seconds, minutes, hours, days;
seconds = milliseconds / 1000;
minutes = seconds / 60;
seconds = seconds % 60;
hours = minutes / 60;
days = hours / 24;
minutes = minutes % 60;
return(String.format("%s days, %s hours, %s minutes, %s seconds", days, hours, minutes, seconds));
}
private String getUser(User member) {
return member.getName() + "#" + member.getDiscriminator();
}
}

View File

@ -27,6 +27,10 @@ public class UserListener {
.selfDestruct(0).queue(rixaGuild.getSettings().getGreetings());
}
if (!rixaGuild.getSettings().isJoinVerification()) {
if (rixaGuild.getSettings().getDefaultRole() != null) {
event.getGuild().getController()
.addRolesToMember(event.getMember(), rixaGuild.getSettings().getDefaultRole()).queue();
}
return;
}
if (!rixaGuild.getConfirmationUsers().contains(event.getUser().getId())) {

View File

@ -1,123 +1,130 @@
package io.rixa.bot.utils;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.entities.VoiceChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class DiscordUtils {
public static List<Member> memberSearch(Guild guild, String string, boolean bots) {
List<Member> members = new ArrayList<>();
String finalString = string.toLowerCase();
for (Member member : guild.getMembers()) {
if ((member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator()).contains(finalString)
|| (member.getEffectiveName().toLowerCase().contains(finalString))
|| finalString.contains(member.getUser().getId())
|| finalString.contains(member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator())
|| finalString.contains(member.getEffectiveName().toLowerCase())
|| finalString.contains(member.getUser().getName().toLowerCase())
|| finalString.equalsIgnoreCase(member.getEffectiveName().toLowerCase())
|| finalString.equalsIgnoreCase(member.getUser().getName().toLowerCase())) {
public static List<Member> memberSearch(Guild guild, String string, boolean bots) {
List<Member> members = new ArrayList<>();
String finalString = string.toLowerCase();
for (Member member : guild.getMembers()) {
if ((member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator())
.contains(finalString)
|| (member.getEffectiveName().toLowerCase().contains(finalString))
|| finalString.contains(member.getUser().getId())
|| finalString.contains(
member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator())
|| finalString.contains(member.getEffectiveName().toLowerCase())
|| finalString.contains(member.getUser().getName().toLowerCase())
|| finalString.equalsIgnoreCase(member.getEffectiveName().toLowerCase())
|| finalString.equalsIgnoreCase(member.getUser().getName().toLowerCase())) {
if (!bots && member.getUser().isBot()) continue;
members.add(member);
}
if (!bots && member.getUser().isBot()) {
continue;
}
return members;
members.add(member);
}
}
return members;
}
public static Object[] memberSearchArray(Guild guild, String string, boolean bots) {
Object[] array = new Object[2];
// First item is string, second is member
String finalString = string.toLowerCase().trim();
for (Member member : guild.getMembers()) {
//String nameDescrim = member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator().toLowerCase();
if (finalString.contains(member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator())) {
array[0] = member.getEffectiveName();
array[1] = member;
break;
} else if (finalString.contains(member.getUser().getId())) {
array[0] = member.getEffectiveName();
array[1] = member;
break;
}else if (finalString.contains(member.getEffectiveName().toLowerCase())) {
array[0] = member.getEffectiveName();
array[1] = member;
break;
} else if (finalString.contains(member.getUser().getName().toLowerCase())) {
array[0] = member.getEffectiveName();
array[1] = member;
break;
}
}
return array;
public static Object[] memberSearchArray(Guild guild, String string, boolean bots) {
Object[] array = new Object[2];
// First item is string, second is member
String finalString = string.toLowerCase().trim();
for (Member member : guild.getMembers()) {
//String nameDescrim = member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator().toLowerCase();
if (finalString.contains(
member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator())) {
array[0] = member.getEffectiveName();
array[1] = member;
break;
} else if (finalString.contains(member.getUser().getId())) {
array[0] = member.getEffectiveName();
array[1] = member;
break;
} else if (finalString.contains(member.getEffectiveName().toLowerCase())) {
array[0] = member.getEffectiveName();
array[1] = member;
break;
} else if (finalString.contains(member.getUser().getName().toLowerCase())) {
array[0] = member.getEffectiveName();
array[1] = member;
break;
}
}
return array;
}
public static Role searchFirstRole(Guild guild, String s) {
return roleSearch(guild, s).get(0);
public static Role searchFirstRole(Guild guild, String s) {
return roleSearch(guild, s).get(0);
}
public static List<Role> roleSearch(Guild guild, String string) {
List<Role> roles = new ArrayList<>();
guild.getRoles().forEach(role -> {
if (role.getName().equalsIgnoreCase(string)
|| role.getName().toLowerCase().contains(string.toLowerCase())
|| string.contains(role.getId())
|| string.toLowerCase().contains(role.getName().toLowerCase())) {
roles.add(role);
}
});
return roles;
}
public static Role getMentionedRole(Guild guild, String string) {
Role mentionedRole = null;
for (Role role : guild.getRoles()) {
if (string.contains(role.getAsMention()) || string.contains("@" + role.getName())) {
mentionedRole = role;
break;
}
}
return mentionedRole;
}
public static List<Role> roleSearch(Guild guild, String string) {
List<Role> roles = new ArrayList<>();
guild.getRoles().forEach(role -> {
if (role.getName().toLowerCase().contains(string.toLowerCase())
|| string.contains(role.getId())
|| string.toLowerCase().contains(role.getName().toLowerCase()))
roles.add(role);
});
return roles;
public static VoiceChannel voiceChannelSearch(Guild guild, String string) {
List<VoiceChannel> voiceChannels = guild.getVoiceChannelsByName(string, true);
if (!voiceChannels.isEmpty()) {
return voiceChannels.get(0);
}
Optional<VoiceChannel> optional = guild.getVoiceChannels().stream().sorted()
.filter(voiceChannel -> voiceChannel.getId().equalsIgnoreCase(string) ||
voiceChannel.getName().equalsIgnoreCase(string) ||
voiceChannel.getName().contains(string)).findFirst();
return optional.orElse(null);
}
public static Role getMentionedRole(Guild guild, String string) {
Role mentionedRole = null;
for (Role role : guild.getRoles()) {
if (string.contains(role.getAsMention()) || string.contains("@" + role.getName())) {
mentionedRole = role;
break;
}
}
return mentionedRole;
public static int getLevelFromExperience(int xp) {
int level = 0;
while (xp >= getNeededXP(level)) {
xp -= getNeededXP(level);
level++;
}
return level;
}
public static VoiceChannel voiceChannelSearch(Guild guild, String string) {
List<VoiceChannel> voiceChannels = guild.getVoiceChannelsByName(string, true);
if (!voiceChannels.isEmpty()) {
return voiceChannels.get(0);
}
Optional<VoiceChannel> optional = guild.getVoiceChannels().stream().sorted().filter(voiceChannel -> voiceChannel.getId().equalsIgnoreCase(string) ||
voiceChannel.getName().equalsIgnoreCase(string) ||
voiceChannel.getName().contains(string)).findFirst();
return optional.orElse(null);
public static Double getNeededXP(double n) {
if (n < 0) {
return 0.0;
}
return (6 * Math.pow(n, 3) + 119 * n + 100);
}
public static int getRemainingExperience(int xp) {
int level = getLevelFromExperience(xp);
public static int getLevelFromExperience(int xp) {
int level = 0;
while (xp >= getNeededXP(level)) {
xp -= getNeededXP(level);
level++;
}
return level;
}
public static Double getNeededXP(double n) {
if (n < 0) return 0.0;
return (6 * Math.pow(n, 3) + 119 * n + 100);
}
public static int getRemainingExperience(int xp) {
int level = getLevelFromExperience(xp);
for (int i = 0; i < level; i++) {
xp -= getNeededXP(i);
}
return xp;
for (int i = 0; i < level; i++) {
xp -= getNeededXP(i);
}
return xp;
}
}