支持了从环境变量设置 token #34

This commit is contained in:
A.C.Sukazyo Eyre 2022-05-19 15:44:57 +08:00
parent 16d74a3af5
commit 35fa1ed5c4
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
3 changed files with 33 additions and 7 deletions

View File

@ -1,6 +1,6 @@
## Core
VERSION = 0.7.0.5
VERSION = 0.7.0.6
# dependencies

View File

@ -4,6 +4,6 @@ package cc.sukazyo.cono.morny;
* the final field that will be updated by gradle automatically.
*/
public class GradleProjectConfigures {
public static final String VERSION = "0.7.0.5";
public static final long COMPILE_TIMESTAMP = 1652944218716L;
public static final String VERSION = "0.7.0.6";
public static final long COMPILE_TIMESTAMP = 1652946142762L;
}

View File

@ -15,10 +15,8 @@ import static cc.sukazyo.cono.morny.Log.logger;
*/
public class ServerMain {
private static boolean versionEchoMode = false;
private static boolean welcomeEchoMode = false;
private static boolean showWelcome = true;
public static final String PROP_TOKEN_KEY = "TELEGRAM_BOT_API_TOKEN";
public static final String PROP_TOKEN_MORNY_KEY = "MORNY_TG_TOKEN";
/**
* 程序入口也是参数处理器<br>
@ -71,6 +69,13 @@ public class ServerMain {
*/
public static void main (@Nonnull String[] args) {
//#
//# 启动参数设置区块
//#
boolean versionEchoMode = false;
boolean welcomeEchoMode = false;
boolean showWelcome = true;
String key = null;
String username = null;
boolean outdatedBlock = false;
@ -136,6 +141,19 @@ public class ServerMain {
}
String propToken = null;
String propTokenKey = null;
for (String iKey : new String[]{PROP_TOKEN_KEY, PROP_TOKEN_MORNY_KEY}) {
if (System.getenv(iKey) != null) {
propToken = System.getenv(iKey);
propTokenKey = iKey;
}
}
//#
//# 启动相关参数的检查和处理
//#
if (versionEchoMode) {
logger.info(String.format("""
@ -159,6 +177,14 @@ public class ServerMain {
if (showWelcome) logger.info(MornyHello.MORNY_PREVIEW_IMAGE_ASCII);
if (welcomeEchoMode) return;
//#
//# Coeur 参数检查和正式启动主程序
//#
if (propToken != null) {
key = propToken;
logger.info("Parameter <token> set by EnvVar $"+propTokenKey);
}
if (key == null) {
logger.info("Parameter required has no value:\n --token.");
return;