Search in sources :

Example 11 with CommandContext

use of ml.duncte123.skybot.objects.command.CommandContext in project SkyBot by DuncteBot.

the class LockEmoteCommand method execute.

@Override
public void execute(@Nonnull CommandContext ctx) {
    if (ctx.getArgs().isEmpty()) {
        this.sendUsageInstructions(ctx);
        return;
    }
    final Message message = ctx.getMessage();
    final List<Emote> mentionedEmotes = message.getEmotes();
    final List<Role> mentionedRoles = new ArrayList<>(message.getMentionedRoles());
    if (mentionedRoles.isEmpty()) {
        // Loop over the args and check if there are roles found in text
        ctx.getArgs().forEach((arg) -> mentionedRoles.addAll(FinderUtil.findRoles(arg, ctx.getGuild())));
    }
    if (mentionedEmotes.isEmpty() || mentionedRoles.isEmpty()) {
        this.sendUsageInstructions(ctx);
        return;
    }
    final Emote emote = mentionedEmotes.get(0);
    if (cannotInteractWithEmote(ctx, emote)) {
        return;
    }
    emote.getManager().setRoles(new HashSet<>(mentionedRoles)).queue();
    sendSuccess(message);
    final List<String> roleNames = mentionedRoles.stream().map(Role::getName).collect(Collectors.toList());
    sendMsg(ctx, "The emote " + emote.getAsMention() + " has been locked to users that have the " + "following roles: `" + String.join("`, `", roleNames) + "`");
}
Also used : Role(net.dv8tion.jda.api.entities.Role) Message(net.dv8tion.jda.api.entities.Message) UnlockEmoteCommand.cannotInteractWithEmote(ml.duncte123.skybot.commands.guild.owner.UnlockEmoteCommand.cannotInteractWithEmote) Emote(net.dv8tion.jda.api.entities.Emote) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 12 with CommandContext

use of ml.duncte123.skybot.objects.command.CommandContext in project SkyBot by DuncteBot.

the class ShardInfoCommand method asciiInfo.

private void asciiInfo(CommandContext ctx) {
    final List<String> headers = new ArrayList<>();
    headers.add("ID");
    headers.add("Status");
    headers.add("Ping");
    headers.add("Guilds");
    headers.add("VCs");
    List<List<String>> table = new ArrayList<>();
    final int currentShard = ctx.getJDA().getShardInfo().getShardId();
    final ShardManager shardManager = ctx.getJDA().getShardManager();
    final List<JDA> shards = new ArrayList<>(shardManager.getShards());
    Collections.reverse(shards);
    for (final JDA shard : shards) {
        final List<String> row = new ArrayList<>();
        final int shardId = shard.getShardInfo().getShardId();
        row.add(shardId + (currentShard == shardId ? " (current)" : ""));
        row.add(getShardStatus(shard));
        row.add(String.valueOf(shard.getGatewayPing()));
        row.add(String.valueOf(shard.getGuildCache().size()));
        final LongLongPair channelStats = getConnectedVoiceChannels(shard);
        row.add(channelStats.getFirst() + " / " + channelStats.getSecond());
        table.add(row);
        if (table.size() == 20) {
            MessageUtils.sendMsg(ctx, makeAsciiTable(headers, table, shardManager));
            table = new ArrayList<>();
        }
    }
    if (!table.isEmpty()) {
        MessageUtils.sendMsg(ctx, makeAsciiTable(headers, table, shardManager));
    }
}
Also used : LongLongPair(ml.duncte123.skybot.objects.pairs.LongLongPair) JDA(net.dv8tion.jda.api.JDA) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ShardManager(net.dv8tion.jda.api.sharding.ShardManager)

Example 13 with CommandContext

use of ml.duncte123.skybot.objects.command.CommandContext in project SkyBot by DuncteBot.

the class AutoBanBypassCommand method execute.

@Override
public void execute(@NotNull CommandContext ctx) {
    final long checkId;
    try {
        checkId = MiscUtil.parseSnowflake(ctx.getArgs().get(0));
    } catch (NumberFormatException ignored) {
        sendMsg(ctx, "Your input (`" + ctx.getArgs().get(0) + "`) is not a valid user id.");
        return;
    }
    final DatabaseAdapter database = ctx.getDatabaseAdapter();
    final long guildId = ctx.getGuild().getIdLong();
    database.getBanBypass(guildId, checkId, (byPass) -> {
        if (byPass == null) {
            database.createBanBypass(guildId, checkId);
            sendMsg(ctx, "Single use bypass created, please note that this bypass will expire after a week if unused." + "\nPlease keep in mind that this has not unbanned any user, meaning that you will have to unban the user yourself if they are banned");
            return null;
        }
        sendMsg(ctx, "A bypass already exists for this user");
        return null;
    });
}
Also used : DatabaseAdapter(ml.duncte123.skybot.adapters.DatabaseAdapter)

Example 14 with CommandContext

use of ml.duncte123.skybot.objects.command.CommandContext in project SkyBot by DuncteBot.

the class AudioUtils method loadAndPlay.

public Future<Void> loadAndPlay(final CommandContext ctx, final String trackUrlRaw, final boolean announce) {
    final boolean isPatron = CommandUtils.isUserTagPatron(ctx.getAuthor());
    // final boolean isPatron = false;
    final String trackUrl;
    // Strip <>'s that prevent discord from embedding link resources
    if (trackUrlRaw.charAt(0) == '<' && trackUrlRaw.endsWith(">")) {
        trackUrl = trackUrlRaw.substring(1, trackUrlRaw.length() - 1);
    } else {
        trackUrl = trackUrlRaw;
    }
    final GuildMusicManager mng = getMusicManager(ctx.getJDAGuild());
    final AudioLoader loader = new AudioLoader(ctx, mng, announce, trackUrl, isPatron);
    final DBAudioRef reference = new DBAudioRef(trackUrl, null, isPatron);
    return getPlayerManager().loadItemOrdered(mng, reference, loader);
}
Also used : GuildMusicManager(ml.duncte123.skybot.audio.GuildMusicManager) DBAudioRef(ml.duncte123.skybot.audio.sourcemanagers.DBAudioRef) AudioLoader(ml.duncte123.skybot.audio.AudioLoader)

Example 15 with CommandContext

use of ml.duncte123.skybot.objects.command.CommandContext in project SkyBot by DuncteBot.

the class ChangeLogCommand method fetchLatetstGitHubCommits.

private void fetchLatetstGitHubCommits(CommandContext ctx) {
    WebUtils.ins.getJSONObject("https://api.github.com/repos/DuncteBot/SkyBot/releases/latest", (it) -> it.setRateLimiter(RateLimiter.directLimiter())).async(json -> {
        final String body = json.get("body").asText();
        final String version = json.get("tag_name").asText();
        final EmbedBuilder builder = EmbedUtils.getDefaultEmbed().setTitle("Changelog for DuncteBot v" + version, json.get("html_url").asText());
        for (final String item : body.split("\n")) {
            final String hash = item.substring(0, 7);
            final String text = item.substring(8).trim();
            builder.appendDescription(String.format("[%s](http://g.duncte.bot/%s)%n", text, hash));
        }
        // fallback if with url is too long
        if (builder.getDescriptionBuilder().length() > MessageEmbed.TEXT_MAX_LENGTH) {
            builder.setDescription(body);
        }
        final EmbedBuilder embed = builder.setFooter("Released on", null).setTimestamp(Instant.ofEpochMilli(parseTimeStamp(json.get("published_at").asText())));
        embedJson = embed.build().toData().put("type", "rich").toString();
        sendEmbed(ctx, embed);
    });
}
Also used : EmbedUtils(me.duncte123.botcommons.messaging.EmbedUtils) CommandContext(ml.duncte123.skybot.objects.command.CommandContext) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Instant(java.time.Instant) MessageUtils.sendEmbed(me.duncte123.botcommons.messaging.MessageUtils.sendEmbed) Command(ml.duncte123.skybot.objects.command.Command) JDAImpl(net.dv8tion.jda.internal.JDAImpl) RateLimiter(com.github.natanbc.reliqua.limiter.RateLimiter) WebUtils(me.duncte123.botcommons.web.WebUtils) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) DataObject(net.dv8tion.jda.api.utils.data.DataObject) ParseException(java.text.ParseException) Nonnull(javax.annotation.Nonnull) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder)

Aggregations

CommandContext (ml.duncte123.skybot.objects.command.CommandContext)9 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)7 ArrayList (java.util.ArrayList)6 User (net.dv8tion.jda.api.entities.User)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 CustomCommand (ml.duncte123.skybot.objects.command.custom.CustomCommand)4 LongLongPair (ml.duncte123.skybot.objects.pairs.LongLongPair)4 JDA (net.dv8tion.jda.api.JDA)4 Member (net.dv8tion.jda.api.entities.Member)4 Message (net.dv8tion.jda.api.entities.Message)4 ShardManager (net.dv8tion.jda.api.sharding.ShardManager)4 Nonnull (javax.annotation.Nonnull)3 DataObject (net.dv8tion.jda.api.utils.data.DataObject)3 JDAImpl (net.dv8tion.jda.internal.JDAImpl)3 GuildSetting (com.dunctebot.models.settings.GuildSetting)2 Parser (com.jagrosh.jagtag.Parser)2 Sentry (io.sentry.Sentry)2 DecimalFormat (java.text.DecimalFormat)2 HashSet (java.util.HashSet)2