Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void handleCommand(CommandObject commandObject, String command, String args) {
- 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;
- }
- 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;
- }
- }
- //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;
- }
- }
- //arguments checking.
- if (c.requiresArgs() && args.isEmpty()) {
- Utility.sendMessage(Utility.getCommandInfo(c, commandObject), channel);
- return;
- }
- //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);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment