use of ml.duncte123.skybot.objects.command.CommandContext in project SkyBot by duncte123.
the class TokenCommand method execute.
@Override
public void execute(@Nonnull CommandContext ctx) {
final List<String> args = ctx.getArgs();
final Matcher matcher = TOKEN_REGEX.matcher(args.get(0));
if (!matcher.matches()) {
sendMsg(ctx, "Your input `" + args.get(0) + "` has the wrong token format.");
return;
}
final DuncteApis apis = ctx.getVariables().getApis();
final JsonNode json = apis.decodeToken(args.get(0));
if (json.get("success").asBoolean()) {
handleSuccess(args.get(0), json.get("data"), ctx);
return;
}
final JsonNode error = json.get("error");
final String errorType = error.get("type").asText();
final String errorMessage = error.get("message").asText();
sendMsg(ctx, String.format("Invalid token: (%s) %s", errorType, errorMessage));
}
use of ml.duncte123.skybot.objects.command.CommandContext in project SkyBot by duncte123.
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 CommandManager method runCustomCommand.
private void runCustomCommand(ICommand cmd, String invoke, List<String> args, GuildMessageReceivedEvent event) {
final CustomCommand cusomCommand = (CustomCommand) cmd;
if (cusomCommand.getGuildId() != event.getGuild().getIdLong()) {
return;
}
try {
MDC.put("command.custom.message", cusomCommand.getMessage());
final Parser parser = CommandUtils.getParser(new CommandContext(invoke, args, event, variables));
final String message = parser.parse(cusomCommand.getMessage());
final MessageConfig.Builder messageBuilder = MessageConfig.Builder.fromEvent(event);
final DataObject object = parser.get("embed");
boolean hasContent = false;
if (!message.isEmpty()) {
messageBuilder.setMessage("\u200B" + message);
hasContent = true;
}
if (object != null) {
final JDAImpl jda = (JDAImpl) event.getJDA();
final EmbedBuilder embed = new EmbedBuilder(jda.getEntityBuilder().createMessageEmbed(object));
messageBuilder.addEmbed(true, embed);
hasContent = true;
}
if (hasContent) {
sendMsg(messageBuilder.build());
}
parser.clear();
} catch (Exception e) {
sendMsg(MessageConfig.Builder.fromEvent(event).setMessage("Error with parsing custom command: " + e.getMessage()).build());
Sentry.captureException(e);
}
}
use of ml.duncte123.skybot.objects.command.CommandContext in project SkyBot by DuncteBot.
the class CommandManager method runNormalCommand.
private void runNormalCommand(ICommand cmd, String invoke, List<String> args, GuildMessageReceivedEvent event) {
if (cmd.getCategory() == CommandCategory.NSFW && this.isSafeForWork(event)) {
sendMsg(MessageConfig.Builder.fromEvent(event).setMessage("Woops, this channel is not marked as NSFW.\n" + "Please mark this channel as NSFW to use this command").build());
return;
}
MDC.put("command.class", cmd.getClass().getName());
LOGGER.info("Dispatching command \"{}\" in guild \"{}\" with {}", cmd.getClass().getSimpleName(), event.getGuild(), args);
cmd.executeCommand(new CommandContext(invoke, args, event, variables));
}
use of ml.duncte123.skybot.objects.command.CommandContext in project SkyBot by DuncteBot.
the class UnwarnCommand method execute.
@Override
public void execute(@Nonnull CommandContext ctx) {
final List<Member> mentioned = ctx.getMentionedArg(0);
if (mentioned.isEmpty()) {
sendMsg(ctx, "No users found for query");
return;
}
final DunctebotGuild guild = ctx.getGuild();
final User target = mentioned.get(0).getUser();
ctx.getDatabaseAdapter().deleteLatestWarningForUser(target.getIdLong(), guild.getIdLong(), (latestWarning) -> {
if (latestWarning == null) {
sendMsg(ctx, "This user has no active warnings");
return null;
}
sendMsg(ctx, String.format("Latest warning for _%s_ removed\nReason was: %s", target.getAsTag(), latestWarning.getReason()));
modLog(String.format("**%s** removed the latest warning for **%s**\nReason was: %s", ctx.getAuthor().getAsTag(), target.getAsTag(), latestWarning.getReason()), guild);
return null;
});
}
Aggregations