net.dv8tion.jda.core.entities.Message Java Examples

The following examples show how to use net.dv8tion.jda.core.entities.Message. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogsCommand.java    From FlareBot with MIT License 7 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    int lineCount = DEFAULT_LINE_COUNT;
    if (args.length == 1) {
        lineCount = GeneralUtils.getInt(args[0], DEFAULT_LINE_COUNT);
    }

    try {
        ReversedLinesFileReader rlfr = new ReversedLinesFileReader(new File("latest.log"), Charset.forName("UTF-8"));
        StringBuilder sb = new StringBuilder();
        String line;
        for (int i = 0; i < lineCount; i++) {
            line = rlfr.readLine();
            if (line == null) break;
            sb.append(line).append("\n");
        }

        String pasteUrl = MessageUtils.paste(sb.toString());
        MessageUtils.sendPM(channel, sender, pasteUrl == null ? "null" : pasteUrl, "Could not DM you the logs! " +
                "Please make sure the privacy settings allow me :( dis is pwivate, me need to send pwivately.");
    } catch (IOException e) {
        FlareBot.LOGGER.error("Failed to read latest.log", e);
        MessageUtils.sendException("Failed to read latest.log", e, channel);
    }
}
 
Example #2
Source File: MusicAnnounceCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 1 && ARGS_PATTERN.matcher(args[0]).matches()) {
        if (args[0].equalsIgnoreCase("here")) {
            guild.setMusicAnnounceChannelId(channel.getId());
            channel.sendMessage(MessageUtils.getEmbed(sender)
                    .setDescription("Set music announcements to appear in " + channel
                            .getAsMention()).build()).queue();
        } else {
            guild.setMusicAnnounceChannelId(null);
            channel.sendMessage(MessageUtils.getEmbed(sender)
                    .setDescription(String
                            .format("Disabled announcements for `%s`", channel.getGuild()
                                    .getName()))
                    .build()).queue();
        }
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
 
Example #3
Source File: UnmuteCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 1) {
        User target = GuildUtils.getUser(args[0]);
        if (target == null) {
            MessageUtils.sendErrorMessage("We cannot find that user! Try their ID if you didn't already.", channel, sender);
            return;
        }
        String reason = null;
        if (args.length >= 2)
            reason = MessageUtils.getMessage(args, 1);

        ModlogHandler.getInstance().handleAction(guild, channel, sender, target, ModAction.UNMUTE, reason);
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
 
Example #4
Source File: TempBanCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 2) {
        User user = GuildUtils.getUser(args[0], guild.getGuildId());
        if (user == null) {
            MessageUtils.sendErrorMessage("We cannot find that user! Try their ID if you didn't already.", channel, sender);
            return;
        }
        String reason = null;
        if (args.length >= 3)
            reason = MessageUtils.getMessage(args, 2);

        Period period = GeneralUtils.getTimeFromInput(args[1], channel);
        if (period == null) return;

        ModlogHandler.getInstance().handleAction(guild, channel, sender, user, ModAction.TEMP_BAN, reason,
                period.toStandardDuration().getMillis());
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
 
Example #5
Source File: TempMuteCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length < 2) {
        MessageUtils.sendUsage(this, channel, sender, args);
    } else {
        User user = GuildUtils.getUser(args[0], guild.getGuildId());
        if (user == null) {
            MessageUtils.sendErrorMessage("Invalid user!!", channel);
            return;
        }
        if (guild.getMutedRole() == null) {
            MessageUtils.sendErrorMessage("Error getting the \"Muted\" role! Check FlareBot has permissions to create it!", channel);
            return;
        }

        Period period;
        if ((period = GeneralUtils.getTimeFromInput(args[1], channel)) == null) return;
        String reason = args.length >= 3 ? MessageUtils.getMessage(args, 2) : null;

        ModlogHandler.getInstance().handleAction(guild, channel, sender, user, ModAction.TEMP_MUTE, reason,
                period.toStandardDuration().getMillis());
    }
}
 
