Search in sources :

Example 41 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project DiscordSailv2 by Vaerys-Dawn.

the class CustomCommands method sendCCasJSON.

@Deprecated
public String sendCCasJSON(long channelID, String commandName) {
    IChannel channel = Globals.getClient().getChannelByID(channelID);
    for (CCommandObject c : commands) {
        if (c.getName().equalsIgnoreCase(commandName)) {
            FileHandler.writeToJson(Constants.DIRECTORY_TEMP + c.getName() + ".json", c);
            File file = new File(Constants.DIRECTORY_TEMP + c.getName() + ".json");
            if (RequestHandler.sendFile("> Here is the Raw Data for Custom Command: **" + c.getName() + "**", file, channel).get() == null) {
                RequestHandler.sendMessage("> An error occurred when attempting to getSlashCommands CC data.", channel);
            }
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                Utility.sendStack(e);
            }
            file.delete();
            return null;
        }
    }
    RequestHandler.sendMessage(Constants.ERROR_CC_NOT_FOUND, channel);
    return null;
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) IChannel(sx.blah.discord.handle.obj.IChannel) GuildFile(com.github.vaerys.templates.GuildFile) File(java.io.File)

Example 42 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project DiscordSailv2 by Vaerys-Dawn.

the class NewCC method execute.

@Override
public String execute(String args, CommandObject command) {
    ProfileObject object = command.guild.users.getUserByID(command.user.longID);
    if (object != null && object.getSettings().contains(UserSetting.DENY_MAKE_CC)) {
        return "> " + command.user.mention() + ", You have been denied the creation of custom commands.";
    }
    if (command.guild.getChannelsByType(ChannelSetting.CC_DENIED).contains(command.channel.get()))
        return "> This Channel has CCs Denied, You cannot create ccs here.";
    boolean isShitpost = false;
    boolean isLocked = false;
    SplitFirstObject splitFirst = new SplitFirstObject(args);
    List<IChannel> shitpostChannels = command.guild.getChannelsByType(ChannelSetting.SHITPOST);
    if (shitpostChannels != null) {
        for (IChannel channel : shitpostChannels) {
            if (command.channel.longID == channel.getLongID()) {
                isShitpost = true;
            }
        }
    }
    if (object.getSettings().contains(UserSetting.AUTO_SHITPOST)) {
        isShitpost = true;
    }
    String nameCC = splitFirst.getFirstWord();
    String argsCC = splitFirst.getRest();
    if (handleNameFilter(command, nameCC)) {
        return "> Custom Commands cannot have the same name as built-in commands.";
    }
    if ((argsCC == null || argsCC.isEmpty()) && command.message.get().getAttachments().size() == 0) {
        return "> Custom command contents cannot be blank.";
    }
    if (command.message.get().getAttachments().size() != 0) {
        String testLink = command.message.get().getAttachments().get(0).getUrl();
        if (Utility.isImageLink(testLink)) {
            if (argsCC == null || argsCC.isEmpty()) {
                argsCC = "<embedImage>{" + testLink + "}";
            } else {
                argsCC += "<embedImage>{" + testLink + "}";
            }
        } else {
            return "> Custom command attachment must be a valid Image.";
        }
    }
    if (nameCC.contains("\n")) {
        return "> Command name cannot contain Newlines.";
    }
    if (argsCC.contains("<shitpost>")) {
        argsCC.replace("<shitpost>", "");
        isShitpost = true;
    }
    if (argsCC.contains("<lock>") && GuildHandler.testForPerms(command, Permissions.MANAGE_MESSAGES)) {
        argsCC.replace("<lock>", "");
        isLocked = true;
    }
    return command.guild.customCommands.addCommand(isLocked, nameCC, argsCC, isShitpost, command);
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) ProfileObject(com.github.vaerys.objects.ProfileObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 43 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project DiscordSailv2 by Vaerys-Dawn.

the class TransferCC method execute.

@Override
public String execute(String args, CommandObject command) {
    String filePath = Constants.DIRECTORY_OLD_FILES + command.guild.longID + "_CustomCommands.json";
    IGuild guild = command.guild.get();
    IUser author = command.user.get();
    IChannel channel = command.channel.get();
    CustomCommands customCommands = command.guild.customCommands;
    if (Paths.get(filePath).toFile().exists()) {
        com.github.vaerys.oldcode.CustomCommands oldCommands = null;
        if (oldCommands == null) {
            oldCommands = (com.github.vaerys.oldcode.CustomCommands) FileHandler.readFromJson(filePath, com.github.vaerys.oldcode.CustomCommands.class);
        }
        CCommandObject transfering = oldCommands.convertCommand(args);
        if (transfering == null) {
            return Constants.ERROR_CC_NOT_FOUND;
        }
        boolean locked = transfering.isLocked();
        long userID = transfering.getUserID();
        if (guild.getUserByID(userID) == null) {
            RequestHandler.sendMessage("> This command's old owner no longer is part of this server.\n" + Constants.PREFIX_INDENT + author.getDisplayName(guild) + " will become the new owner of this command.\n" + "> I am now attempting to transfer the command over.", channel);
            userID = author.getLongID();
        } else {
            RequestHandler.sendMessage("> I am now attempting to transfer " + guild.getUserByID(userID).getDisplayName(guild) + "'s command.", channel);
        }
        String name = transfering.getName();
        String contents = transfering.getContents(false);
        contents = contents.replace("#author!#", "#username#");
        boolean shitpost = transfering.isShitPost();
        command.setAuthor(Globals.getClient().getUserByID(userID));
        return customCommands.addCommand(locked, name, contents, shitpost, command);
    } else {
        return "> Your Server has no Legacy commands to transfer.";
    }
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) IChannel(sx.blah.discord.handle.obj.IChannel) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild) CustomCommands(com.github.vaerys.pogos.CustomCommands)

