3
3
import com .electronwill .nightconfig .core .file .FileConfig ;
4
4
import fr .lukam .jambot .model .*;
5
5
6
- import java .net . URL ;
6
+ import java .io . File ;
7
7
import java .util .Arrays ;
8
8
import java .util .List ;
9
9
@@ -13,7 +13,7 @@ public class ConfigurationUtils {
13
13
private static final String TOKEN_DEFAULT = "token" ;
14
14
15
15
private static final String PREFIX_PATH = "prefix" ;
16
- private static final char PREFIX_DEFAULT = '*' ;
16
+ private static final String PREFIX_DEFAULT = "*" ;
17
17
18
18
private static final String GUILD_PATH = "guild" ;
19
19
private static final String GUILD_DEFAULT = "803180065277712404" ;
@@ -29,13 +29,13 @@ public class ConfigurationUtils {
29
29
30
30
public static Token getToken () {
31
31
32
- URL file = ConfigurationUtils . class . getClassLoader (). getResource ("configuration.toml" );
32
+ File file = new File ("configuration.toml" );
33
33
34
- if (file == null ) {
34
+ if (! file . exists () ) {
35
35
return new Token (TOKEN_DEFAULT );
36
36
}
37
37
38
- FileConfig fileConfig = FileConfig .of (file . getPath (). substring ( 1 ) );
38
+ FileConfig fileConfig = FileConfig .of (file );
39
39
fileConfig .load ();
40
40
String token = fileConfig .getOrElse (TOKEN_PATH , TOKEN_DEFAULT );
41
41
fileConfig .close ();
@@ -44,28 +44,28 @@ public static Token getToken() {
44
44
45
45
public static Prefix getPrefix () {
46
46
47
- URL file = ConfigurationUtils . class . getClassLoader (). getResource ("configuration.toml" );
47
+ File file = new File ("configuration.toml" );
48
48
49
- if (file == null ) {
50
- return new Prefix (PREFIX_DEFAULT );
49
+ if (! file . exists () ) {
50
+ return new Prefix (PREFIX_DEFAULT . charAt ( 0 ) );
51
51
}
52
52
53
- FileConfig fileConfig = FileConfig .of (file . getPath (). substring ( 1 ) );
53
+ FileConfig fileConfig = FileConfig .of (file );
54
54
fileConfig .load ();
55
- char prefix = fileConfig .getOrElse (PREFIX_PATH , PREFIX_DEFAULT );
55
+ char prefix = fileConfig .getOrElse (PREFIX_PATH , PREFIX_DEFAULT ). charAt ( 0 ) ;
56
56
fileConfig .close ();
57
57
return new Prefix (prefix );
58
58
}
59
59
60
60
public static GuildId getGuildId () {
61
61
62
- URL file = ConfigurationUtils . class . getClassLoader (). getResource ("configuration.toml" );
62
+ File file = new File ("configuration.toml" );
63
63
64
- if (file == null ) {
64
+ if (! file . exists () ) {
65
65
return new GuildId (GUILD_DEFAULT );
66
66
}
67
67
68
- FileConfig fileConfig = FileConfig .of (file . getPath (). substring ( 1 ) );
68
+ FileConfig fileConfig = FileConfig .of (file );
69
69
fileConfig .load ();
70
70
String guildId = fileConfig .getOrElse (GUILD_PATH , GUILD_DEFAULT );
71
71
fileConfig .close ();
@@ -74,13 +74,13 @@ public static GuildId getGuildId() {
74
74
75
75
public static RoleId getRoleID () {
76
76
77
- URL file = ConfigurationUtils . class . getClassLoader (). getResource ("configuration.toml" );
77
+ File file = new File ("configuration.toml" );
78
78
79
- if (file == null ) {
79
+ if (! file . exists () ) {
80
80
return new RoleId (GUILD_DEFAULT );
81
81
}
82
82
83
- FileConfig fileConfig = FileConfig .of (file . getPath (). substring ( 1 ) );
83
+ FileConfig fileConfig = FileConfig .of (file );
84
84
fileConfig .load ();
85
85
String roleId = fileConfig .getOrElse (ROLE_PATH , ROLE_DEFAULT );
86
86
fileConfig .close ();
@@ -89,13 +89,13 @@ public static RoleId getRoleID() {
89
89
90
90
public static Authorized getAuthorized () {
91
91
92
- URL file = ConfigurationUtils . class . getClassLoader (). getResource ("configuration.toml" );
92
+ File file = new File ("configuration.toml" );
93
93
94
- if (file == null ) {
94
+ if (! file . exists () ) {
95
95
return new Authorized (AUTHORIZED_DEFAULT );
96
96
}
97
97
98
- FileConfig fileConfig = FileConfig .of (file . getPath (). substring ( 1 ) );
98
+ FileConfig fileConfig = FileConfig .of (file );
99
99
fileConfig .load ();
100
100
List <String > authorized = fileConfig .getOrElse (AUTHORIZED_PATH , AUTHORIZED_DEFAULT );
101
101
fileConfig .close ();
@@ -104,13 +104,13 @@ public static Authorized getAuthorized() {
104
104
105
105
public static Channels getChannels () {
106
106
107
- URL file = ConfigurationUtils . class . getClassLoader (). getResource ("configuration.toml" );
107
+ File file = new File ("configuration.toml" );
108
108
109
- if (file == null ) {
109
+ if (! file . exists () ) {
110
110
return new Channels (CHANNELS_DEFAULT );
111
111
}
112
112
113
- FileConfig fileConfig = FileConfig .of (file . getPath (). substring ( 1 ) );
113
+ FileConfig fileConfig = FileConfig .of (file );
114
114
fileConfig .load ();
115
115
List <String > channels = fileConfig .getOrElse (CHANNELS_PATH , CHANNELS_DEFAULT );
116
116
fileConfig .close ();
0 commit comments