use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project JavaBot by Java-Discord.
the class JamInfoSubcommand method fetchJam.
private Jam fetchJam(SlashCommandInteractionEvent event) {
Jam jam;
try (Connection con = Bot.dataSource.getConnection()) {
JamRepository jamRepository = new JamRepository(con);
OptionMapping idOption = event.getOption("id");
if (idOption == null) {
if (event.getGuild() == null) {
throw new RuntimeException("Cannot find active Jam without Guild context.");
}
jam = jamRepository.getActiveJam(event.getGuild().getIdLong());
} else {
jam = jamRepository.getJam(idOption.getAsLong());
}
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("Error occurred while fetching the Jam info.", e);
}
return jam;
}
use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project JavaBot by Java-Discord.
the class EditJamSubcommand method handleJamCommand.
@Override
protected ReplyCallbackAction handleJamCommand(SlashCommandInteractionEvent event, Jam activeJam, Connection con, JamConfig config) throws SQLException {
OptionMapping propertyNameOption = event.getOption("property");
OptionMapping propertyValueOption = event.getOption("value");
if (propertyNameOption == null || propertyValueOption == null) {
return Responses.warning(event, "Missing required arguments.");
}
String value = propertyValueOption.getAsString();
if (value.equalsIgnoreCase("null")) {
value = null;
}
var propertyHandler = propertyHandlers.get(propertyNameOption.getAsString().toLowerCase());
if (propertyHandler == null) {
return Responses.warning(event, "Unsupported Property", "Only the following properties may be updated: " + String.join(", ", propertyHandlers.keySet()));
}
return propertyHandler.updateProperty(event, con, activeJam, value);
}
use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project JavaBot by Java-Discord.
the class PlanNewJamSubcommand method handleSlashCommandInteraction.
@Override
public ReplyCallbackAction handleSlashCommandInteraction(SlashCommandInteractionEvent event) {
OptionMapping startOption = event.getOption("start-date");
if (startOption == null) {
return Responses.warning(event, "Missing start date.");
}
LocalDate startsAt;
try {
startsAt = LocalDate.parse(startOption.getAsString(), DateTimeFormatter.ofPattern("dd-MM-yyyy"));
} catch (DateTimeParseException e) {
return Responses.warning(event, "Invalid start date. Must be formatted as `dd-MM-yyyy`. For example, June 5th, 2017 is formatted as `05-06-2017`.");
}
if (startsAt.isBefore(LocalDate.now())) {
return Responses.warning(event, "Invalid start date. The Jam cannot start in the past.");
}
long guildId = Objects.requireNonNull(event.getGuild()).getIdLong();
String name = null;
OptionMapping nameOption = event.getOption("name");
if (nameOption != null) {
name = nameOption.getAsString();
}
// So we can pass the variable in the lambda expression.
final String nameFinal = name;
Bot.asyncPool.submit(() -> this.createNewJam(event.getHook(), guildId, nameFinal, startsAt));
return event.deferReply();
}
use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project JavaBot by Java-Discord.
the class WarnsCommand method handleSlashCommandInteraction.
@Override
public ReplyCallbackAction handleSlashCommandInteraction(SlashCommandInteractionEvent event) throws ResponseException {
OptionMapping warnsOption = event.getOption("user");
Member member = warnsOption == null ? event.getMember() : warnsOption.getAsMember();
if (member == null)
return Responses.error(event, "Member is missing.");
LocalDateTime cutoff = LocalDateTime.now().minusDays(Bot.config.get(event.getGuild()).getModeration().getWarnTimeoutDays());
try (var con = Bot.dataSource.getConnection()) {
return event.replyEmbeds(buildWarnsEmbed(new WarnRepository(con).getWarnsByUserId(member.getIdLong(), cutoff), member));
} catch (SQLException e) {
throw ResponseException.error("Could not get warns from user: " + member.getUser().getAsTag(), e);
}
}
use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project JavaBot by Java-Discord.
the class RemoveQuestionSubcommand method handleCommand.
@Override
protected ReplyCallbackAction handleCommand(SlashCommandInteractionEvent event, Connection con, long guildId) throws SQLException {
OptionMapping idOption = event.getOption("id");
if (idOption == null) {
return Responses.warning(event, "Missing required arguments.");
}
long id = idOption.getAsLong();
boolean removed = new QuestionQueueRepository(con).removeQuestion(guildId, id);
if (removed) {
return Responses.success(event, "Question Removed", "The question with id `" + id + "` has been removed.");
} else {
return Responses.warning(event, "Could not remove question with id `" + id + "`. Are you sure it exists?");
}
}
Aggregations