Compare commits

...

10 Commits

Author SHA1 Message Date
80007fec19
feat: moved to gitea workflows for CI/CD
All checks were successful
Build and test program / Build and test (push) Successful in 19s
Signed-off-by: Louis Vallat <contact@louis-vallat.dev>
2024-09-08 18:11:42 +02:00
ffcdd46c95 Removed useless comment in DiscordManager (duplicated from code)
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
2021-04-16 20:57:38 +02:00
f27b9cb4f6 Optimized and fixed the reaction system
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
2021-04-16 19:07:10 +02:00
42dd0e8dca Added the deploy phase of the CI/CD
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
2021-04-16 16:28:51 +02:00
09be3c9959 Fix: the reaction isn't added
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
2021-04-16 16:28:31 +02:00
0375911c67 Introduced the reaction system
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
2021-04-16 15:59:58 +02:00
306e72403c Fixed some minor typos
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
2021-04-16 15:59:36 +02:00
23c842a2ac Updated the discord4j dependency version
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
2021-04-16 15:54:31 +02:00
4fb6022524 Removed unused function in Command
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
2021-04-09 09:41:53 +02:00
cf135d9ff5 Set the prefix back to + as we lost a lot of readability with the semicolon
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
2020-11-30 19:16:00 +01:00
8 changed files with 51 additions and 92 deletions

View File

@ -0,0 +1,16 @@
name: "Build and test program"
on: push
jobs:
build:
name: "Build and test"
runs-on: java-bookworm
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Compile
run: gradle --build-cache compileJava
- name: Test
run: gradle --build-cache check
- name: Package
run: gradle --build-cache assemble

View File

@ -1,77 +0,0 @@
image: docker:latest
services:
- docker:dind
stages:
- build
- test
- package
- release
# Disable the Gradle daemon for Continuous Integration servers as correctness
# is usually a priority over speed in CI environments. Using a fresh
# runtime for each build is more reliable since the runtime is completely
# isolated from any previous builds.
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
# Use TLS https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#tls-enabled
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
CONTAINER_BRANCH_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
build:
image: gradle:jdk15
stage: build
script: gradle --build-cache compileJava
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
test:
image: gradle:jdk15
stage: test
script: gradle --build-cache check
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- build
- .gradle
package:
image: gradle:jdk15
stage: package
script: gradle --build-cache assemble
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
artifacts:
paths:
- app/build/libs/app.jar
release:
stage: release
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build . -t $CONTAINER_BRANCH_IMAGE
- docker push $CONTAINER_BRANCH_IMAGE
release-master:
stage: release
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build . -t $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE
only:
- master

View File

@ -35,7 +35,7 @@ jar {
}
dependencies {
implementation 'com.discord4j:discord4j-core:3.1.1'
implementation 'com.discord4j:discord4j-core:3.1.5'
implementation 'ch.qos.logback:logback-classic:1.2.3'
implementation 'org.postgresql:postgresql:42.2.18.jre7'
implementation 'org.apache.commons:commons-lang3:3.11'

View File

@ -8,10 +8,10 @@ import xyz.vallat.louis.timer.TimerManager;
public class App {
public static final String PREFIX = ";";
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.3.3";
public static final String VERSION = "0.4.0";
private static final Logger logger = LoggerFactory.getLogger(App.class.getCanonicalName());
public static void main(String[] args) {

View File

@ -50,8 +50,4 @@ public abstract class Command {
.addField("IDENTIFIER", errorCode, false).setTimestamp(Instant.now());
})).then();
}
protected String[] getArgArray(MessageCreateEvent event) {
return event.getMessage().getContent().substring(name.length()).split(" ");
}
}

View File

@ -14,7 +14,7 @@ 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);
super(name, "Récupère (au maximum) tes 5 prochaines cours.", name);
}
@Override
@ -27,10 +27,10 @@ public class Edt extends Command {
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);
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() + "> :")
.setFooter("Liste des " + events.size() + " prochains cours", null)
.setDescription("Voici tes " + events.size() + " prochains cours, <@!" + s.getSnowflake() + "> :")
.setColor(Color.GREEN);
events.forEach(ev -> e.addField(ev.getStartEvent().toString(), ev.getSummary(), false));
e.setTimestamp(Instant.now());

View File

@ -36,10 +36,10 @@ public final class EventManager {
connection.rollback();
} else {
try {
logger.debug("'{}' events reimported, commiting.", importedEvents);
logger.debug("'{}' events re-imported, committing.", importedEvents);
connection.commit();
} catch (SQLException e) {
logger.error("An SQLExcetpion occured, rolling back.", e);
logger.error("An SQLException occurred, rolling back.", e);
connection.rollback();
}
}

View File

@ -5,17 +5,18 @@ import discord4j.core.DiscordClientBuilder;
import discord4j.core.GatewayDiscordClient;
import discord4j.core.event.domain.lifecycle.ReadyEvent;
import discord4j.core.event.domain.message.MessageCreateEvent;
import discord4j.core.event.domain.message.ReactionAddEvent;
import discord4j.core.object.entity.User;
import discord4j.core.object.presence.Activity;
import discord4j.core.object.presence.Presence;
import discord4j.core.object.reaction.ReactionEmoji;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
import xyz.vallat.louis.commands.*;
import xyz.vallat.louis.environment.EnvironmentVariables;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import static xyz.vallat.louis.App.PREFIX;
@ -23,6 +24,16 @@ public final class DiscordManager {
private static final List<Command> commands = new ArrayList<>();
private static final Logger logger = LoggerFactory.getLogger(DiscordManager.class.getCanonicalName());
private static final ReactionEmoji[] reactionAnswers = {
ReactionEmoji.unicode("\uD83E\uDD16"), // robot head
ReactionEmoji.unicode("\uD83D\uDE0B"), // smile with tongue out
ReactionEmoji.unicode("\uD83E\uDD70"), // smile with hearts
ReactionEmoji.unicode("\uD83E\uDD29"), // smile with stars in eyes
ReactionEmoji.unicode("\uD83D\uDE01"), // smile
ReactionEmoji.unicode("\uD83D\uDE07"), // innocent
ReactionEmoji.unicode("\uD83D\uDCAF"), // 1OO
ReactionEmoji.unicode("\uD83E\uDDBE") // robot arm
};
private static GatewayDiscordClient discordClient;
static {
@ -50,6 +61,18 @@ public final class DiscordManager {
.subscribe();
}
private static void registerReactionEvents() {
discordClient.getEventDispatcher().on(ReactionAddEvent.class)
.flatMap(ReactionAddEvent::getMessage)
.filter(message -> message.getAuthor().isPresent()
&& message.getAuthor().get().equals(discordClient.getSelf().block()))
.filter(message -> message.getReactions().stream()
.noneMatch(r -> message.getReactors(r.getEmoji()).toStream()
.anyMatch(u -> u.equals(discordClient.getSelf().block()))))
.flatMap(message -> message.addReaction(reactionAnswers[new Random().nextInt(reactionAnswers.length)]).then())
.subscribe();
}
public static void login() {
discordClient = DiscordClientBuilder.create(System.getenv(EnvironmentVariables.DISCORD_TOKEN.getValue()))
.build().login().retry(2)
@ -66,6 +89,7 @@ public final class DiscordManager {
logger.info("Logged in on Discord as {}#{}.", self.getUsername(), self.getDiscriminator());
});
registerDiscordCommands();
registerReactionEvents();
}
public static Mono<Void> sendPrivateMessageToUser(String snowflake, String message) {