Search in sources :

Example 1 with RunnableWrapper

use of stream.flarebot.flarebot.util.objects.RunnableWrapper in project FlareBot by FlareBot.

the class FixCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 1 && args[0].equalsIgnoreCase("confirm")) {
        if (ConfirmUtil.checkExists(sender.getId(), this.getClass())) {
            ConfirmUtil.run(sender.getId(), this.getClass());
            ConfirmUtil.remove(sender.getId(), this.getClass());
        } else {
            MessageUtils.sendErrorMessage("You haven't got any action to confirm!", channel);
        }
        return;
    }
    MessageUtils.sendErrorMessage("Are you sure you want to fix any potential autoassign roles " + "and FlareBot's nickname if songnick is enabled?" + "\nWe assign roles to users without any roles so be aware that if you allow " + "the removal of your autoassign roles they may be added back to users." + "\n\nDo `{%}fix confirm` to confirm you want to do this command!", channel, sender);
    ConfirmUtil.pushAction(sender.getId(), new RunnableWrapper(() -> fix(guild, sender, channel), this.getClass()));
}
Also used : RunnableWrapper(stream.flarebot.flarebot.util.objects.RunnableWrapper)

Example 2 with RunnableWrapper

use of stream.flarebot.flarebot.util.objects.RunnableWrapper in project FlareBot by FlareBot.

the class PruneCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length != 0) {
        if (args[0].equalsIgnoreCase("server") && args.length == 2) {
            // Re-add sub-permission when roles is added
            int amount;
            try {
                amount = Integer.parseInt(args[1]);
            } catch (NumberFormatException e) {
                MessageUtils.sendErrorMessage("Please enter a valid amount of days!", channel);
                return;
            }
            if (amount == 0) {
                MessageUtils.sendErrorMessage("The amount of days has to be more that 0!", channel);
                return;
            }
            if (amount > 30) {
                MessageUtils.sendErrorMessage("You can only prune a maximum of 30 days!", channel);
                return;
            }
            int userSize = guild.getGuild().getPrunableMemberCount(amount).complete();
            MessageUtils.sendErrorMessage(FormatUtils.formatCommandPrefix(guild, "Are you sure you want to prune " + userSize + " members?\n" + "To confirm type `{%}prune confirm` within 1 minute!"), channel);
            ConfirmUtil.pushAction(sender.getId(), new RunnableWrapper(new RestActionRunnable(guild.getGuild().getController().prune(amount).reason("Pruned by user: " + MessageUtils.getTag(sender))), this.getClass()));
            return;
        } else if (args[0].equalsIgnoreCase("confirm")) {
            if (ConfirmUtil.checkExists(sender.getId(), this.getClass())) {
                ConfirmUtil.run(sender.getId(), this.getClass());
                ConfirmUtil.remove(sender.getId(), this.getClass());
            } else {
                MessageUtils.sendErrorMessage("You haven't got any action to confirm!", channel);
            }
            return;
        }
    }
    MessageUtils.sendUsage(this, channel, sender, args);
}
Also used : RestActionRunnable(stream.flarebot.flarebot.util.objects.RestActionRunnable) RunnableWrapper(stream.flarebot.flarebot.util.objects.RunnableWrapper)

Example 3 with RunnableWrapper

use of stream.flarebot.flarebot.util.objects.RunnableWrapper in project FlareBot by FlareBot.

the class FlareBotManager method savePlaylist.

public void savePlaylist(Command command, TextChannel channel, String ownerId, boolean overwriteAllowed, String name, List<String> songs) {
    CassandraController.runTask(session -> {
        if (savePlaylistStatement == null)
            savePlaylistStatement = session.prepare("SELECT * FROM flarebot.playlist " + "WHERE playlist_name = ? AND guild_id = ?");
        ResultSet set = session.execute(savePlaylistStatement.bind().setString(0, name).setString(1, channel.getGuild().getId()));
        if (set.one() != null) {
            if (ConfirmUtil.checkExists(ownerId, command.getClass())) {
                MessageUtils.sendWarningMessage("Overwriting playlist!", channel);
            } else if (!overwriteAllowed) {
                MessageUtils.sendErrorMessage("That name is already taken! You need the `flarebot.queue.save.overwrite` permission to overwrite", channel);
                return;
            } else {
                MessageUtils.sendErrorMessage("That name is already taken! Do this again within 1 minute to overwrite!", channel);
                ConfirmUtil.pushAction(ownerId, new RunnableWrapper(Runnables.doNothing(), command.getClass()));
                return;
            }
        }
        if (insertPlaylistStatement == null)
            insertPlaylistStatement = session.prepare("INSERT INTO flarebot.playlist" + " (playlist_name, guild_id, owner, songs, scope, times_played) VALUES (?, ?, ?, ?, ?, ?)");
        session.execute(insertPlaylistStatement.bind().setString(0, name).setString(1, channel.getGuild().getId()).setString(2, ownerId).setList(3, songs).setString(4, "local").setInt(5, 0));
        channel.sendMessage(MessageUtils.getEmbed(Getters.getUserById(ownerId)).setDescription("Successfully saved the playlist '" + MessageUtils.escapeMarkdown(name) + "'").build()).queue();
    });
}
Also used : RunnableWrapper(stream.flarebot.flarebot.util.objects.RunnableWrapper) ResultSet(com.datastax.driver.core.ResultSet)

Aggregations

RunnableWrapper (stream.flarebot.flarebot.util.objects.RunnableWrapper)3 ResultSet (com.datastax.driver.core.ResultSet)1 RestActionRunnable (stream.flarebot.flarebot.util.objects.RestActionRunnable)1