Example #6
Source File: WarnCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 0) {
        MessageUtils.sendUsage(this, channel, sender, args);
    } else {
        User user = GuildUtils.getUser(args[0]);
        if (user == null) {
            MessageUtils.sendErrorMessage("We couldn't find that user!!", channel);
            return;
        }
        String reason = null;
        if (args.length >= 2) reason = MessageUtils.getMessage(args, 1);

        ModlogHandler.getInstance().handleAction(guild, channel, sender, user, ModAction.WARN, reason);
    }
}
 
Example #7
Source File: SoftBanCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 1) {
        User target = GuildUtils.getUser(args[0], guild.getGuildId());
        if (target == null) {
            MessageUtils.sendErrorMessage("We cannot find that user! Try their ID if you didn't already.", channel, sender);
            return;
        }
        String reason = null;
        if (args.length >= 2)
            reason = MessageUtils.getMessage(args, 1);

        ModlogHandler.getInstance().handleAction(guild, channel, sender, target, ModAction.SOFTBAN, reason);
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
 
Example #8
Source File: MuteCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 0) {
        MessageUtils.sendUsage(this, channel, sender, args);
    } else {
        User user = GuildUtils.getUser(args[0], guild.getGuildId());
        if (user == null) {
            MessageUtils.sendErrorMessage("Invalid user!!", channel);
            return;
        }
        if (guild.getMutedRole() == null) {
            MessageUtils.sendErrorMessage("Error getting the \"Muted\" role! Check FlareBot has permissions to create it!", channel);
            return;
        }
        String reason = args.length > 1 ? MessageUtils.getMessage(args, 1) : null;
        ModlogHandler.getInstance().handleAction(guild, channel, sender, user, ModAction.MUTE, reason);
    }
}
 
Example #9
Source File: KickCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 1) {
        User user = GuildUtils.getUser(args[0], guild.getGuildId());
        if (user == null) {
            MessageUtils.sendErrorMessage("We cannot find that user! Try their ID if you didn't already.", channel, sender);
            return;
        }
        Member target = guild.getGuild().getMember(user);
        if (target == null) {
            MessageUtils.sendErrorMessage("That user is not on this server therefore cannot be kicked!",
                    channel, sender);
            return;
        }
        String reason = null;
        if (args.length >= 2)
            reason = MessageUtils.getMessage(args, 1);
        ModlogHandler.getInstance().handleAction(guild, channel, sender, user, ModAction.KICK, reason);
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
 
Example #10
Source File: ForceBanCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 1) {
        User user = GuildUtils.getUser(args[0], true);
        if (user == null) {
            MessageUtils.sendErrorMessage("We cannot find that user!", channel, sender);
            return;
        }
        String reason = null;
        if (args.length >= 2)
            reason = MessageUtils.getMessage(args, 1);
        ModlogHandler.getInstance().handleAction(guild, channel, sender, user, ModAction.FORCE_BAN, reason);
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
 
Example #11
Source File: ButtonGroup.java    From FlareBot with MIT License 6 votes vote down vote up
public void addReaction(Message message) {
    if (!(message.getChannel().getType() == ChannelType.TEXT && message.getGuild().getSelfMember()
            .hasPermission(message.getTextChannel(), Permission.MESSAGE_HISTORY))) {
        message.getChannel().sendMessage("I can't add buttons due to not having the `Message History` permission!").queue();
        return;
    }

    this.message = message;
    if (unicode != null)
        message.addReaction(unicode).queue();
    else {
        try {
            message.addReaction(Getters.getEmoteById(emoteId)).queue();
        } catch (IllegalArgumentException ignored) {}
    }
}
 
Example #12
Source File: BanCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 1) {
        User target = GuildUtils.getUser(args[0], guild.getGuildId());
        if (target == null) {
            MessageUtils.sendErrorMessage("We cannot find that user! Try their ID if you didn't already.", channel, sender);
            return;
        }
        String reason = null;
        if (args.length >= 2)
            reason = MessageUtils.getMessage(args, 1);

        ModlogHandler.getInstance().handleAction(guild, channel, sender, target, ModAction.BAN, reason);
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
 
Example #13
Source File: RandomExtractor.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void process(String input, Player player, Message message, User user) throws Exception {
    int i = 0;
    for (String s : input.split(",")) {
        try {
            AudioItem probablyATrack = player.resolve(s);
            if (probablyATrack == null)
                continue;
            Track track = new Track((AudioTrack) probablyATrack);
            track.getMeta().put("requester", user.getId());
            track.getMeta().put("guildId", player.getGuildId());
            player.queue(track);
            i++;
        } catch (FriendlyException ignored) {
        }
    }
    MessageUtils.editMessage(null, MessageUtils.getEmbed()
            .setDescription("Added " + i + " random songs to the playlist!"), message);
}
 
Example #14
Source File: HelpCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 1) {
        CommandType type;
        try {
            type = CommandType.valueOf(args[0].toUpperCase());
        } catch (IllegalArgumentException ignored) {
            channel.sendMessage(MessageUtils.getEmbed(sender).setDescription("No such category!").build()).queue();
            return;
        }
        if (type.isInternal() && !GeneralUtils.canRunInternalCommand(type, sender)) {
            channel.sendMessage(MessageUtils.getEmbed(sender).setDescription("No such category!").build()).queue();
            return;
        }

        sendCommands(guild, channel, member, type);
    } else
        sendCommands(channel.getGuild(), channel, sender);
}
 
