Search in sources :

Example 1 with IMentionable

use of net.dv8tion.jda.core.entities.IMentionable in project MantaroBot by Mantaro.

the class ActionCmds method meow.

@Command
public static void meow(CommandRegistry registry) {
    registry.register("meow", new SimpleCommand(Category.ACTION) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            Message receivedMessage = event.getMessage();
            if (!receivedMessage.getMentionedUsers().isEmpty()) {
                String mew = event.getMessage().getMentionedUsers().stream().map(IMentionable::getAsMention).collect(Collectors.joining(" "));
                event.getChannel().sendFile(ImageActionCmd.CACHE.getInput("http://imgur.com/yFGHvVR.gif"), "mew.gif", new MessageBuilder().append(EmoteReference.TALKING).append(String.format("%s *is meowing at %s.*", event.getAuthor().getAsMention(), mew)).build()).queue();
            } else {
                event.getChannel().sendFile(ImageActionCmd.CACHE.getInput("http://imgur.com/yFGHvVR.gif"), "mew.gif", new MessageBuilder().append(":speech_balloon: Meow.").build()).queue();
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Meow command").setDescription("**Meow either to a person or the sky**.").setColor(Color.cyan).build();
        }
    });
    registry.registerAlias("meow", "mew");
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Message(net.dv8tion.jda.core.entities.Message) IMentionable(net.dv8tion.jda.core.entities.IMentionable) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 2 with IMentionable

use of net.dv8tion.jda.core.entities.IMentionable in project FredBoat by Frederikam.

the class ArgumentUtil method checkSingleFuzzySearchResult.

/**
 * Processes a list of mentionables (roles / users).
 * Replies in the context of there are none / more than one mentionable and returns null, otherwise returns the
 * single mentionable.
 */
@Nullable
public static IMentionable checkSingleFuzzySearchResult(@Nonnull List<IMentionable> list, @Nonnull CommandContext context, @Nonnull String term) {
    switch(list.size()) {
        case 0:
            context.reply(context.i18nFormat("fuzzyNothingFound", term));
            return null;
        case 1:
            return list.get(0);
        default:
            StringBuilder searchResults = new StringBuilder();
            int i = 0;
            for (IMentionable mentionable : list) {
                if (i == FUZZY_RESULT_LIMIT)
                    break;
                if (mentionable instanceof Member) {
                    Member member = (Member) mentionable;
                    searchResults.append("\nUSER ").append(member.getUser().getId()).append(" ").append(member.getEffectiveName());
                } else if (mentionable instanceof Role) {
                    Role role = (Role) mentionable;
                    searchResults.append("\nROLE ").append(role.getId()).append(" ").append(role.getName());
                } else {
                    throw new IllegalArgumentException("Expected Role or Member, got " + mentionable);
                }
                i++;
            }
            if (list.size() > FUZZY_RESULT_LIMIT) {
                searchResults.append("\n[...]");
            }
            context.reply(context.i18n("fuzzyMultiple") + "\n" + TextUtils.asCodeBlock(searchResults.toString()));
            return null;
    }
}
Also used : Role(net.dv8tion.jda.core.entities.Role) IMentionable(net.dv8tion.jda.core.entities.IMentionable) Member(net.dv8tion.jda.core.entities.Member) Nullable(javax.annotation.Nullable)

Example 3 with IMentionable

use of net.dv8tion.jda.core.entities.IMentionable in project FredBoat by Frederikam.

the class RoleInfoCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    if (!context.hasArguments()) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    List<IMentionable> roles = new ArrayList<>(ArgumentUtil.fuzzyRoleSearch(context.guild, context.rawArgs));
    Role role = (Role) ArgumentUtil.checkSingleFuzzySearchResult(roles, context, context.rawArgs);
    if (role == null)
        return;
    EmbedBuilder eb = CentralMessaging.getClearThreadLocalEmbedBuilder();
    // todo i18n
    eb.setTitle("Information about role " + role.getName() + ":").setColor(role.getColor()).addField("Name", role.getName(), // todo i18n
    true).addField("Id", role.getId(), // todo i18n
    true).addField("Color", colorToHex(role.getColor()), // todo i18n
    true).addField("Hoisted", Boolean.toString(role.isHoisted()), // todo i18n
    true).addField("Mentionable", Boolean.toString(role.isMentionable()), // todo i18n
    true).addField("Managed", Boolean.toString(role.isManaged()), // todo i18n
    true).addField("Permissions", permissionsToString(role.getPermissions()), // todo i18n
    true);
    context.reply(eb.build());
}
Also used : Role(net.dv8tion.jda.core.entities.Role) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) IMentionable(net.dv8tion.jda.core.entities.IMentionable) ArrayList(java.util.ArrayList)

Aggregations

IMentionable (net.dv8tion.jda.core.entities.IMentionable)3 Role (net.dv8tion.jda.core.entities.Role)2 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)1 Member (net.dv8tion.jda.core.entities.Member)1 Message (net.dv8tion.jda.core.entities.Message)1 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)1 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)1 Command (net.kodehawa.mantarobot.modules.Command)1 SimpleCommand (net.kodehawa.mantarobot.modules.commands.SimpleCommand)1