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;
}
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);
}
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.";
}
}
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));
}
Aggregations