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

View File

@ -10,26 +10,28 @@ import io.rixa.bot.user.RixaUser;
import io.rixa.bot.user.manager.UserManager; import io.rixa.bot.user.manager.UserManager;
import io.rixa.bot.utils.DiscordUtils; import io.rixa.bot.utils.DiscordUtils;
import io.rixa.bot.utils.MessageFactory; 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.Arrays;
import java.util.List; 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 { public class ConfigCommand extends Command {
private Pagination pagination; private Pagination pagination;
public ConfigCommand(String command, RixaPermission rixaPermission, String description) {
super(command, rixaPermission, description);
pagination = new Pagination(Arrays.asList( public ConfigCommand(String command, RixaPermission rixaPermission, String description) {
"%pconfig set greetings ; Set channel where greeting messages are announced!", super(command, rixaPermission, description);
"%pconfig set farewell ; Set channel where farewell messages are announced!",
"%pconfig set prefix <prefix> ; Set Rixa's command prefix!", pagination = new Pagination(Arrays.asList(
"%pconfig set defaultRole <role> ; Set role to be assigned when a user joins the server!", "%pconfig set greetings ; Set channel where greeting messages are announced!",
"%pconfig set muteRole <role> ; Set role to be assigned when a user is muted!", "%pconfig set farewell ; Set channel where farewell messages are announced!",
"%pconfig set musicRole <musicRole> ; Set role required to use the music functions! (Not required)", "%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 twitterCKey <key> ; Set Twitter Consumer Key!",
"%pconfig set twitterCSecret <key> ; Set Twitter Consumer Secret!", "%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!", "%pconfig set twitterASecret <key> ; Set Twitter Access Secret!",
"%config set twitterChannel ; Set the channel for Twitter feed updates!",*/ "%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 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 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 joinPm <joinPm> ; Set the message to be private messaged when a user joins!",
"%pconfig set description <description> ; Set your server description!", "%pconfig set description <description> ; Set your server description!",
"%pconfig addPerm <role> <permission> ; Give a role permission to access a command!", "%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 removePerm <role> <permission> ; Remove a role's permission to access a command!",
"%pconfig enable <module> ; Enabled a Rixa Module!", "%pconfig enable <module> ; Enabled a Rixa Module!",
"%pconfig disable <module> ; Disable a Rixa Module!" "%pconfig disable <module> ; Disable a Rixa Module!"
), 6); ), 6);
} }
@Override @Override
public void execute(String commandLabel, Guild guild, Member member, TextChannel channel, String[] args) { public void execute(String commandLabel, Guild guild, Member member, TextChannel channel,
RixaGuild rixaGuild = GuildManager.getInstance().getGuild(guild); String[] args) {
if (args.length == 2) { RixaGuild rixaGuild = GuildManager.getInstance().getGuild(guild);
switch (args[0].toLowerCase()) { if (args.length == 2) {
case "set": switch (args[0].toLowerCase()) {
if (args[1].equalsIgnoreCase("greetings")) { case "set":
rixaGuild.getSettings().setGreetings(channel); if (args[1].equalsIgnoreCase("greetings")) {
MessageFactory.create(channel.getAsMention()).setAuthor("Updated Greetings Channel", rixaGuild.getSettings().setGreetings(channel);
guild.getIconUrl()).setColor(member.getColor()).queue(channel); MessageFactory.create(channel.getAsMention()).setAuthor("Updated Greetings Channel",
return; guild.getIconUrl()).setColor(member.getColor()).queue(channel);
} 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; return;
} } else if (args[1].equalsIgnoreCase("farewell")) {
String string = join(args, 2, args.length); rixaGuild.getSettings().setFarewell(channel);
Role role; MessageFactory.create(channel.getAsMention()).setAuthor("Updated Farewell Channel",
switch (args[0].toLowerCase()) { guild.getIconUrl()).setColor(member.getColor()).queue(channel);
case "set": return;
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;
}
} }
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) { private void sendHelp(Member member, int page, String prefix) {
List<Object> objects = pagination.getPage(page); List<Object> objects = pagination.getPage(page);
MessageFactory messageFactory = MessageFactory.create("\u2699" + " **Config**" + MessageFactory messageFactory = MessageFactory.create("\u2699" + " **Config**" +
"\nClick the back or forward reactions to switch between pages.") "\nClick the back or forward reactions to switch between pages.")
.setTitle(String.format("Config: %s", member.getGuild().getId())); .setTitle(String.format("Config: %s", member.getGuild().getId()));
objects.forEach(obj -> { objects.forEach(obj -> {
String object = obj.toString(); String object = obj.toString();
messageFactory.addField(object.split(" ; ")[0].replace("%p", prefix), messageFactory.addField(object.split(" ; ")[0].replace("%p", prefix),
object.split(" ; ")[1], false); object.split(" ; ")[1], false);
}); });
messageFactory.footer("Page: (" + page + " / " + (pagination.getMaxPage()) + ")", member.getGuild().getIconUrl()) messageFactory.footer("Page: (" + page + " / " + (pagination.getMaxPage()) + ")",
member.getGuild().getIconUrl())
.setColor(member.getColor()).selfDestruct(0).send(member.getUser(), success -> .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) { private RixaPermission searchPerms(String[] args) {
for (String stringInArgs : args) { for (String stringInArgs : args) {
for (RixaPermission rixaPermission : RixaPermission.values()) { for (RixaPermission rixaPermission : RixaPermission.values()) {
if (stringInArgs.equalsIgnoreCase(rixaPermission.toString())) { if (stringInArgs.equalsIgnoreCase(rixaPermission.toString())) {
return rixaPermission; return rixaPermission;
}
}
} }
return null; }
} }
return null;
}
private String join(Object[] obj, int startIndex, int endIndex) { private String join(Object[] obj, int startIndex, int endIndex) {
return StringUtils.join(obj, " ", startIndex, endIndex); return StringUtils.join(obj, " ", startIndex, endIndex);
} }
} }

View File

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

View File

@ -1,123 +1,130 @@
package io.rixa.bot.utils; 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.Guild;
import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Role; import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.entities.VoiceChannel; 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 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())) {
if (!bots && member.getUser().isBot()) continue; public static List<Member> memberSearch(Guild guild, String string, boolean bots) {
members.add(member); 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;
} }
return members; members.add(member);
}
} }
return members;
}
public static Object[] memberSearchArray(Guild guild, String string, boolean bots) { public static Object[] memberSearchArray(Guild guild, String string, boolean bots) {
Object[] array = new Object[2]; Object[] array = new Object[2];
// First item is string, second is member // First item is string, second is member
String finalString = string.toLowerCase().trim(); String finalString = string.toLowerCase().trim();
for (Member member : guild.getMembers()) { for (Member member : guild.getMembers()) {
//String nameDescrim = member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator().toLowerCase(); //String nameDescrim = member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator().toLowerCase();
if (finalString.contains(member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator())) { if (finalString.contains(
array[0] = member.getEffectiveName(); member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator())) {
array[1] = member; array[0] = member.getEffectiveName();
break; array[1] = member;
} else if (finalString.contains(member.getUser().getId())) { break;
array[0] = member.getEffectiveName(); } else if (finalString.contains(member.getUser().getId())) {
array[1] = member; array[0] = member.getEffectiveName();
break; array[1] = member;
}else if (finalString.contains(member.getEffectiveName().toLowerCase())) { break;
array[0] = member.getEffectiveName(); } else if (finalString.contains(member.getEffectiveName().toLowerCase())) {
array[1] = member; array[0] = member.getEffectiveName();
break; array[1] = member;
} else if (finalString.contains(member.getUser().getName().toLowerCase())) { break;
array[0] = member.getEffectiveName(); } else if (finalString.contains(member.getUser().getName().toLowerCase())) {
array[1] = member; array[0] = member.getEffectiveName();
break; array[1] = member;
} break;
} }
return array;
} }
return array;
}
public static Role searchFirstRole(Guild guild, String s) { public static Role searchFirstRole(Guild guild, String s) {
return roleSearch(guild, s).get(0); 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) { public static VoiceChannel voiceChannelSearch(Guild guild, String string) {
List<Role> roles = new ArrayList<>(); List<VoiceChannel> voiceChannels = guild.getVoiceChannelsByName(string, true);
guild.getRoles().forEach(role -> { if (!voiceChannels.isEmpty()) {
if (role.getName().toLowerCase().contains(string.toLowerCase()) return voiceChannels.get(0);
|| string.contains(role.getId())
|| string.toLowerCase().contains(role.getName().toLowerCase()))
roles.add(role);
});
return roles;
} }
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; public static int getLevelFromExperience(int xp) {
for (Role role : guild.getRoles()) { int level = 0;
if (string.contains(role.getAsMention()) || string.contains("@" + role.getName())) { while (xp >= getNeededXP(level)) {
mentionedRole = role; xp -= getNeededXP(level);
break; level++;
}
}
return mentionedRole;
} }
return level;
}
public static VoiceChannel voiceChannelSearch(Guild guild, String string) { public static Double getNeededXP(double n) {
List<VoiceChannel> voiceChannels = guild.getVoiceChannelsByName(string, true); if (n < 0) {
if (!voiceChannels.isEmpty()) { return 0.0;
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);
} }
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++) {
public static int getLevelFromExperience(int xp) { xp -= getNeededXP(i);
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;
} }
return xp;
}
} }