Example #15
Source File: ChangelogCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message msg, String[] args, Member member) {
    if (PerGuildPermissions.isAdmin(sender)) {
        if (args.length == 0) {
            channel.sendMessage("Specify a version or PR to post about!").queue();
            return;
        }
        if (args[0].startsWith("pr:")) {
            channel.sendMessage(new MessageBuilder().setEmbed(GitHubUtils.getEmbedForPR(args[0].substring(3))
                    .build()).build()).queue();
        } else {
            String message = msg.getContentRaw();
            message = message.substring(message.indexOf(" ") + 1);
            channel.sendMessage(message).queue();
        }
    }
}
 
Example #16
Source File: JoinCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (member.getVoiceState().inVoiceChannel()) {
        if (channel.getGuild().getAudioManager().isAttemptingToConnect()) {
            MessageUtils.sendErrorMessage("Currently connecting to a voice channel! Try again soon!", channel);
            return;
        }
        if (channel.getGuild().getSelfMember().getVoiceState().inVoiceChannel() && !channel.getGuild()
                .getSelfMember()
                .getVoiceState()
                .getAudioChannel()
                .getId()
                .equals(member
                        .getVoiceState()
                        .getAudioChannel()
                        .getId()) && !getPermissions(channel).hasPermission(member, Permission.JOIN_OTHER)) {
            MessageUtils.sendErrorMessage("You need the permission `" + Permission.JOIN_OTHER + "` for me to join your voice channel while I'm in one!", channel);
            return;
        }
        GuildUtils.joinChannel(channel, member);
    }
}
 
Example #17
Source File: AvatarCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    User user = sender;
    if (args.length > 0)
        user = GuildUtils.getUser(MessageUtils.getMessage(args, 0), guild.getGuildId());
    if (user != null) {
        if (!user.getId().equals(sender.getId()) && !getPermissions(channel).hasPermission(member, Permission.AVATAR_OTHER)) {
            MessageUtils.sendErrorMessage("You need the permission `" + Permission.AVATAR_OTHER + "` in order to do that command!",
                    channel);
            return;
        }
        channel.sendMessage(MessageUtils.getEmbed(sender).setColor(Color.cyan).setAuthor(user.getName(), null, null)
                .setImage(user.getEffectiveAvatarUrl()).build()).queue();
    } else
        MessageUtils.sendErrorMessage("Cannot find that user!", channel);
}
 
Example #18
Source File: SetPrefixCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 1) {
        if (args[0].equalsIgnoreCase("reset")) {
            guild.setPrefix('_');
            MessageUtils.sendInfoMessage("Reset the prefix back to `_`!", channel, sender);
        } else if (args[0].length() == 1) {
            guild.setPrefix(args[0].charAt(0));
            channel.sendMessage(MessageUtils.getEmbed(sender)
                    .setDescription(String.format("Set the prefix to `%s`", args[0])).build())
                    .queue();
        } else {
            MessageUtils.sendErrorMessage("Cannot set the prefix to be more that one character long!", channel, sender);
        }
    } else {
        channel.sendMessage(MessageUtils.getEmbed(sender)
                .setDescription(String.format("Current guild prefix is `%s`!", guild.getPrefix())).build()).queue();
    }
}
 
