use of ml.duncte123.skybot.objects.command.CommandContext in project SkyBot by duncte123.
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 duncte123.
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;
});
}
use of ml.duncte123.skybot.objects.command.CommandContext in project SkyBot by duncte123.
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 duncte123.
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 duncte123.
the class PronounsCheckCommand method execute.
@Override
public void execute(@Nonnull CommandContext ctx) {
final User target = getMentionedUser(ctx);
final long userId = target.getIdLong();
final JsonNode json = ctx.getApis().getPronouns(userId);
final boolean isSelf = userId == ctx.getAuthor().getIdLong();
if (json == null) {
sendMsg(ctx, (isSelf ? "You do" : target.getName() + " does") + " not have any pronouns set");
return;
}
final String pronouns = json.get("pronouns").asText();
final String singular = json.get("singular").asBoolean() ? "Singular" : "Plural";
final String userName = isSelf ? "Your" : target.getName() + "'s";
final String format = "%s current pronouns are:%n**%s** (%s)";
sendMsg(ctx, String.format(format, userName, pronouns, singular));
}
Aggregations