Skip to content

Commit 80c4607

Browse files
Added null checks and made requested changes
1 parent 954be30 commit 80c4607

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/main/java/net/javadiscord/javabot/systems/notification/GuildNotificationService.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.javadiscord.javabot.systems.notification;
22

3+
import lombok.extern.slf4j.Slf4j;
34
import net.dv8tion.jda.api.entities.Guild;
45
import net.dv8tion.jda.api.entities.MessageEmbed;
56
import net.javadiscord.javabot.Bot;
@@ -8,6 +9,7 @@
89
/**
910
* Sends notifications within a single {@link Guild}.
1011
*/
12+
@Slf4j
1113
public final class GuildNotificationService extends NotificationService {
1214

1315
private final Guild guild;
@@ -18,19 +20,57 @@ public GuildNotificationService(Guild guild) {
1820
this.config = Bot.config.get(guild);
1921
}
2022

23+
/**
24+
* Sends a {@link MessageEmbed} to the Guild's log channel.
25+
*
26+
* @param embed The {@link MessageEmbed} to send.
27+
*/
2128
public void sendLogChannelNotification(MessageEmbed embed) {
29+
if (config.getModeration().getLogChannel() == null) {
30+
log.warn("Could not find Log Channel for Guild {}", guild.getName());
31+
return;
32+
}
2233
this.sendMessageChannelNotification(config.getModeration().getLogChannel(), embed);
2334
}
2435

36+
/**
37+
* Sends a simple Message to the Guild's log channel.
38+
*
39+
* @param string The message that should be sent.
40+
* @param args Optional args for formatting.
41+
*/
2542
public void sendLogChannelNotification(String string, Object... args) {
43+
if (config.getModeration().getLogChannel() == null) {
44+
log.warn("Could not find Log Channel for Guild {}", guild.getName());
45+
return;
46+
}
2647
this.sendMessageChannelNotification(config.getModeration().getLogChannel(), string, args);
2748
}
2849

50+
/**
51+
* Sends a {@link MessageEmbed} to the Guild's message log channel.
52+
*
53+
* @param embed The {@link MessageEmbed} to send.
54+
*/
2955
public void sendMessageLogChannelNotification(MessageEmbed embed) {
56+
if (config.getMessageCache().getMessageCacheLogChannel() == null) {
57+
log.warn("Could not find Message Log Channel for Guild {}", guild.getName());
58+
return;
59+
}
3060
this.sendMessageChannelNotification(config.getMessageCache().getMessageCacheLogChannel(), embed);
3161
}
3262

63+
/**
64+
* Sends a simple Message to the Guild's message log channel.
65+
*
66+
* @param string The message that should be sent.
67+
* @param args Optional args for formatting.
68+
*/
3369
private void sendMessageLogChannelNotification(String string, Object... args) {
70+
if (config.getMessageCache().getMessageCacheLogChannel() == null) {
71+
log.warn("Could not find Message Log Channel for Guild {}", guild.getName());
72+
return;
73+
}
3474
this.sendMessageChannelNotification(config.getMessageCache().getMessageCacheLogChannel(), string, args);
3575
}
3676
}

src/main/java/net/javadiscord/javabot/systems/notification/QOTWNotificationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public QOTWNotificationService(User user, Guild guild) {
4646
QuestionPointsRepository dao = new QuestionPointsRepository(connection);
4747
account = dao.getAccountByUserId(user.getIdLong());
4848
} catch (SQLException e) {
49-
e.printStackTrace();
49+
log.error("Could not find Account with user Id: {}", user.getIdLong(), e);
5050
account = null;
5151
}
5252
this.account = account;

src/main/java/net/javadiscord/javabot/systems/qotw/QOTWJob.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected void execute(JobExecutionContext context, JDA jda) throws JobExecution
4545
} else {
4646
QOTWQuestion question = nextQuestion.get();
4747
QOTWConfig qotw = config.getQotw();
48-
qotw.getSubmissionChannel().getThreadChannels().forEach(thread -> thread.getManager().setArchived(true).queue());
48+
qotw.getSubmissionChannel().getThreadChannels().forEach(thread -> thread.getManager().setLocked(true).queue());
4949
qotw.getSubmissionChannel().getManager()
5050
.putRolePermissionOverride(guild.getIdLong(), Collections.singleton(Permission.MESSAGE_SEND_IN_THREADS), Collections.emptySet())
5151
.queue();

0 commit comments

Comments
 (0)