Example #19
Source File: BetaCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    String betaInfo =
            FormatUtils.formatCommandPrefix(guild, FlareBot.getCommandManager().getCommands()
                    .stream()
                    .filter(Command::isBetaTesterCommand)
                    .map(c -> "`{%}" + c.getCommand() + "` - " + c.getDescription())
                    .collect(Collectors.joining("\n")));
    String betaMessage = guild.hasBetaAccess() ?
            "Thank you for being apart of our beta program! Please report any bugs or give us suggestions over at the [support discord](" + Constants.INVITE_URL + ")!"
            : "Listed below are the commands you can gain access to by being a part of our beta program! To join the beta program, you will either need to win " +
            "beta access through a giveaway (Make sure you are in the [support server](" + Constants.INVITE_URL + ") to hear of these!) or you can become apart of the " +
            "Donator tier or higher on our [patreon page](https://www.patreon.com/flarebot)!";
    EmbedBuilder builder = MessageUtils.getEmbed(sender);
    builder.setColor(Color.CYAN);
    builder.setDescription(betaMessage);
    builder.addField("Beta Commands", betaInfo, false);
    channel.sendMessage(builder.build()).queue();
}
 
Example #20
Source File: ShardInfoCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    PagedTableBuilder tb = new PagedTableBuilder();

    tb.addColumn("Shard ID");
    tb.addColumn("Status");
    tb.addColumn("Ping");
    tb.addColumn("Guild Count");
    tb.addColumn("Connected VCs");

    List<JDA> shards = new ArrayList<>(Getters.getShards());
    Collections.reverse(shards);
    for (JDA jda : shards) {
        List<String> row = new ArrayList<>();
        row.add(ShardUtils.getDisplayShardId(jda) +
                (ShardUtils.getShardId(channel.getJDA()) == ShardUtils.getShardId(jda) ? " (You)" : ""));
        row.add(WordUtils.capitalizeFully(jda.getStatus().toString().replace("_", " ")));
        row.add(String.valueOf(jda.getPing()));
        row.add(String.valueOf(jda.getGuilds().size()));
        row.add(String.valueOf(jda.getVoiceChannels().stream().filter(vc -> vc.getMembers().contains(vc.getGuild()
                .getSelfMember())).count()));
        tb.addRow(row);
    }
    PaginationUtil.sendPagedMessage(channel, tb.build(), 0, sender, ButtonGroupConstants.SHARDINFO);
}
 
Example #21
Source File: UnbanCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length >= 1) {
        User target = GuildUtils.getUser(MessageUtils.getMessage(args, 0), null, true);
        if (target == null) {
            MessageUtils.sendErrorMessage("We cannot find that user! Try their ID if you didn't already.\n"
                            + "To get a User ID simply enable developer mode by going to User Settings > Appearance " +
                            "> Developer Mode then just right click the user and click Copy ID",
                    channel, sender);
            return;
        }
        ModlogHandler.getInstance().handleAction(guild, channel, sender, target, ModAction.UNBAN, null);
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
 
Example #22
Source File: LeaveCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (channel.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
        if ((!member.getVoiceState().inVoiceChannel() || !channel.getGuild().getSelfMember().getVoiceState()
                .getAudioChannel().getId()
                .equals(member.getVoiceState().getAudioChannel()
                        .getId())) && !getPermissions(channel)
                .hasPermission(member, Permission.LEAVE_OTHER)) {
            MessageUtils.sendErrorMessage("You need the permission `" + Permission.LEAVE_OTHER + "` for me to leave a different voice channel!",
                    channel, sender);
            return;
        }
        channel.getGuild().getAudioManager().closeAudioConnection();
        if (FlareBotManager.instance().getLastActive().containsKey(guild.getGuildIdLong()))
            FlareBotManager.instance().getLastActive().remove(guild.getGuildIdLong());
        MessageUtils.sendInfoMessage("Bye bye! I've left the channel for now", channel, sender);
    }
}
 
