Search in sources :

Example 1 with CompObject

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

the class EnterComp method execute.

@Override
public String execute(String args, CommandObject command) {
    GuildConfig guildconfig = command.guild.config;
    IMessage message = command.message.get();
    IUser author = command.user.get();
    if (guildconfig.compEntries) {
        String fileName;
        String fileUrl;
        if (message.getAttachments().size() > 0) {
            List<IMessage.Attachment> attatchments = message.getAttachments();
            IMessage.Attachment a = attatchments.get(0);
            fileName = a.getFilename();
            fileUrl = a.getUrl();
        } else if (!args.isEmpty()) {
            fileName = author.getName() + "'s Entry";
            fileUrl = args;
        } else {
            return "> Missing a File or Image link to enter into the competition.";
        }
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy - HH:mm:ss");
        Calendar cal = Calendar.getInstance();
        command.guild.competition.newEntry(new CompObject(author.getDisplayName(command.guild.get()), author.getLongID(), fileName, fileUrl, dateFormat.format(cal.getTime())));
        return "> Thank you " + author.getDisplayName(command.guild.get()) + " For entering the Competition.";
    } else {
        return "> Competition Entries are closed.";
    }
}
Also used : GuildConfig(com.github.vaerys.pogos.GuildConfig) IMessage(sx.blah.discord.handle.obj.IMessage) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Calendar(java.util.Calendar) IUser(sx.blah.discord.handle.obj.IUser) CompObject(com.github.vaerys.objects.CompObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with CompObject

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

the class GetCompEntries method execute.

@Override
public String execute(String args, CommandObject command) {
    if (command.guild.competition.getEntries().size() == 0) {
        return "> No entries were found.";
    }
    List<CompObject> compObjects = command.guild.competition.getEntries();
    for (int i = 0; i < compObjects.size(); i++) {
        XEmbedBuilder builder = new XEmbedBuilder(command);
        builder.withTitle("Entry " + (i + 1));
        IUser user = command.guild.getUserByID(compObjects.get(i).getUserID());
        if (user != null) {
            builder.withDesc(user.mention());
            builder.withColor(GuildHandler.getUsersColour(user, command.guild.get()));
        }
        if (Utility.isImageLink(compObjects.get(i).getFileUrl())) {
            builder.withThumbnail(compObjects.get(i).getFileUrl());
        } else {
            if (user != null) {
                builder.withDesc(user.mention() + "\n" + compObjects.get(i).getFileUrl());
            } else {
                builder.withDesc(compObjects.get(i).getFileUrl());
            }
        }
        builder.send(command.channel);
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            Utility.sendStack(e);
        }
    }
    return "";
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) IUser(sx.blah.discord.handle.obj.IUser) CompObject(com.github.vaerys.objects.CompObject)

Example 3 with CompObject

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

the class RemoveEntry method execute.

@Override
public String execute(String args, CommandObject command) {
    try {
        int entry = Integer.parseInt(args) - 1;
        CompObject didRemove = command.guild.competition.getEntries().remove(entry);
        return "> Removed entry " + (entry + 1) + "\n<" + didRemove.getFileUrl() + ">";
    } catch (NumberFormatException e) {
        return "> Needs a valid number";
    } catch (IndexOutOfBoundsException e) {
        return "> Could not find entry";
    }
}
Also used : CompObject(com.github.vaerys.objects.CompObject)

Aggregations

CompObject (com.github.vaerys.objects.CompObject)3 IUser (sx.blah.discord.handle.obj.IUser)2 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)1 GuildConfig (com.github.vaerys.pogos.GuildConfig)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 IMessage (sx.blah.discord.handle.obj.IMessage)1