use of com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.
the class DailyMsg method execute.
@Override
public String execute(String args, CommandObject command) {
SplitFirstObject uIDString = new SplitFirstObject(args);
try {
long uID = Long.parseLong(uIDString.getFirstWord());
DailyMessage messageObject = null;
for (DailyMessage u : Globals.getDailyMessages().getMessages()) {
if (u.getUID() == uID) {
messageObject = u;
}
}
if (messageObject == null) {
return "> Could not find daily message with that UID.";
}
SplitFirstObject mode = null;
String totest;
if (uIDString.getRest() == null) {
totest = "empty";
} else {
mode = new SplitFirstObject(uIDString.getRest());
totest = mode.getFirstWord();
}
switch(totest.toLowerCase()) {
case "edit":
if (mode.getRest() == null) {
return "> Missing args";
}
messageObject.setContents(mode.getRest());
return "> Daily Message contents updated";
case "delete":
ListIterator iterator = Globals.getDailyMessages().getMessages().listIterator();
while (iterator.hasNext()) {
DailyMessage object = (DailyMessage) iterator.next();
if (object.getUID() == uID) {
iterator.remove();
}
}
return "> Daily Message Deleted";
case "moveday":
if (mode.getRest() == null) {
return "> Missing args";
}
String day = mode.getRest().toUpperCase();
try {
DayOfWeek dayOfWeek = DayOfWeek.valueOf(day);
messageObject.setDay(dayOfWeek);
return "> Moved message to " + dayOfWeek + ".";
} catch (IllegalArgumentException e) {
return "> Not a valid day of the week.";
}
case "info":
RequestHandler.sendEmbedMessage("", getInfo(messageObject, command), command.channel.get());
return null;
default:
RequestHandler.sendEmbedMessage("", getInfo(messageObject, command), command.channel.get());
return null;
}
} catch (NumberFormatException e) {
return "> Invalid UID.";
}
}
use of com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.
the class EventSetup method addMessage.
private String addMessage(TimedEvent event, String rest, CommandObject command) {
if (rest == null)
return "> Missing arguments.\n" + getModes();
SplitFirstObject messageID = new SplitFirstObject(rest);
if (messageID.getRest() == null)
return "> Missing arguments.\n" + getModes();
for (DailyMessage m : event.getMessages()) {
if (m.getSpecialID().equalsIgnoreCase(messageID.getFirstWord())) {
return "> Message Id already in use.";
}
}
DayOfWeek day = null;
SplitFirstObject message = new SplitFirstObject(messageID.getRest());
try {
day = DayOfWeek.valueOf(message.getFirstWord().toUpperCase());
} catch (IllegalArgumentException e) {
// do nothing
}
if (day == null) {
event.getMessages().add(new DailyMessage(message.getAll(), day, command.user.longID, messageID.getFirstWord()));
} else {
event.getMessages().add(new DailyMessage(message.getRest(), day, command.user.longID, messageID.getFirstWord()));
}
event.setSpecialMessages(true);
return "> New message added.";
}
use of com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.
the class EditChar method execute.
@Override
public String execute(String args, CommandObject command) {
SplitFirstObject charName = new SplitFirstObject(args);
if (charName.getRest() == null || charName.getRest().isEmpty()) {
return "> Mode Not Specified";
}
SplitFirstObject mode = new SplitFirstObject(charName.getRest());
for (CharacterObject c : command.guild.characters.getCharacters(command.guild.get())) {
if (c.getName().equalsIgnoreCase(charName.getFirstWord())) {
if (c.getUserID() == command.user.longID || GuildHandler.canBypass(command.user.get(), command.guild.get())) {
String rest = mode.getRest();
if (rest == null) {
rest = "";
}
command.setAuthor(command.guild.getUserByID(c.getUserID()));
switch(mode.getFirstWord().toLowerCase()) {
case "age":
return CharEditModes.age(rest, c, command);
case "gender":
return CharEditModes.gender(rest, c, command);
case "avatar":
return CharEditModes.avatar(rest, c, command);
case "bio":
return CharEditModes.desc(rest, c, command);
case "longdesc":
return CharEditModes.longDesc(rest, c);
case "weight":
return CharEditModes.weight(rest, c, command);
case "height":
return CharEditModes.height(rest, c, command);
default:
return "> Mode not Valid.";
}
} else {
return command.user.notAllowed;
}
}
}
return "> Char with that name not found.";
}
use of com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.
the class Sudo method execute.
@Override
public String execute(String args, CommandObject command) {
if (!command.guild.config.debugMode)
return "> Debug mode is disabled. No Sudo for you missy.";
SplitFirstObject sudo = new SplitFirstObject(args);
UserObject user = Utility.getUser(command, sudo.getFirstWord(), false, false);
if (user == null) {
return "> Could not find user.";
}
command.setAuthor(user.get());
if (sudo.getRest() == null) {
return "> You need to specify some arguments.";
}
try {
new MessageHandler(sudo.getRest(), command, false);
} catch (Exception e) {
String errorPos = "";
for (StackTraceElement s : e.getStackTrace()) {
if (s.toString().contains("com.github.vaerys")) {
errorPos = s.toString();
break;
}
}
StringBuilder builder = new StringBuilder();
builder.append("> I caught an Error, Please send this Error message and the message that caused this error " + "to my **Direct Messages** so my developer can look at it and try to solve the issue.\n```\n");
builder.append(e.getClass().getName());
builder.append(": " + e.getMessage());
if (!errorPos.isEmpty()) {
builder.append("\n" + Constants.PREFIX_INDENT + "at " + errorPos);
}
builder.append("```");
RequestHandler.sendMessage(builder.toString(), command.channel.get());
Utility.sendStack(e);
}
return null;
}
use of com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.
the class SetGender method execute.
@Override
public String execute(String args, CommandObject command) {
UserObject user = command.user;
String quote = args;
boolean adminEdit = false;
if (ADMIN_EDIT.isSubCommand(command)) {
SplitFirstObject userCall = new SplitFirstObject(quote);
user = Utility.getUser(command, userCall.getFirstWord(), false, true);
if (user == null)
return "> Could not find user.";
quote = userCall.getRest();
adminEdit = true;
}
int maxLength = 20;
if (user.isPatron) {
maxLength += 20;
}
ProfileObject u = user.getProfile(command.guild);
quote = Utility.removeFun(quote);
if (quote == null || quote.isEmpty())
return "> You can't have an empty gender.";
if (adminEdit) {
if (quote.length() > maxLength) {
return "> Gender's Length is too long...\n(Must be under " + maxLength + " chars)";
}
u.setGender(quote);
return "> " + user.displayName + "'s Gender Edited";
} else {
if (quote.length() > maxLength) {
return "> Your Gender's Length is too long...\n(Must be under " + maxLength + " chars)";
}
u.setGender(quote);
return "> Gender Edited";
}
}
Aggregations