Skip to content

Commit be0bcb6

Browse files
author
赵立田
committed
update
1 parent a79a299 commit be0bcb6

File tree

6 files changed

+59
-63
lines changed

6 files changed

+59
-63
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ out
3737
### bot.ini ###
3838
bot.ini
3939
bot.log
40-
bot.log.1
40+
bot.log.1
41+
42+
### env.ini ###
43+
env.ini

src/main/java/com/las/LASBot.java

+42-17
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,27 @@ private static void run(String basePackage) {
6262
* 初始化配置文件
6363
*/
6464
private static void init(BotRun annotation) throws Exception {
65-
String path = System.getProperty("user.dir") + File.separator + "bot.ini";
65+
readEnvFile();
66+
readBotFile(annotation);
67+
UserDao userDao = (UserDao) APP_CONTEXT.getBean("userDao");
68+
User superUser;
69+
try {
70+
superUser = userDao.findSuperQQ();
71+
if (null != superUser) {
72+
logger.debug("检查管理员QQ信息:" + superUser.toString());
73+
} else {
74+
logger.warn("该机器人QQ未添加管理员好友");
75+
}
76+
} catch (Exception e) {
77+
throw new Exception("数据库连接异常,请检查env.ini配置文件");
78+
}
79+
if (!StrUtils.isNotBlank(AppConfigs.BOT_QQ)) {
80+
throw new Exception("botQQ暂未初始化,请检查BotRun注解里面的参数");
81+
}
82+
}
83+
84+
private static void readEnvFile() throws IOException {
85+
String path = System.getProperty("user.dir") + File.separator + "env.ini";
6686
logger.debug("当前env配置路径是:" + path);
6787
InputStream initialStream = ClassLoader.getSystemClassLoader().getResourceAsStream("env.ini");
6888
BufferedReader br;
@@ -71,32 +91,37 @@ private static void init(BotRun annotation) throws Exception {
7191
File file = new File(path);
7292
if (!file.exists()) {
7393
br = new BufferedReader(new InputStreamReader(initialStream));
74-
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("bot.ini")));
94+
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("env.ini")));
7595
String line;
7696
while (null != (line = br.readLine())) {
77-
bw.write(changeLine(line, annotation));
97+
bw.write(line);
7898
bw.newLine();
7999
bw.flush();
80100
}
81101
bw.close();
82102
br.close();
83103
initialStream.close();
84104
}
85-
UserDao userDao = (UserDao) APP_CONTEXT.getBean("userDao");
86-
User superUser;
87-
try {
88-
superUser = userDao.findSuperQQ();
89-
if (null != superUser) {
90-
logger.debug("检查管理员QQ信息:" + superUser.toString());
91-
} else {
92-
logger.warn("该机器人QQ未添加管理员好友");
93-
}
94-
} catch (Exception e) {
95-
throw new Exception("数据库连接异常,请检查bot.ini配置");
96-
}
97-
if (!StrUtils.isNotBlank(AppConfigs.BOT_QQ)) {
98-
throw new Exception("botQQ暂未初始化,请检查BotRun注解里面的参数");
105+
}
106+
107+
108+
private static void readBotFile(BotRun annotation) throws IOException {
109+
String path = System.getProperty("user.dir") + File.separator + "bot.ini";
110+
logger.debug("当前bot配置路径是:" + path);
111+
InputStream initialStream = ClassLoader.getSystemClassLoader().getResourceAsStream("bot.ini");
112+
BufferedReader br;
113+
BufferedWriter bw;
114+
br = new BufferedReader(new InputStreamReader(initialStream));
115+
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("bot.ini")));
116+
String line;
117+
while (null != (line = br.readLine())) {
118+
bw.write(changeLine(line, annotation));
119+
bw.newLine();
120+
bw.flush();
99121
}
122+
bw.close();
123+
br.close();
124+
initialStream.close();
100125
}
101126