Example 44 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project Shadbot by Shadorc.

the class ChannelSetting method execute.

@Override
public void execute(Context context, String arg) throws MissingArgumentException, IllegalCmdArgumentException {
    if (arg == null) {
        throw new MissingArgumentException();
    }
    List<String> splitArgs = StringUtils.split(arg);
    if (splitArgs.size() < 2) {
        throw new MissingArgumentException();
    }
    List<IChannel> mentionedChannels = context.getMessage().getChannelMentions();
    if (mentionedChannels.isEmpty()) {
        throw new MissingArgumentException();
    }
    Action action = Utils.getValueOrNull(Action.class, splitArgs.get(0));
    if (action == null) {
        throw new IllegalCmdArgumentException(String.format("`%s` is not a valid action. %s", splitArgs.get(0), FormatUtils.formatOptions(Action.class)));
    }
    DBGuild dbGuild = Database.getDBGuild(context.getGuild());
    List<Long> allowedChannelsList = dbGuild.getAllowedChannels();
    if (Action.ADD.equals(action)) {
        if (allowedChannelsList.isEmpty() && mentionedChannels.stream().noneMatch(channel -> channel.getLongID() == context.getChannel().getLongID())) {
            BotUtils.sendMessage(Emoji.WARNING + " You did not mentioned this channel. " + "I will not reply here until this channel is added to the list of allowed channels.", context.getChannel());
        }
        allowedChannelsList.addAll(mentionedChannels.stream().map(IChannel::getLongID).filter(channelID -> !allowedChannelsList.contains(channelID)).collect(Collectors.toList()));
        BotUtils.sendMessage(String.format(Emoji.CHECK_MARK + " Channel %s added to allowed channels.", FormatUtils.format(mentionedChannels, IChannel::mention, ", ")), context.getChannel());
    } else {
        allowedChannelsList.removeAll(mentionedChannels.stream().map(IChannel::getLongID).collect(Collectors.toList()));
        BotUtils.sendMessage(String.format(Emoji.CHECK_MARK + " Channel %s removed from allowed channels.", FormatUtils.format(mentionedChannels, IChannel::mention, ", ")), context.getChannel());
    }
    dbGuild.setSetting(this.getSetting(), new JSONArray(allowedChannelsList));
}
Also used : IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) SettingEnum(me.shadorc.shadbot.command.admin.setting.core.SettingEnum) DBGuild(me.shadorc.shadbot.data.db.DBGuild) AbstractSetting(me.shadorc.shadbot.command.admin.setting.core.AbstractSetting) FormatUtils(me.shadorc.shadbot.utils.FormatUtils) Collectors(java.util.stream.Collectors) BotUtils(me.shadorc.shadbot.utils.BotUtils) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) StringUtils(me.shadorc.shadbot.utils.StringUtils) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) List(java.util.List) Context(me.shadorc.shadbot.core.command.Context) Database(me.shadorc.shadbot.data.db.Database) IChannel(sx.blah.discord.handle.obj.IChannel) Setting(me.shadorc.shadbot.command.admin.setting.core.Setting) Emoji(me.shadorc.shadbot.utils.object.Emoji) EmbedUtils(me.shadorc.shadbot.utils.embed.EmbedUtils) JSONArray(org.json.JSONArray) Utils(me.shadorc.shadbot.utils.Utils) IChannel(sx.blah.discord.handle.obj.IChannel) DBGuild(me.shadorc.shadbot.data.db.DBGuild) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) JSONArray(org.json.JSONArray)

Aggregations

IChannel (sx.blah.discord.handle.obj.IChannel)44 IGuild (sx.blah.discord.handle.obj.IGuild)7 IRole (sx.blah.discord.handle.obj.IRole)7 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)7 SQLException (java.sql.SQLException)6 IUser (sx.blah.discord.handle.obj.IUser)6 ProfileObject (com.github.vaerys.objects.ProfileObject)5 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 CommandObject (com.github.vaerys.commands.CommandObject)3 ChannelSetting (com.github.vaerys.enums.ChannelSetting)3 StringHandler (com.github.vaerys.handlers.StringHandler)3 UserObject (com.github.vaerys.masterobjects.UserObject)3 CCommandObject (com.github.vaerys.objects.CCommandObject)3 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)3 IOException (java.io.IOException)3 DBGuild (me.shadorc.shadbot.data.db.DBGuild)3