Skip to content

Commit

Permalink
feat: migrate to Skolengo
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceh121 committed Nov 29, 2023
1 parent 92acffe commit 8100b75
Show file tree
Hide file tree
Showing 13 changed files with 499 additions and 102 deletions.
15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>vinceh121-snapshots</id>
<name>vinceh121's Maven repository</name>
<url>https://maven.vinceh121.me/snapshots</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -52,6 +57,16 @@
<artifactId>jkdecole</artifactId>
<version>fdb58c3efdf49c8a6a3df3c5e851fc42bca00ac6</version>
</dependency>
<dependency>
<groupId>me.vinceh121.jskolengo</groupId>
<artifactId>wrapper</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>oauth2-oidc-sdk</artifactId>
<version>11.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.quartz-scheduler/quartz -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import java.util.Date;
import java.util.List;

public class UserInstance {
public abstract class AbstractUserInstance {
private String id;
private String kdecoleToken, adderId, channelId, guildId, endpoint;
private String adderId;
private String channelId;
private String guildId;
private Date lastCheck = new Date(0L);
private boolean showWarnings = true, allowOthers = false, alwaysShowWarnings = false;
private List<RelayType> relays = new ArrayList<>();
private boolean showWarnings = true;
private boolean allowOthers = false;
private boolean alwaysShowWarnings = false;
private final List<RelayType> relays = new ArrayList<>();

public String getId() {
return this.id;
Expand All @@ -19,14 +23,6 @@ public void setId(final String id) {
this.id = id;
}

public String getKdecoleToken() {
return this.kdecoleToken;
}

public void setKdecoleToken(final String kdecoleToken) {
this.kdecoleToken = kdecoleToken;
}

public String getAdderId() {
return this.adderId;
}
Expand All @@ -51,14 +47,6 @@ public void setLastCheck(final Date lastCheck) {
this.lastCheck = lastCheck;
}

public String getEndpoint() {
return this.endpoint;
}

public void setEndpoint(final String endpoint) {
this.endpoint = endpoint;
}

public boolean isShowWarnings() {
return this.showWarnings;
}
Expand Down Expand Up @@ -87,10 +75,6 @@ public List<RelayType> getRelays() {
return this.relays;
}

public void setRelays(final List<RelayType> relays) {
this.relays = relays;
}

public String getGuildId() {
return this.guildId;
}
Expand All @@ -99,30 +83,4 @@ public void setGuildId(final String guildId) {
this.guildId = guildId;
}

@Override
public String toString() {
return "UserInstance [id="
+ id
+ ", kdecoleToken="
+ kdecoleToken
+ ", adderId="
+ adderId
+ ", channelId="
+ channelId
+ ", guildId="
+ guildId
+ ", endpoint="
+ endpoint
+ ", lastCheck="
+ lastCheck
+ ", showWarnings="
+ showWarnings
+ ", allowOthers="
+ allowOthers
+ ", alwaysShowWarnings="
+ alwaysShowWarnings
+ ", relays="
+ relays
+ "]";
}
}
6 changes: 3 additions & 3 deletions src/main/java/me/vinceh121/knb/CommandContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class CommandContext {
private MessageReceivedEvent event;
private List<String> args;
private UserInstance userInstance;
private KdecoleUserInstance userInstance;
private boolean adminCalled;

public MessageReceivedEvent getEvent() {
Expand All @@ -26,11 +26,11 @@ public void setArgs(final List<String> args) {
this.args = args;
}

public UserInstance getUserInstance() {
public KdecoleUserInstance getUserInstance() {
return this.userInstance;
}

public void setUserInstance(final UserInstance userInstance) {
public void setUserInstance(final KdecoleUserInstance userInstance) {
this.userInstance = userInstance;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/vinceh121/knb/CommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ public void onMessageReceived(MessageReceivedEvent event) {
ctx.setAdminCalled(this.knb.isUserAdmin(event.getAuthor().getIdLong()));

if (cmd.isAuthenticatedCommand()) {
final UserInstance ui;
final KdecoleUserInstance ui;
try {
ui = this.knb.getTableInstances()
.filter(r.hashMap("channelId", event.getChannel().getId()))
.run(this.knb.getDbCon(), UserInstance.class)
.run(this.knb.getDbCon(), KdecoleUserInstance.class)
.first();
} catch (final NoSuchElementException e) {
event.getChannel().sendMessage("Il n'y a pas d'intégration dans ce canal").queue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import net.dv8tion.jda.api.entities.MessageEmbed.Field;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;

public class CheckingJob implements Job {
public class KdecoleCheckingJob implements Job {
public static final int COLOR_ARTICLE = 0xff7b1c;
private static final Logger LOG = LogManager.getLogger(CheckingJob.class);
private static final Logger LOG = LogManager.getLogger(KdecoleCheckingJob.class);
private Counter metricNewsCount, metricEmailsCount, metricGradesCount;
private Timer metricProcessTime;

Expand All @@ -51,7 +51,7 @@ public void execute(final JobExecutionContext context) throws JobExecutionExcept

this.setupMetrics(knb.getMetricRegistry());

knb.getAllValidInstances().forEach(u -> {
knb.getAllValidKdecoleInstances().forEach(u -> {
this.metricProcessTime.time(() -> {
final JKdecole kdecole = knb.getKdecole();
kdecole.setToken(u.getKdecoleToken());
Expand All @@ -60,7 +60,7 @@ public void execute(final JobExecutionContext context) throws JobExecutionExcept
try {
info = kdecole.getUserInfo();
} catch (final Exception e) {
CheckingJob.LOG.error(
KdecoleCheckingJob.LOG.error(
new FormattedMessage("Error while fetching user info for instance {}", u.getId()), e);
info = new UserInfo();
info.setNom("");
Expand All @@ -87,7 +87,7 @@ public void execute(final JobExecutionContext context) throws JobExecutionExcept
knb.getJda().getPresence().setActivity(oldAct);
}

private void processGrades(final Knb knb, final JKdecole kde, final UserInfo info, final UserInstance ui) {
private void processGrades(final Knb knb, final JKdecole kde, final UserInfo info, final KdecoleUserInstance ui) {
final TextChannel chan = knb.getJda().getTextChannelById(ui.getChannelId());
final List<Grade> grades;
try {
Expand All @@ -96,7 +96,7 @@ private void processGrades(final Knb knb, final JKdecole kde, final UserInfo inf
this.sendWarning(knb, chan, ui, "Votre ENT n'a pas de module de notes activé");
return;
} catch (final Exception e) {
CheckingJob.LOG.error(new FormattedMessage("Error while getting grades for instance {}", ui.getId()), e);
KdecoleCheckingJob.LOG.error(new FormattedMessage("Error while getting grades for instance {}", ui.getId()), e);
this.sendWarning(knb, chan, ui, "Une érreur est survenue en récupérant les nouvelles notes: " + e);
return;
}
Expand All @@ -115,7 +115,7 @@ private void processGrades(final Knb knb, final JKdecole kde, final UserInfo inf

embBuild.setAuthor("Kdecole", "https://github.com/vinceh121/kdecole-notification-bot",
"https://cdn.discordapp.com/avatars/691655008076300339/4f492132883b1aa4f5984fe2eab9fa09.png");
embBuild.setColor(CheckingJob.COLOR_ARTICLE);
embBuild.setColor(KdecoleCheckingJob.COLOR_ARTICLE);
embBuild.setTimestamp(oldest.toInstant());
embBuild.setTitle("Nouvelles notes");
embBuild.setFooter(estabName);
Expand All @@ -130,15 +130,15 @@ private void processGrades(final Knb knb, final JKdecole kde, final UserInfo inf
chan.sendMessageEmbeds(emb).queue();
}

private void processEmails(final Knb knb, final JKdecole kde, final UserInfo info, final UserInstance ui) {
private void processEmails(final Knb knb, final JKdecole kde, final UserInfo info, final KdecoleUserInstance ui) {
final TextChannel chan = knb.getJda().getTextChannelById(ui.getChannelId());
final List<CommunicationPreview> coms;
try {
coms = knb.fetchNewMailsForInstance(kde, ui);
} catch (final Exception e) {
CheckingJob.LOG
KdecoleCheckingJob.LOG
.error(new FormattedMessage("Error while getting communications for instance {}", ui.getId()), e);
this.sendWarning(knb, chan, ui, "Une érreur est survenue en récupérant les nouvelles communications: " + e);
this.sendWarning(knb, chan, ui, "Une erreur est survenue en récupérant les nouvelles communications: " + e);
return;
}

Expand All @@ -157,7 +157,7 @@ private void processEmails(final Knb knb, final JKdecole kde, final UserInfo inf

embBuild.setAuthor("Kdecole", "https://github.com/vinceh121/kdecole-notification-bot",
"https://cdn.discordapp.com/avatars/691655008076300339/4f492132883b1aa4f5984fe2eab9fa09.png");
embBuild.setColor(CheckingJob.COLOR_ARTICLE);
embBuild.setColor(KdecoleCheckingJob.COLOR_ARTICLE);
embBuild.setTimestamp(oldest.toInstant());
embBuild.setTitle("Nouvelles communications");
embBuild.setFooter(estabName);
Expand All @@ -172,14 +172,14 @@ private void processEmails(final Knb knb, final JKdecole kde, final UserInfo inf
chan.sendMessageEmbeds(emb).queue();
}

private void processArticles(final Knb knb, final JKdecole kde, final UserInfo info, final UserInstance ui) {
private void processArticles(final Knb knb, final JKdecole kde, final UserInfo info, final KdecoleUserInstance ui) {
final TextChannel chan = knb.getJda().getTextChannelById(ui.getChannelId());
final List<Article> news;
try {
news = knb.fetchNewsForInstance(kde, ui);
} catch (final Exception e) {
CheckingJob.LOG.error(new FormattedMessage("Error while getting news for instance {}", ui.getId()), e);
this.sendWarning(knb, chan, ui, "Une érreur est survenue en récupérant les nouveaux articles: " + e);
KdecoleCheckingJob.LOG.error(new FormattedMessage("Error while getting news for instance {}", ui.getId()), e);
this.sendWarning(knb, chan, ui, "Une erreur est survenue en récupérant les nouveaux articles: " + e);
return;
}

Expand All @@ -197,7 +197,7 @@ private void processArticles(final Knb knb, final JKdecole kde, final UserInfo i

embBuild.setAuthor("Kdecole", "https://github.com/vinceh121/kdecole-notification-bot",
"https://cdn.discordapp.com/avatars/691655008076300339/4f492132883b1aa4f5984fe2eab9fa09.png");
embBuild.setColor(CheckingJob.COLOR_ARTICLE);
embBuild.setColor(KdecoleCheckingJob.COLOR_ARTICLE);
embBuild.setTimestamp(oldest.toInstant());
embBuild.setTitle("Nouveaux articles");
embBuild.setFooter(estabName);
Expand All @@ -211,13 +211,13 @@ private void processArticles(final Knb knb, final JKdecole kde, final UserInfo i
chan.sendMessageEmbeds(emb).queue();
}

private void processHomework(final Knb knb, final JKdecole kde, final UserInfo info, final UserInstance ui) {
private void processHomework(final Knb knb, final JKdecole kde, final UserInfo info, final KdecoleUserInstance ui) {
final TextChannel chan = knb.getJda().getTextChannelById(ui.getChannelId());
final List<Homework> hws;
try {
hws = knb.fetchAgendaForInstance(kde, ui);
} catch (final Exception e) {
CheckingJob.LOG.error(new FormattedMessage("Error while getting homework for instance {}", ui.getId()), e);
KdecoleCheckingJob.LOG.error(new FormattedMessage("Error while getting homework for instance {}", ui.getId()), e);
this.sendWarning(knb, chan, ui, "Une érreur est survenue en récupérant les nouveaux devoirs: " + e);
return;
}
Expand All @@ -236,7 +236,7 @@ private void processHomework(final Knb knb, final JKdecole kde, final UserInfo i

embBuild.setAuthor("Kdecole", "https://github.com/vinceh121/kdecole-notification-bot",
"https://cdn.discordapp.com/avatars/691655008076300339/4f492132883b1aa4f5984fe2eab9fa09.png");
embBuild.setColor(CheckingJob.COLOR_ARTICLE);
embBuild.setColor(KdecoleCheckingJob.COLOR_ARTICLE);
embBuild.setTimestamp(oldest.toInstant());
embBuild.setTitle("Nouveaux devoirs");
embBuild.setFooter(estabName);
Expand All @@ -250,7 +250,7 @@ private void processHomework(final Knb knb, final JKdecole kde, final UserInfo i
chan.sendMessageEmbeds(emb).queue();
}

private void sendWarning(final Knb knb, final TextChannel chan, final UserInstance ui, final String text) {
private void sendWarning(final Knb knb, final TextChannel chan, final KdecoleUserInstance ui, final String text) {
if (ui.isShowWarnings() || ui.isAlwaysShowWarnings()) {
chan.sendMessage(text
+ "\n\n"
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/me/vinceh121/knb/KdecoleUserInstance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package me.vinceh121.knb;

public class KdecoleUserInstance extends AbstractUserInstance {
private String kdecoleToken, endpoint;

public String getKdecoleToken() {
return this.kdecoleToken;
}

public void setKdecoleToken(final String kdecoleToken) {
this.kdecoleToken = kdecoleToken;
}

public String getEndpoint() {
return this.endpoint;
}

public void setEndpoint(final String endpoint) {
this.endpoint = endpoint;
}

@Override
public String toString() {
return "KdecoleUserInstance [kdecoleToken="
+ kdecoleToken
+ ", endpoint="
+ endpoint
+ ", getId()="
+ getId()
+ ", getAdderId()="
+ getAdderId()
+ ", getChannelId()="
+ getChannelId()
+ ", getLastCheck()="
+ getLastCheck()
+ ", isShowWarnings()="
+ isShowWarnings()
+ ", isAllowOthers()="
+ isAllowOthers()
+ ", isAlwaysShowWarnings()="
+ isAlwaysShowWarnings()
+ ", getRelays()="
+ getRelays()
+ ", getGuildId()="
+ getGuildId()
+ "]";
}
}
Loading

0 comments on commit 8100b75

Please sign in to comment.