Example #23
Source File: QuickPollCommand.java    From DiscordBlueBot with MIT License 6 votes vote down vote up
@Override
public void action(String[] args, MessageReceivedEvent event) {
    String query = "";
    for (String arg : args) {
        query += arg + " ";
    }
    EmbedBuilder builder = new EmbedBuilder();
    builder.setColor(Color.decode(MainBot.getConfig().getEmbedColor()));
    builder.setAuthor(event.getAuthor().getName() + "#" + event.getAuthor().getDiscriminator() + " created a poll", null, event.getAuthor().getAvatarUrl());
    builder.addField("", ":grey_question: Question : " + "**" + query + "**", false);
    builder.setFooter("Vote by adding a reaction below !", null);

    event.getMessage().delete().queue();
    event.getTextChannel().sendMessage(builder.build()).queue();

    //Now retrieves the last message from BlueBot to add reactions
    List<Message> history = event.getTextChannel().getHistory().retrievePast(10).complete(); //arbitrary ammount
    for (Message msg : history) {
        if(msg.getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) {
            msg.addReaction("\uD83D\uDC4D").queue();
            msg.addReaction("\ud83d\udc4e").queue();
            msg.addReaction("\uD83E\uDD37").queue();
            break;
        }
    }
}
 
Example #24
Source File: DeleteCommand.java    From FlareBot with MIT License 6 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 0) {
        MessageUtils.sendUsage(this, channel, sender, args);
        return;
    }
    channel.sendTyping().complete();
    String name = MessageUtils.getMessage(args, 0);
    CassandraController.runTask(session -> {
        ResultSet set = session.execute(session
                .prepare("SELECT playlist_name FROM flarebot.playlist WHERE playlist_name = ? AND guild_id = ?")
                .bind().setString(0, name).setString(1, channel.getGuild().getId()));
        if (set.one() != null) {
            session.execute(session
                    .prepare("DELETE FROM flarebot.playlist WHERE playlist_name = ? AND guild_id = ?").bind()
                    .setString(0, name).setString(1, channel.getGuild().getId()));
            channel.sendMessage(MessageUtils.getEmbed(sender)
                    .setDescription(String
                            .format("Removed the playlist '%s'", name)).setColor(Color.green)
                    .build()).queue();
        } else {
            MessageUtils.sendErrorMessage(String.format("The playlist '%s' does not exist!", name), channel, sender);
        }
    });
}
 
Example #25
Source File: QueryCommand.java    From FlareBot with MIT License 5 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    try {
        CassandraController.runUnsafeTask(conn -> {
            ResultSet set = conn.execute(MessageUtils.getMessage(args, 0));
            List<String> header = new ArrayList<>();
            List<List<String>> table = new ArrayList<>();
            int columnsCount = set.getColumnDefinitions().size();
            for (int i = 0; i < columnsCount; i++) {
                header.add(set.getColumnDefinitions().getName(i));
            }
            for (Row setRow : set) {
                List<String> row = new ArrayList<>();
                for (int i = 0; i < columnsCount; i++) {
                    String value = setRow.getObject(i).toString();
                    row.add(value.substring(0, Math.min(30, value.length())));
                }
                table.add(row);
            }
            String output = MessageUtils.makeAsciiTable(header, table, null);
            if (output.length() < 2000) {
                channel.sendMessage(output).queue();
            } else {
                MessageUtils.sendErrorMessage("The query result set was very large, it has been posted to paste [here](" + MessageUtils
                        .paste(output) + ")", channel, sender);
            }
        });
    } catch (QueryExecutionException | QueryValidationException e) {
        EmbedBuilder eb = new EmbedBuilder();
        eb.setTitle("Failed to execute query");
        eb.addField("Error", "```\n" + e.getMessage() + "\n```", false);
        channel.sendMessage(eb.build()).queue();
    }
}
 
