小修小改

main
lensfrex 3 years ago
parent fe53b334c7
commit 51545510a1
Signed by: lensfrex
GPG Key ID: 947ADABD8533C476
  1. 19
      Dogename/src/main/java/me/lensferno/dogename/data/Data.java
  2. 2
      Dogename/src/main/java/me/lensferno/dogename/data/History.java
  3. 21
      Dogename/src/main/java/me/lensferno/dogename/voice/TokenManager.java
  4. 2
      Dogename/src/main/java/me/lensferno/dogename/voice/VoicePlayer.java

@ -13,18 +13,16 @@ public class Data {
public static final int IGNORELIST_NAME_ONLY = 0;
public static final int IGNORELIST_NUMBER_ONLY = 1;
public static final int IGNORELIST_ALL = 2;
File dataFile;
SecureRandom secRandom = new SecureRandom();
Random random = new Random();
private final File dataFile = new File(FilePath.toSpecificPathForm("files/Namelist.data"));
private final SecureRandom secRandom = new SecureRandom();
private final Random random = new Random();
private List<String> nameList;
private final IgnoreList ignoreList = new IgnoreList();
public Data() {
dataFile = new File(FilePath.toSpecificPathForm("files/Namelist.data"));
try {
if (!dataFile.exists()) {
dataFile.getParentFile().mkdirs();
dataFile.createNewFile();
@ -48,7 +46,6 @@ public class Data {
System.out.println("Failed to load data file.");
e.printStackTrace();
}
ignoreList.readIgnoreList();
}
@ -90,9 +87,7 @@ public class Data {
System.out.println("error in import namelist:" + e);
e.printStackTrace();
}
}
}
public void makeMass() {
@ -209,7 +204,7 @@ public class Data {
return ignoreList.getNumberIgnoreListSize();
}
class IgnoreList {
static class IgnoreList {
private final File nameIgnoreFile = new File(FilePath.toSpecificPathForm("files/IgnoredNameList.data"));
private final File numbIgnoreFile = new File(FilePath.toSpecificPathForm("files/IgnoredNumberList.data"));
@ -251,7 +246,7 @@ public class Data {
public void readIgnoreList() {
readNameIgnoreList();
readNumberIgnoreList();
System.out.println(String.format("There are %d names and %d numbers ignored", ignoreNameList.size(), ignoreNumberList.size()));
System.out.printf("There are %d names and %d numbers ignored", ignoreNameList.size(), ignoreNumberList.size());
}
private void readNameIgnoreList() {

@ -16,7 +16,6 @@ public class History {
File historyFile = new File(HISTORY_FILE);
try {
if (!historyFile.exists()) {
historyFile.getParentFile().mkdirs();
historyFile.createNewFile();
@ -57,7 +56,6 @@ public class History {
File historyFile = new File(HISTORY_FILE);
try {
if (!historyFile.exists()) {
historyFile.createNewFile();
}

@ -32,7 +32,6 @@ public class TokenManager {
if (netAvailable()) {
refreshToken();
}
if (checkTokenAvailable() != 0) {
tokenStatus = TOKEN_BAD;
}
@ -55,19 +54,13 @@ public class TokenManager {
if (tokenFile.exists()) {
loadToken();
updateTokenStatus(checkTokenAvailable());
} else {
if (netAvailable()) {
refreshToken();
updateTokenStatus(checkTokenAvailable());
} else {
tokenStatus = TOKEN_BAD;
}
}
}
@ -98,17 +91,10 @@ public class TokenManager {
return 0;
}
void fetchToken() {
try {
token = new Gson().fromJson(
NetworkUtil.getHtml(
TOKEN_API_URL
+ "?grant_type=client_credentials&client_id=" + API_KEY
+ "&client_secret=" + SEC_KEY,
true)
, Token.class);
NetworkUtil.getHtml(String.format("%s?grant_type=client_credentials&client_id=%s&client_secret=%s", TOKEN_API_URL, API_KEY, SEC_KEY), true), Token.class);
token.setExpTime();
} catch (Exception e) {
System.out.println("Error to get Token:" + e);
@ -118,7 +104,6 @@ public class TokenManager {
private boolean netAvailable() {
try {
URL sourcesURL = new URL("http://www.baidu.com");
HttpURLConnection connection = (HttpURLConnection) sourcesURL.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36");
@ -136,9 +121,8 @@ public class TokenManager {
}
private void loadToken() {
ObjectInputStream ois;
try {
ois = new ObjectInputStream(new FileInputStream(tokenFile));
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(tokenFile));
this.token = (Token) ois.readObject();
ois.close();
} catch (Exception e) {
@ -148,7 +132,6 @@ public class TokenManager {
}
private void writeToken() {
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(tokenFile));
oos.writeObject(token);

@ -18,7 +18,7 @@ public class VoicePlayer {
Token token;
StreamPlayer streamPlayer = new StreamPlayer();
private VoiceConfig voiceConfig = null;
private final VoiceConfig voiceConfig;
public VoicePlayer(Token token, VoiceConfig voiceConfig) {
this.token = token;

Loading…
Cancel
Save