Skip to content

Commit f33aceb

Browse files
Merge pull request #470 from Java-Discord/fix/startup
2 parents f62e5d3 + b013be0 commit f33aceb

File tree

5 files changed

+29
-23
lines changed

5 files changed

+29
-23
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Usage
66

7-
To start up, run the bot once, and it will generate a `config` directory. Stop the bot, and set the up **all of the following values**:
7+
To start up, run the bot once, and it will generate a `config` directory. Stop the bot, and set the up **all the following values**:
88
- in `systems.json`
99
- `jdaBotToken` to your bot's token
1010
- (some `adminUsers` which, e.g., can manipulate the database)
@@ -14,6 +14,8 @@ To start up, run the bot once, and it will generate a `config` directory. Stop t
1414
- `moderation.adminRoleId` to a roleId
1515
- `jam.adminRoleId` to a roleId
1616

17+
NOTE: Don't forget to enable the Presence Intent, Server Members Intent and Message Content Intent on the Discord Developer Portal!
18+
1719
Note that this is just what is required for the bot to start. Certain features may require other values to be set.
1820

1921
# Configuration

src/main/java/net/discordjug/javabot/SpringConfig.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.concurrent.Executors;
66
import java.util.concurrent.ScheduledExecutorService;
77

8-
import javax.security.auth.login.LoginException;
98
import javax.sql.DataSource;
109

1110
import org.springframework.context.ApplicationContext;
@@ -43,7 +42,10 @@ PresenceUpdater standardActivityPresenceUpdater() {
4342
}
4443

