use of ml.duncte123.skybot.adapters.DatabaseAdapter in project SkyBot by DuncteBot.
the class SQLiteTimers method checkUnbansAndUnmutes.
private static void checkUnbansAndUnmutes(Variables variables) {
variables.getDatabaseAdapter().getExpiredBansAndMutes((bans, mutes) -> {
final DatabaseAdapter adapter = variables.getDatabaseAdapter();
handleUnban(bans, adapter, variables);
handleUnmute(mutes, adapter, variables);
return null;
});
}
use of ml.duncte123.skybot.adapters.DatabaseAdapter 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.adapters.DatabaseAdapter in project SkyBot by duncte123.
the class AirUtils method handleExpiredReminders.
public static void handleExpiredReminders(List<Reminder> reminders, DatabaseAdapter adapter) {
// Get the shardManager and a list of ints to purge the ids for
final ShardManager shardManager = SkyBot.getInstance().getShardManager();
final List<Integer> toPurge = new ArrayList<>();
for (final Reminder reminder : reminders) {
// The reminder message template
final String message = String.format("%s you asked me to remind you about \"%s\"", TimeFormat.RELATIVE.format(reminder.getCreate_date()), reminder.getReminder().trim());
// If we have a channel send the message to that
if (reminder.getIn_channel()) {
final long channelId = reminder.getChannel_id();
final TextChannel channel = shardManager.getTextChannelById(channelId);
// skipping the continue statement makes sure that we roll into the dm part of this
if (channel != null) {
// Add the reminder to the list of the reminders to purge
toPurge.add(reminder.getId());
sendMsg(new MessageConfig.Builder().setChannel(channel).setMessage(String.format("<@%s>, %s", reminder.getUser_id(), message)).replyTo(reminder.getMessage_id()).build());
// go to the next one and don't run the user code if a channel was found
continue;
}
}
try {
Objects.requireNonNull(shardManager.getShardById(0)).openPrivateChannelById(reminder.getUser_id()).flatMap((c) -> c.sendMessage(message + "\n" + reminder.getJumpUrl())).complete();
toPurge.add(reminder.getId());
} catch (ErrorResponseException errorResponseEx) {
final ErrorResponse errorResponse = errorResponseEx.getErrorResponse();
if (// The account probably got deleted or something
errorResponse == ErrorResponse.UNKNOWN_USER || // we cannot dm this user (has dms blocked?)
errorResponse == ErrorResponse.CANNOT_SEND_TO_USER) {
toPurge.add(reminder.getId());
}
} catch (Exception e) {
Sentry.captureException(e);
}
}
// get a date that is 2 days in the future
final OffsetDateTime plusTwoDays = OffsetDateTime.now(ZoneOffset.UTC).plus(2L, ChronoUnit.DAYS);
// Remove any reminders that have not been removed after 2 days
final List<Integer> extraRemoval = reminders.stream().filter((reminder) -> reminder.getReminder_date().isAfter(plusTwoDays)).map(Reminder::getId).collect(Collectors.toList());
toPurge.addAll(extraRemoval);
if (!toPurge.isEmpty()) {
adapter.purgeRemindersSync(toPurge);
}
}
Aggregations