Added +edt command and bumped version to 0-2-SNAPSHOT
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
ac4f691c92
commit
9aef9ac706
@ -11,7 +11,7 @@ public class App {
|
||||
public static final String PREFIX = "+";
|
||||
public static final String NAME = "PrésencEirb";
|
||||
public static final String DESCRIPTION = "Tu as pensé à pointer ?";
|
||||
public static final String VERSION = "0.1-SNAPSHOT";
|
||||
public static final String VERSION = "0.2-SNAPSHOT";
|
||||
private static final Logger logger = LoggerFactory.getLogger(App.class.getCanonicalName());
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
41
app/src/main/java/xyz/vallat/louis/commands/Edt.java
Normal file
41
app/src/main/java/xyz/vallat/louis/commands/Edt.java
Normal file
@ -0,0 +1,41 @@
|
||||
package xyz.vallat.louis.commands;
|
||||
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.rest.util.Color;
|
||||
import reactor.core.publisher.Mono;
|
||||
import xyz.vallat.louis.managers.database.EventManager;
|
||||
import xyz.vallat.louis.managers.database.StudentManager;
|
||||
import xyz.vallat.louis.managers.database.dao.Event;
|
||||
import xyz.vallat.louis.managers.database.dao.Student;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
public class Edt extends Command {
|
||||
|
||||
public Edt(String name) {
|
||||
super(name, "Récupère tes 5 prochaines cours (si tu en as 5 ou plus).", name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> execute(MessageCreateEvent event) {
|
||||
return event.getMessage().getChannel().flatMap(messageChannel -> {
|
||||
if (event.getMessage().getAuthor().isEmpty())
|
||||
return messageChannel.createMessage("Je ne sais pas qui tu es...");
|
||||
Student s = StudentManager.getStudentFromSnowflake(event.getMessage().getAuthor().get().getId().asString());
|
||||
if (s == null)
|
||||
return messageChannel.createMessage("On dirait que tu n'es pas dans ma base de données ! Es tu inscrit ?");
|
||||
return messageChannel.createEmbed(e -> {
|
||||
List<Event> events = EventManager.getNextEventsFromStudent(s);
|
||||
if (events.size() >= 5) events = events.subList(0, 5);
|
||||
e.setTitle("Prochains cours")
|
||||
.setFooter("Liste des 5 prochains cours", null)
|
||||
.setDescription("Voici tes 5 prochains cours, <@!" + s.getSnowflake() + "> :")
|
||||
.setColor(Color.GREEN);
|
||||
events.forEach(ev -> e.addField(ev.getStartEvent().toString(), ev.getSummary(), false));
|
||||
e.setTimestamp(Instant.now());
|
||||
});
|
||||
}).then().onErrorResume(t -> fatalError(event, t));
|
||||
|
||||
}
|
||||
}
|
@ -85,7 +85,8 @@ public final class EventManager {
|
||||
public static List<Event> getNextEventsFromStudent(Student s) {
|
||||
logger.debug("Getting events from student '{}'.", s.getSnowflake());
|
||||
String sql = "SELECT id, summary, start_event, end_event" +
|
||||
" FROM events WHERE students_id = ? AND (start_event + interval '5 minutes') >= NOW();";
|
||||
" FROM events WHERE students_id = ? AND (start_event + interval '5 minutes') >= NOW()" +
|
||||
" ORDER BY start_event;";
|
||||
List<Event> events = new ArrayList<>();
|
||||
try (Connection connection = DBManager.getConnection()) {
|
||||
try (PreparedStatement stmt = connection.prepareStatement(sql)) {
|
||||
|
@ -29,6 +29,7 @@ public final class DiscordManager {
|
||||
commands.add(new Inscription(PREFIX + "inscription"));
|
||||
commands.add(new Desinscription(PREFIX + "désinscription"));
|
||||
commands.add(new Lien(PREFIX + "lien"));
|
||||
commands.add(new Edt(PREFIX + "edt"));
|
||||
commands.add(new Version(PREFIX + "version"));
|
||||
commands.add(new Aide(PREFIX + "aide"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user