Example #26
Source File: InfoCommand.java    From FlareBot with MIT License 5 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 0) {
        EmbedBuilder bld = MessageUtils.getEmbed()
                .setThumbnail(MessageUtils.getAvatar(channel.getJDA().getSelfUser()))
                .setFooter("Made by Walshy#9060 and BinaryOverload#2382", channel.getJDA().getSelfUser().getEffectiveAvatarUrl());
        bld.setDescription("FlareBot v" + FlareBot.getVersion() + " info")
                .setColor(Color.CYAN);
        for (Content content : Content.values) {
            bld.addField(content.getName(), content.getReturn(), content.isAlign());
        }
        channel.sendMessage(bld.build()).queue();
    } else
        GeneralUtils.handleMultiSelectionCommand(sender, channel, args, Content.values);
}
 
Example #27
Source File: LoopCommand.java    From FlareBot with MIT License 5 votes vote down vote up
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    Player player = FlareBot.instance().getMusicManager().getPlayer(channel.getGuild().getId());
    if (!player.getLooping()) {
        player.setLooping(true);
        channel.sendMessage("Looping: **ON**").queue();
    } else {
        player.setLooping(false);
        channel.sendMessage("Looping: **OFF**").queue();
    }
}
 
Example #28
Source File: ButtonUtil.java    From FlareBot with MIT License 5 votes vote down vote up
private static void handleSuccessConsumer(TextChannel channel, Message message, ButtonGroup buttonGroup) {
    if (!channel.getGuild().getSelfMember().hasPermission(Permission.MESSAGE_ADD_REACTION)) {
        MessageUtils.sendErrorMessage("We don't have permission to add reactions to messages so buttons have been " +
                "disabled", channel);
        return;
    }
    if (!channel.getGuild().getSelfMember().hasPermission(channel, Permission.MESSAGE_MANAGE)) {
        MessageUtils.sendErrorMessage("We don't have permission to manage reactions so you won't be getting the best experience with buttons", channel);
    }
    for (ButtonGroup.Button button : buttonGroup.getButtons()) {
        button.addReaction(message);
    }
    buttonMessages.put(message.getId(), buttonGroup);
}
 
Example #29
Source File: Counter.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
@Override
public void action(String[] args, MessageReceivedEvent event) throws ParseException, IOException {

    Message message = event.getMessage();
    Guild guild = event.getGuild();
    Member author = event.getMember();

    if (args.length < 1) {
        Messages.message(message.getTextChannel(), help(), Color.red);
        return;
    }

    switch (args[0]) {

        case "add":
        case "create":
            create(args, event);
            break;

        case "delete":
        case "remove":
            delete(args, event);
            break;

        case "list":
            list(event);
            break;

        default:
            changeValue(args, event);
    }

    saveAll();

}
 
Example #30
Source File: ParseUtils.java    From FlareBot with MIT License 5 votes vote down vote up
/**
 * Parse user input to find a user.
 *
 * Accepts:
 * * Mention
 * * Name
 * * ID
 *
 * @param guild The guild to find the user from.
 * @param input The input of which to search.
 * @param searchGlobally If we should search the entirety of FlareBot or just the guild.
 * @return The User if found, null otherwise.
 */
@Nullable
public static User parseUser(Guild guild, String input, boolean searchGlobally) {
    Matcher matcher = Message.MentionType.USER.getPattern().matcher(input);
    if (matcher.matches()) {
        return Getters.getUserById(matcher.group(1));
    }

    for (Member m : guild.getMemberCache()) {
        if (m.getUser().getName().equalsIgnoreCase(input)
                || (m.getNickname() != null && m.getNickname().equalsIgnoreCase(input))
                || input.contains("#")
                && (m.getUser().getName() + '#' + m.getUser().getDiscriminator()).equalsIgnoreCase(input))
            return m.getUser();
    }

    if (searchGlobally) {
        for (User u : Getters.getUserCache())
            if (u.getName().equalsIgnoreCase(input) ||
                    input.contains("#") && (u.getName() + '#' + u.getDiscriminator()).equalsIgnoreCase(input))
                return u;
    }

    try {
        return Getters.getUserById(input);
    } catch (NumberFormatException e) {
        return null;
    }
}