102127
/**

src/main/java/com/las/config/AppConfigs.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,26 @@ public class AppConfigs {
3131

3232

3333
static {
34-
String path = System.getProperty("user.dir") + File.separator + "bot.ini";
35-
IniSection iniSection;
34+
String envPath = System.getProperty("user.dir") + File.separator + "env.ini";
35+
IniSection envIniSection;
3636
//设置mysql数据账号密码
37-
iniSection = getInit(path).getSection("dbmysql");
38-
String DRIVER = iniSection.getItem("driver").getValue();
39-
String JDBC = iniSection.getItem("jdbc").getValue();
40-
String USER = iniSection.getItem("user").getValue();
41-
String PWD = iniSection.getItem("passwd").getValue();
37+
envIniSection = getInit(envPath).getSection("dbmysql");
38+
String DRIVER = envIniSection.getItem("driver").getValue();
39+
String JDBC = envIniSection.getItem("jdbc").getValue();
40+
String USER = envIniSection.getItem("user").getValue();
41+
String PWD = envIniSection.getItem("passwd").getValue();
4242
logger.debug("数据库连接DRIVER信息:" + DRIVER);
4343
DATA_SOURCE = new DruidDataSource();
4444
DATA_SOURCE.setDriverClassName(DRIVER);
4545
DATA_SOURCE.setUrl(JDBC);
4646
DATA_SOURCE.setUsername(USER);
4747
DATA_SOURCE.setPassword(PWD);
4848

49+
50+
// 分开两个配置,上面的是数据库,下面的是bot配置
51+
52+
String path = System.getProperty("user.dir") + File.separator + "bot.ini";
53+
IniSection iniSection;
4954
//获取botQQ
5055
iniSection = getInit(path).getSection("botqq");
5156
BOT_QQ = iniSection.getItem("qq").getValue();

src/main/resources/env/bot/env.ini

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
[superuser]
2-
superqq = SUPER_QQ_PARAM
3-
41
[dbmysql]
52
driver = 数据库驱动
63
jdbc = JDBC链接
74
user = 数据库账号
8-
passwd = 数据库密码
9-
10-
[botqq]
11-
qq = BOT_QQ_PARAM
12-
qqAuth = QQ_AUTH_PARAM
13-
miraiUrl = MIRAI_URL_PARAM
14-
botServer = BOT_SERVER_PARAM
15-
16-
[webpath]
17-
webpath = WEB_PATH_PARAM
18-
5+
passwd = 数据库密码

src/main/resources/env/dw/env.ini

-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
[superuser]
2-
superqq = SUPER_QQ_PARAM
3-
41
[dbmysql]
52
driver = com.mysql.jdbc.Driver
63
jdbc = jdbc:mysql://47.106.142.49:3306/lasbot?useUnicode=true&characterEncoding=utf8
74
user = root
85
passwd = dw123456
96

10-
[botqq]
11-
qq = BOT_QQ_PARAM
12-
qqAuth = QQ_AUTH_PARAM
13-
miraiUrl = MIRAI_URL_PARAM
14-
botServer = BOT_SERVER_PARAM
15-
16-
[webpath]
17-
webpath = WEB_PATH_PARAM
18-

src/main/resources/env/frz/env.ini

-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
[superuser]
2-
superqq = SUPER_QQ_PARAM
3-
41
[dbmysql]
52
driver = com.mysql.jdbc.Driver
63
jdbc = jdbc:mysql://175.24.191.26:2221/frz
74
user = frz
85
passwd = qwsa1234
96

10-
[botqq]
11-
qq = BOT_QQ_PARAM
12-
qqAuth = QQ_AUTH_PARAM
13-
miraiUrl = MIRAI_URL_PARAM
14-
botServer = BOT_SERVER_PARAM
15-
16-
[webpath]
17-
webpath = WEB_PATH_PARAM
18-

0 commit comments

Comments
 (0)