Search in sources :

Example 1 with JoinMessage

use of com.github.vaerys.objects.JoinMessage in project DiscordSailv2 by Vaerys-Dawn.

the class JoinHandler method customJoinMessages.

/**
 * Send A special message to the specified JoinMessage channel that welcomes the user to the server.
 *
 * @param user    The user that joined. ({@link UserObject})
 * @param content The Guild that the user joined. ({@link GuildObject})
 */
public static void customJoinMessages(GuildObject content, IUser user) {
    IChannel channel = content.getChannelByType(ChannelSetting.JOIN_CHANNEL);
    if (channel == null)
        return;
    Random random = new Random();
    List<JoinMessage> joinMessageList = content.channelData.getJoinMessages();
    if (joinMessageList.size() == 0)
        return;
    JoinMessage message = joinMessageList.get(random.nextInt(joinMessageList.size()));
    String response = message.getContent(new CommandObject(content, channel, user));
    RequestHandler.sendMessage(response, channel);
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) IChannel(sx.blah.discord.handle.obj.IChannel) Random(java.util.Random) JoinMessage(com.github.vaerys.objects.JoinMessage)

Example 2 with JoinMessage

use of com.github.vaerys.objects.JoinMessage in project DiscordSailv2 by Vaerys-Dawn.

the class EditJoinMessage method execute.

@Override
public String execute(String args, CommandObject command) {
    int index;
    SplitFirstObject splitArgs = new SplitFirstObject(args);
    List<JoinMessage> messages = command.guild.channelData.getJoinMessages();
    try {
        index = Integer.parseInt(splitArgs.getFirstWord());
    } catch (NumberFormatException e) {
        return "> Not a valid number.";
    }
    index--;
    if (index < 0 || index >= messages.size()) {
        return "> Could not find message.";
    }
    if (splitArgs.getRest() == null) {
        return "> Could not find any content to edit with.";
    }
    if (!splitArgs.getRest().contains("<user>"))
        return "> Could not find <user> tag.";
    for (JoinMessage m : messages) {
        if (m.getContent().equals(splitArgs.getRest())) {
            return "> New Contents matches another Custom join message's contents, cannot have duplicate messages.";
        }
    }
    JoinMessage message = messages.get(index);
    message.setContent(splitArgs.getRest());
    return "> Contents edited.";
}
Also used : JoinMessage(com.github.vaerys.objects.JoinMessage) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 3 with JoinMessage

use of com.github.vaerys.objects.JoinMessage in project DiscordSailv2 by Vaerys-Dawn.

the class JoinMessageInfo method execute.

@Override
public String execute(String args, CommandObject command) {
    int index;
    List<JoinMessage> messages = command.guild.channelData.getJoinMessages();
    XEmbedBuilder builder = new XEmbedBuilder(command);
    try {
        index = Integer.parseInt(args);
    } catch (NumberFormatException e) {
        return "> Not a valid number.";
    }
    index--;
    if (index < 0 || index >= messages.size()) {
        return "> Could not find message.";
    }
    JoinMessage message = messages.get(index);
    builder.withTitle("Message #" + (index + 1));
    builder.withDesc(message.getContent());
    UserObject user = new UserObject(message.getCreator(), command.guild);
    if (user.get() == null) {
        builder.withFooterText("Could not find user.");
    } else {
        builder.withFooterText("Creator: @" + user.username);
        builder.withFooterIcon(user.getAvatarURL());
    }
    builder.send(command.channel);
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) JoinMessage(com.github.vaerys.objects.JoinMessage) UserObject(com.github.vaerys.masterobjects.UserObject)

Example 4 with JoinMessage

use of com.github.vaerys.objects.JoinMessage in project DiscordSailv2 by Vaerys-Dawn.

the class NewJoinMessage method execute.

@Override
public String execute(String args, CommandObject command) {
    List<JoinMessage> messages = command.guild.channelData.getJoinMessages();
    if (!args.contains("<user>"))
        return "> Could not find <user> Tag";
    for (JoinMessage m : messages) {
        if (m.getContent().equals(args)) {
            return "> New Join Message Contents matches another Custom Join Message's contents, cannot have duplicate messages.";
        }
    }
    if (StringUtils.containsIgnoreCase(args, "@everyone") || StringUtils.containsIgnoreCase(args, "@here")) {
        return "> You cannot put everyone or here mentions in join messages.";
    }
    messages.add(new JoinMessage(command.user.longID, args));
    return "> New Custom Join Message added at index" + command.guild.channelData.getJoinMessages().size() + ".";
}
Also used : JoinMessage(com.github.vaerys.objects.JoinMessage)

Example 5 with JoinMessage

use of com.github.vaerys.objects.JoinMessage in project DiscordSailv2 by Vaerys-Dawn.

the class ListJoinMessages method execute.

@Override
public String execute(String args, CommandObject command) {
    XEmbedBuilder builder = new XEmbedBuilder(command);
    StringHandler handler = new StringHandler();
    List<JoinMessage> messages = command.guild.channelData.getJoinMessages();
    if (messages.size() == 0) {
        return "> No Messages exist right now, you can create some with **" + new NewJoinMessage().getUsage(command) + "**";
    }
    int page = 1;
    try {
        page = Integer.parseInt(args);
        if (page <= 0)
            return "> Invalid Page.";
    } catch (NumberFormatException e) {
        if (args != null && !args.isEmpty()) {
            return "> Not a valid number";
        }
    }
    page--;
    List<String> pages = new LinkedList<>();
    int index = 1;
    int i = 0;
    for (JoinMessage m : messages) {
        if (i == 10) {
            i = 0;
            pages.add(handler.toString());
            handler.emptyContent();
        }
        String shortNote = Utility.truncateString(Utility.removeFun(m.getContent()), 65);
        handler.append("**> Message #" + index + "**");
        handler.append("\n" + shortNote);
        handler.append("\n");
        i++;
        index++;
    }
    pages.add(handler.toString());
    if (page >= pages.size()) {
        return "> Invalid Page.";
    }
    builder.withTitle("> Join Message list");
    builder.withDesc(pages.get(page) + "\n\n" + missingArgs(command));
    builder.withFooterText("Page " + (page + 1) + "/" + pages.size() + " | Total Join Messages: " + messages.size());
    builder.send(command.channel);
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) JoinMessage(com.github.vaerys.objects.JoinMessage) StringHandler(com.github.vaerys.handlers.StringHandler) LinkedList(java.util.LinkedList)

Aggregations

JoinMessage (com.github.vaerys.objects.JoinMessage)5 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)2 CommandObject (com.github.vaerys.commands.CommandObject)1 StringHandler (com.github.vaerys.handlers.StringHandler)1 UserObject (com.github.vaerys.masterobjects.UserObject)1 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)1 LinkedList (java.util.LinkedList)1 Random (java.util.Random)1 IChannel (sx.blah.discord.handle.obj.IChannel)1