Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

queer/catnip-utilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

catnip-utilities

Some stuff to make using catnip easier.

Current features:

  • Typesafe commands
  • Menus + pagination

Usage:

Typesafe commands

Remember to pass -parameters to javac when compiling, otherwise it won't work!

catnip.loadExtension(new TypesafeCommandsExtension("!", new UnixArgParser()));
// or
catnip.loadExtension(new TypesafeCommandsExtension("!", new GenericArgParser()));
public class Commands {
    @Command(names = "ping")
    public void ping(final Context context) {
        context.source().channel().sendMessage("pong! <3");
    }
}

Menus + pagination

Example: A command that paginates members based on when they joined

@Command(names = "members")
public void members(final Context context, final String guild) {
    final String guildId = guild == null ? context.source().guildId() : guild;
    final Guild g = context.catnip().cache().guild(guildId);
    final List<Member> members = new ArrayList<>(g.members().snapshot());
    members.sort(Comparator.comparing(Member::joinedAt));
    final List<String> pages = Lists.partition(members, 25).stream()
            .map(e -> {
                StringBuilder sb = new StringBuilder("```\n");
                e.stream().map(m -> context.catnip().cache().user(m.id())).filter(Objects::nonNull)
                        .forEach(u -> sb.append("- ").append(u.username()).append('#').append(u.discriminator())
                                .append(" (").append(u.id()).append(")\n"));
                sb.append("```");
                return sb.toString();
            })
            .collect(Collectors.toList());
    context.catnip().extensionManager().extension(MenuExtension.class)
            .createPaginatedMenu("Members of **" + g.name() + "**:", ImmutableList.copyOf(pages))
            .accept(context.source().author(), context.source().channelId());
}

About

A collection of utility extensions to make using catnip easier

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages