Added Modules Command, Features command and made config sub commands more consistent (Issue #6)

This commit is contained in:
Savvy 2017-10-03 08:57:35 -04:00
parent c6b613eae6
commit def00258d4
8 changed files with 162 additions and 46 deletions

View File

@ -136,7 +136,8 @@ public class Rixa {
new BatchMoveCommand(), new MuteCommand(), new MusicCommand(),
new ConfigCommand(), new UrbanDictionaryCommand(), new YoutubeCommand(),
new AddRoleCommand(), new RemoveRoleCommand(), new LevelsCommand(),
new LeaderboardCommand(), new RaidModeCommand(), new OwnerCommand(), new ColorCommand());
new LeaderboardCommand(), new RaidModeCommand(), new OwnerCommand(),
new ColorCommand(), new ModulesCommand());
register(new HelpReaction(), new ConfigReaction(), new LeaderboardReaction());
}

View File

@ -40,10 +40,10 @@ public class ConfigCommand implements CommandExec {
"%pconfig set twitterASecret <key> ; Set Twitter Access Secret!",
"%config set twitterChannel ; Set the channel for Twitter feed updates!",
"%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 description <description> ; Set your server description!",
"%pconfig set tjoinMessage <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!",
@ -87,43 +87,43 @@ public class ConfigCommand implements CommandExec {
return;
}
String message;
if (messages[1].equalsIgnoreCase("joinmessage")) {
message = getMessage(messages);
if(event.getMessage().getMentionedChannels().size() > 0) {
for (TextChannel messageChannel : event.getMessage().getMentionedChannels()) {
message = message.replace(messageChannel.getAsMention(), "<#" + messageChannel.getId() + ">");
if (messages[1].equalsIgnoreCase("set")) {
if (messages[2].equalsIgnoreCase("joinpm")) {
message = getMessage(messages);
if(event.getMessage().getMentionedChannels().size() > 0) {
for (TextChannel messageChannel : event.getMessage().getMentionedChannels()) {
message = message.replace(messageChannel.getAsMention(), "<#" + messageChannel.getId() + ">");
}
}
}
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);
if(event.getMessage().getMentionedChannels().size() > 0) {
for (TextChannel messageChannel : event.getMessage().getMentionedChannels()) {
message = message.replace(messageChannel.getAsMention(), "<#" + messageChannel.getId() + ">");
}
}
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);
if(event.getMessage().getMentionedChannels().size() > 0) {
for (TextChannel messageChannel : event.getMessage().getMentionedChannels()) {
message = message.replace(messageChannel.getAsMention(), "<#" + messageChannel.getId() + ">");
}
}
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("description")) {
message = getMessage(messages);
rixaGuild.getGuildSettings().setDescription(message);
new MessageBuilder("Successfully set Server Description 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().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[2].equalsIgnoreCase("description")) {
message = getMessage(messages);
rixaGuild.getGuildSettings().setDescription(message);
new MessageBuilder("Successfully set Server Description to\n" + message.replace("{0}", event.getMember().getUser().getName())
.replace("{1}", event.getGuild().getName())).setColor(event.getMember().getColor()).queue(event.getChannel());
} else if (messages[2].equalsIgnoreCase("joinmessage")) {
message = getMessage(messages);
if(event.getMessage().getMentionedChannels().size() > 0) {
for (TextChannel messageChannel : event.getMessage().getMentionedChannels()) {
message = message.replace(messageChannel.getAsMention(), "<#" + messageChannel.getId() + ">");
}
}
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[2].equalsIgnoreCase("quitmessage")) {
message = getMessage(messages);
if(event.getMessage().getMentionedChannels().size() > 0) {
for (TextChannel messageChannel : event.getMessage().getMentionedChannels()) {
message = message.replace(messageChannel.getAsMention(), "<#" + messageChannel.getId() + ">");
}
}
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[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")) {
@ -287,7 +287,7 @@ public class ConfigCommand implements CommandExec {
private String getMessage(String[] messages) {
StringBuilder builder = new StringBuilder();
for(int i = 2; i < messages.length; i++) {
for(int i = 3; i < messages.length; i++) {
builder.append(messages[i]).append(" ");
}
return builder.toString().trim();
@ -296,4 +296,4 @@ public class ConfigCommand implements CommandExec {
public static ConfigCommand getInstance() {
return instance;
}
}
}

View File

@ -0,0 +1,28 @@
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.management.Guilds;
import me.savvy.rixa.utils.MessageBuilder;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
/**
* Created by Timber on 5/23/2017.
*/
public class FeaturesCommand implements CommandExec {
@Override
@Command(mainCommand = "features",
description = "List Rixa Features!",
channelType = ChannelType.TEXT)
public void execute(GuildMessageReceivedEvent event) {
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
String[] features = {};
new MessageBuilder(
features.length == 0 ? "There are currently no features listed." :
"Rixa Features: " + String.join("\n", features
)).setColor(event.getMember().getColor()).complete(event.getChannel());
}
}

View File

@ -0,0 +1,24 @@
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.management.Guilds;
import me.savvy.rixa.utils.MessageBuilder;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
/**
* Created by Timber on 5/23/2017.
*/
public class ModulesCommand implements CommandExec {
@Override
@Command(mainCommand = "modules",
description = "List Rixa Modules!",
channelType = ChannelType.TEXT)
public void execute(GuildMessageReceivedEvent event) {
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
new MessageBuilder("Available Rixa Modules: " + String.join(",", rixaGuild.getModules().keySet())).setColor(event.getMember().getColor()).complete(event.getChannel());
}
}

View File

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

View File

@ -0,0 +1,63 @@
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.management.Guilds;
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 UnmuteCommand implements CommandExec {
@Override
@Command(mainCommand = "unmute",
description = "Unmute a member.",
type = CommandType.MOD,
channelType = ChannelType.TEXT)
public void execute(GuildMessageReceivedEvent event) {
RixaGuild rixaGuild = Guilds.getGuild(event.getGuild());
if(!rixaGuild.hasPermission(event.getMember(), RixaPermission.UNMUTE)) {
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;
}
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())) {
Role muteRole = event.getGuild().getRoleById(rixaGuild.getGuildSettings().getMuteRole());
if(muteRole != null) {
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 {
new MessageBuilder( muted.getEffectiveName() + ", is not muted.").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());
}
}
}

View File

@ -21,8 +21,7 @@ public enum DatabaseTables {
PERMISSIONS("CREATE TABLE IF NOT EXISTS `permissions` ( `role_id` varchar(255) NOT NULL, `guild_id` varchar(255) NOT NULL, `MUTE` tinyint(1) NOT NULL DEFAULT '0'," +
" `ADD_ROLE` tinyint(1) NOT NULL DEFAULT '0', `REMOVE_ROLE` tinyint(1) NOT NULL DEFAULT '0', `CLEAR_CHAT` tinyint(1) NOT NULL DEFAULT '0'," +
" `ACCESS_CONFIG` tinyint(1) NOT NULL DEFAULT '0', `PM_MESSAGE` tinyint(1) NOT NULL DEFAULT '0', `KICK_MEMBER` tinyint(1) NOT NULL DEFAULT '0'," +
" `BAN_MEMBER` tinyint(1) NOT NULL DEFAULT '0', `TOGGLE_RAIDMODE` tinyint(4) NOT NULL DEFAULT '0'\n" +
");"),
" `BAN_MEMBER` tinyint(1) NOT NULL DEFAULT '0', `TOGGLE_RAIDMODE` tinyint(4) NOT NULL DEFAULT '0, `UNMUTE` tinyint(1) NOT NULL DEFAULT '0');"),
POLLS("CREATE TABLE IF NOT EXISTS `polls` ( `id` int(9) NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` varchar(255) NOT NULL, `description` text," +
" `option_1` varchar(255) DEFAULT NULL, `option_2` varchar(255) DEFAULT NULL, `option_3` varchar(255) DEFAULT NULL," +

View File

@ -165,6 +165,7 @@ public class RixaGuild {
}
public void unmuteMember(User user) {
if (mutedMembers.contains(user.getId()))
mutedMembers.remove(user.getId());
}