use of com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.
the class MentionCommand method getArgs.
@Override
public String getArgs(String args, CommandObject command) {
SplitFirstObject mention = new SplitFirstObject(args);
SplitFirstObject call = new SplitFirstObject(mention.getRest());
if (call.getRest() == null) {
return "";
}
return call.getRest();
}
use of com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.
the class MentionCommand method isCall.
@Override
public boolean isCall(String args, CommandObject command) {
if (command.guild.client.bot == null) {
command.guild.sendDebugLog(command, "MENTION_COMMAND", "BOT_NULL", command.message.getContent());
return false;
}
SplitFirstObject mention = new SplitFirstObject(args);
if (mention.getRest() == null) {
return false;
}
List<IUser> users = command.message.getMentions();
IUser bot = command.client.bot.get();
if (bot == null || !users.contains(bot)) {
return false;
}
SplitFirstObject call = new SplitFirstObject(mention.getRest());
for (String s : names) {
String regex = "^(<@|<@!)" + command.client.bot.longID + "> " + s.toLowerCase();
String toMatch = mention.getFirstWord() + " " + call.getFirstWord().toLowerCase();
Matcher matcher = Pattern.compile(regex).matcher(toMatch);
if (matcher.matches()) {
return true;
}
}
return false;
}
use of com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.
the class EditCC 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 modification of custom commands.";
}
SplitFirstObject getName = new SplitFirstObject(args);
String rest = getName.getRest();
if (rest == null) {
rest = "";
}
if (command.message.get().getAttachments().size() != 0) {
String testLink = command.message.get().getAttachments().get(0).getUrl();
if (Utility.isImageLink(testLink)) {
if (rest.length() > 0) {
rest += " ";
}
rest += "<embedImage>{" + testLink + "}";
} else {
return "> Custom command attachment must be a valid Image.";
}
}
SplitFirstObject getMode = new SplitFirstObject(rest);
String mode = getMode.getFirstWord();
String content = getMode.getRest();
CCommandObject customCommand = command.guild.customCommands.getCommand(getName.getFirstWord());
if (customCommand == null) {
return "> Command Not found.";
}
boolean canBypass = GuildHandler.testForPerms(command, Permissions.MANAGE_MESSAGES);
boolean isAuthor = command.user.longID == customCommand.getUserID();
// test if can edit
if ((customCommand.isLocked() && !canBypass) || (!canBypass && !isAuthor)) {
return "> You do not have permission to edit this command.";
}
if (command.guild.customCommands.checkblackList(args) != null) {
return command.guild.customCommands.checkblackList(args);
}
if (customCommand.isLocked() && !canBypass) {
return "> This command is locked and cannot be edited.";
}
switch(mode.toLowerCase()) {
case "replace":
return CCEditModes.replace(customCommand, content, command);
case "toembed":
return CCEditModes.toEmbed(customCommand);
case "append":
return CCEditModes.append(customCommand, content, command);
case "delet":
case "delcall":
return CCEditModes.deleteTag(customCommand);
case "shitpost":
return CCEditModes.shitPost(customCommand, command, command.user.get(), command.guild.get());
case "lock":
return CCEditModes.lock(customCommand, command, command.user.get(), command.guild.get());
case "addsearch":
return CCEditModes.addSearchTag(customCommand, content);
case "removesearch":
return CCEditModes.removeSearchTag(customCommand, content);
default:
if (content == null || content.isEmpty()) {
return CCEditModes.replace(customCommand, mode, command);
} else {
return CCEditModes.replace(customCommand, mode + " " + content, command);
}
}
}
use of com.github.vaerys.objects.SplitFirstObject 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 com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.
the class EventSetup method addAvatar.
private String addAvatar(TimedEvent event, String rest, CommandObject command) {
if (rest == null) {
return imageAvatar(event, command, null);
}
SplitFirstObject daySplit = new SplitFirstObject(rest);
DayOfWeek day;
try {
day = DayOfWeek.valueOf(daySplit.getFirstWord().toUpperCase());
} catch (IllegalArgumentException e) {
return "> Invalid Day.";
}
if (daySplit.getRest() == null) {
return imageAvatar(event, command, day);
} else {
String url = daySplit.getRest();
if (Utility.isImageLink(url) && !url.endsWith(".gif")) {
return event.setAvatar(url, day);
} else
return "> Invalid Image.";
}
}
Aggregations