Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private boolean handleCommand(CommandObject command, String args) {
- List<Command> commands;
- IChannel currentChannel = command.channel.get();
- String commandArgs;
- if (command.channel.get().isPrivate()) {
- commands = new ArrayList<>(Globals.getCommands(true));
- } else {
- commands = new ArrayList<>(Globals.getCommands(false));
- }
- for (Command c : commands) {
- if (c.isCall(args, command)) {
- commandArgs = c.getArgs(args, command);
- //log command
- logger.debug(Utility.loggingFormatter(command));
- //test if user has permissions
- if (!Utility.testForPerms(c.perms(), command.user.get(), command.guild.get())) {
- Utility.sendMessage(command.user.notAllowed, currentChannel);
- return true;
- }
- //check if it is a valid channel
- if (c.channel() != null && !Utility.canBypass(command.user.get(), command.guild.get())) {
- List<IChannel> channels = command.guild.config.getChannelsByType(c.channel(), command.guild);
- if (!channels.contains(command.channel.get())) {
- List<String> list = Utility.getChannelMentions(Utility.getVisibleChannels(channels, command.user));
- if (list.size() == 0) {
- Utility.sendMessage("> You do not have access to any channels that you are able to run this command in.", currentChannel);
- } else if (list.size() > 1) {
- Utility.sendMessage("> Command must be performed in any of the following channels: \n" + Utility.listFormatter(list, true), currentChannel);
- } else {
- Utility.sendMessage("> Command must be performed in: " + list.get(0), currentChannel);
- }
- return true;
- }
- }
- if (c.requiresArgs() && commandArgs.isEmpty()) {
- Utility.sendMessage(Utility.getCommandInfo(c, command), currentChannel);
- return true;
- }
- //command logging
- handleLogging(command, c, commandArgs);
- if (!command.channel.get().getTypingStatus()) {
- command.channel.get().toggleTypingStatus();
- }
- try {
- Utility.sendMessage(c.execute(args, command), currentChannel);
- } catch (Exception e) {
- Utility.sendMessage("> I caught an Error, Please send this to my **Direct Messages** so my developer can look at it.\n```\n"
- + e.getClass().getName() + ": " + e.getMessage() + "```", currentChannel);
- Utility.sendStack(e);
- }
- }
- }
- return false;
- //Old Command Handler
- IChannel channel = commandObject.channel.get();
- GuildConfig guildconfig = commandObject.guild.config;
- List<Command> commands = commandObject.guild.commands;
- IDiscordClient client = commandObject.client.get();
- for (Command c : commands) {
- for (String name : c.names()) {
- if (command.equalsIgnoreCase(guildconfig.getPrefixCommand() + name)) {
- if (c.type().equals(Command.TYPE_CREATOR) && !commandObject.user.stringID.equalsIgnoreCase(Globals.creatorID)) {
- return false;
- }
- logger.debug(Utility.loggingFormatter("COMMAND", command, args, commandObject));
- //permissions checking
- if (c.perms().length != 0 && !Utility.canBypass(commandObject.user.get(), commandObject.guild.get())) {
- if (!Utility.testForPerms(c.perms(), commandObject.user.get(), commandObject.guild.get())) {
- Utility.sendMessage(commandObject.user.notAllowed, channel);
- return false;
- }
- }
- //channel checking
- if (c.channel() != null && !Utility.canBypass(commandObject.user.get(), commandObject.guild.get())) {
- boolean channelFound = false;
- List<String> channelMentions = new ArrayList<>();
- for (ChannelSetting s : commandObject.guild.channelSettings) {
- if (s.type().equals(c.channel())) {
- if (s.getIDs(commandObject.guild.config) != null) {
- for (String id : s.getIDs(commandObject.guild.config)) {
- if (id.equals(commandObject.channel.stringID)) {
- channelFound = true;
- }
- IChannel testPerms = client.getChannelByID(id);
- EnumSet<Permissions> userPerms = testPerms.getModifiedPermissions(commandObject.user.get());
- if (userPerms.contains(Permissions.SEND_MESSAGES) && userPerms.contains(Permissions.READ_MESSAGES)) {
- channelMentions.add(commandObject.client.get().getChannelByID(id).mention());
- }
- }
- } else {
- channelFound = true;
- }
- }
- }
- //correct channel message formatting
- if (!channelFound) {
- if (channelMentions.size() == 0) {
- Utility.sendMessage("> You do not have access to any channels that you are able to run this command in.", channel);
- } else if (channelMentions.size() > 1) {
- Utility.sendMessage("> Command must be performed in any of the following channels: \n" + Utility.listFormatter(channelMentions, true), channel);
- } else {
- Utility.sendMessage("> Command must be performed in: " + channelMentions.get(0), channel);
- }
- return channelFound;
- }
- }
- //arguments checking.
- if (c.requiresArgs() && args.isEmpty()) {
- Utility.sendMessage(Utility.getCommandInfo(c, commandObject), channel);
- return false;
- }
- //command logging
- if (c.doAdminLogging()) {
- if (guildconfig.adminLogging) {
- handleLogging(commandObject, args, c, true);
- }
- } else {
- if (guildconfig.generalLogging) {
- handleLogging(commandObject, args, c, false);
- }
- }
- if (!commandObject.channel.get().getTypingStatus()) {
- commandObject.channel.get().toggleTypingStatus();
- }
- try {
- Utility.sendMessage(c.execute(args, commandObject), channel);
- } catch (Exception e) {
- Utility.sendMessage("> I caught an Error, Please send this to my **Direct Messages** so my developer can look at it.\n```\n"
- + e.getClass().getName() + ": " + e.getMessage() + "```", channel);
- Utility.sendStack(e);
- }
- }
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement