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) + "`");
}
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));
}
}
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;
});
}
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);
}
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);
});
}
Aggregations