4544
@Bean
46-
DataSource getDataSource(BotConfig config) {
45+
DataSource dataSource(BotConfig config) {
46+
if (config.getSystems().getJdaBotToken().isEmpty()) {
47+
throw new RuntimeException("JDA Token not set. Stopping Bot...");
48+
}
4749
return DbHelper.initDataSource(config);
4850
}
4951

@@ -62,10 +64,9 @@ SystemsConfig systemsConfig(BotConfig botConfig) {
6264
* @param botConfig the main configuration of the bot
6365
* @param ctx the Spring application context used for obtaining all listeners
6466
* @return the initialized {@link JDA} object
65-
* @throws LoginException if the token is invalid
6667
*/
6768
@Bean
68-
JDA jda(BotConfig botConfig, ApplicationContext ctx) throws LoginException {
69+
JDA jda(BotConfig botConfig, ApplicationContext ctx) {
6970
Collection<Object> listeners = ctx.getBeansWithAnnotation(PreRegisteredListener.class).values();
7071
return JDABuilder.createDefault(botConfig.getSystems().getJdaBotToken())
7172
.setStatus(OnlineStatus.DO_NOT_DISTURB)

src/main/java/net/discordjug/javabot/data/config/SystemsConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static class ApiConfig {
6666
private String clientSecret = "";
6767
private String redirectUrl = "";
6868
private String[] scopes = new String[]{};
69-
private String ajpSecret = "";
69+
private String ajpSecret = "secret";
7070
}
7171

7272
/**

src/main/java/net/discordjug/javabot/data/h2db/DbHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
/**
3333
* Class that provides helper methods for dealing with the database.
3434
*/
35+
@Getter
3536
@Slf4j
3637
@Service
3738
@RequiredArgsConstructor
3839
public class DbHelper {
39-
@Getter
4040
private final DataSource dataSource;
4141

4242
/**
@@ -108,6 +108,7 @@ private static void initializeSchema(HikariDataSource dataSource) throws IOExcep
108108
for (String rawQuery : queries) {
109109
String query = rawQuery.lines()
110110
.map(s -> s.strip().stripIndent())
111+
.filter(s -> !s.startsWith("//"))
111112
.collect(Collectors.joining(""));
112113
try (Statement stmt = c.createStatement()) {
113114
stmt.executeUpdate(query);

src/main/resources/database/schema.sql

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Help System
2-
CREATE TABLE reserved_help_channels
2+
CREATE TABLE IF NOT EXISTS reserved_help_channels
33
(
44
id BIGINT PRIMARY KEY AUTO_INCREMENT,
55
channel_id BIGINT NOT NULL UNIQUE,
@@ -8,7 +8,7 @@ CREATE TABLE reserved_help_channels
88
timeout INT NOT NULL DEFAULT 60
99
);
1010

11-
CREATE TABLE help_channel_thanks
11+
CREATE TABLE IF NOT EXISTS help_channel_thanks
1212
(
1313
id BIGINT PRIMARY KEY AUTO_INCREMENT,
1414
reservation_id BIGINT NOT NULL,
@@ -19,13 +19,13 @@ CREATE TABLE help_channel_thanks
1919
CONSTRAINT help_channel_thanks_unique UNIQUE (reservation_id, helper_id)
2020
);
2121

22-
CREATE TABLE help_account
22+
CREATE TABLE IF NOT EXISTS help_account
2323
(
2424
user_id BIGINT PRIMARY KEY,
2525
experience DOUBLE NOT NULL
2626
);
2727

28-
CREATE TABLE help_transaction
28+
CREATE TABLE IF NOT EXISTS help_transaction
2929
(
3030
id BIGINT PRIMARY KEY AUTO_INCREMENT,
3131
recipient BIGINT NOT NULL,
@@ -35,7 +35,7 @@ CREATE TABLE help_transaction
3535
);
3636

3737
// Question of the Week
38-
CREATE TABLE qotw_question
38+
CREATE TABLE IF NOT EXISTS qotw_question
3939
(
4040
id BIGINT PRIMARY KEY AUTO_INCREMENT,
4141
created_at TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
@@ -47,15 +47,16 @@ CREATE TABLE qotw_question
4747
priority INTEGER NOT NULL DEFAULT 0
4848
);
4949

50-
CREATE TABLE qotw_points
50+
CREATE TABLE IF NOT EXISTS qotw_points
5151
(
52-
user_id BIGINT PRIMARY KEY,
53-
obtained_at DATE PRIMARY KEY DEFAULT CURRENT_TIMESTAMP(0),
54-
points BIGINT NOT NULL DEFAULT 0
52+
user_id BIGINT,
53+
obtained_at DATE DEFAULT CURRENT_TIMESTAMP(0),
54+
points BIGINT NOT NULL DEFAULT 0,
55+
PRIMARY KEY (user_id, obtained_at)
5556
);
5657

5758
// Warn
58-
CREATE TABLE warn
59+
CREATE TABLE IF NOT EXISTS warn
5960
(
6061
id BIGINT PRIMARY KEY AUTO_INCREMENT,
6162
user_id BIGINT NOT NULL,
@@ -68,7 +69,7 @@ CREATE TABLE warn
6869
);
6970

7071
// Custom Tags
71-
CREATE TABLE custom_tags
72+
CREATE TABLE IF NOT EXISTS custom_tags
7273
(
7374
id BIGINT PRIMARY KEY AUTO_INCREMENT,
7475
guild_id BIGINT NOT NULL,
@@ -80,7 +81,7 @@ CREATE TABLE custom_tags
8081
);
8182

8283
// Starboard
83-
CREATE TABLE starboard
84+
CREATE TABLE IF NOT EXISTS starboard
8485
(
8586
original_message_id BIGINT PRIMARY KEY,
8687
guild_id BIGINT NOT NULL,
@@ -90,21 +91,22 @@ CREATE TABLE starboard
9091
);
9192

9293
// Message Cache
93-
CREATE TABLE message_cache
94+
CREATE TABLE IF NOT EXISTS message_cache
9495
(
9596
message_id BIGINT PRIMARY KEY,
9697
author_id BIGINT NOT NULL,
9798
message_content VARCHAR(4000) NOT NULL
9899
);
99-
CREATE TABLE message_cache_attachments (
100+
101+
CREATE TABLE IF NOT EXISTS message_cache_attachments (
100102
message_id BIGINT NOT NULL,
101103
attachment_index INT NOT NULL,
102104
link VARCHAR(255),
103105
PRIMARY KEY(message_id, attachment_index)
104-
)
106+
);
105107

106108
// User Preferences
107-
CREATE TABLE user_preferences
109+
CREATE TABLE IF NOT EXISTS user_preferences
108110
(
109111
user_id BIGINT NOT NULL,
110112
ordinal INTEGER NOT NULL,

0 commit comments

Comments
 (0)