Skip to content

Commit

Permalink
v2.52 - added DBL Token and DBL ID configuration with .env (for now m…
Browse files Browse the repository at this point in the history
…anually)
  • Loading branch information
Tzesh committed Mar 18, 2021
1 parent 1ccfeea commit b98f27d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mainClassName = 'TzeBot.Main'

version '2.51'

sourceCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_14

repositories {
jcenter()
Expand All @@ -22,7 +22,7 @@ dependencies {
compile group: 'ch.qos.logback', name: 'logback-classic', version: '+'
compile group: 'org.xerial', name: 'sqlite-jdbc', version: '+'

compile 'io.github.cdimascio:java-dotenv:+'
compile 'io.github.cdimascio:dotenv-java:2.2.0'
compile 'com.google.apis:google-api-services-youtube:+'
compile 'org.discordbots:DBL-Java-Library:+'
implementation 'com.sedmelluq:lavaplayer:+'
Expand Down
40 changes: 24 additions & 16 deletions src/main/java/TzeBot/essentials/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public class Config {
public static Map<Long, HashMap<Long, Long>> MUSICCHANNELS = new HashMap<>(); // All of the music channels that are created and initialized.
public static Map<Long, Integer> VOLUMES = new HashMap<>(); // Volumes of the servers default is 50%
public static Map<Long, Long> CHANNELCREATED = new HashMap<>(); // All of the music channels that are created but either initialized or not. It's important value for preventing some kind of abusing of channel creation.
public static double currentVersion = 2.51; // Check if there's an update or not.
public static String dblToken = "";
public static String botId = "";
public static double currentVersion = 2.52; // Check if there's an update or not.
public static String dblToken = null;
public static String botId = null;

public static String get(String key) {
return dotenv.get(key.toUpperCase());
Expand All @@ -38,7 +38,9 @@ public static void save(String token, String pre, String owner, String key, Stri
+ "\nPRE=" + pre
+ "\nOWNER=" + owner
+ "\nKEY=" + key
+ "\nSHARD=" + shards);
+ "\nSHARD=" + shards
+ "\nDBLTOKEN=" + dblToken
+ "\nBOTID=" + botId);
} catch (IOException exception) {
System.out.println("An error occurred during saving the .env");
}
Expand All @@ -54,7 +56,9 @@ public static void createENV() {
+ "\nPRE=."
+ "\nOWNER="
+ "\nKEY="
+ "\nSHARD=");
+ "\nSHARD="
+ "\nDBLTOKEN="
+ "\nBOTID=");
} catch (IOException exception) {
System.out.println("An error occurred during saving the .env");
}
Expand Down Expand Up @@ -89,23 +93,27 @@ public static void getDatabase() {
File file = new File("database.bin");
if (file.exists()) {
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(file))) {
PREFIXES = (HashMap<Long, String>) in.readObject();
LANGUAGES = (HashMap<Long, String>) in.readObject();
CHANNELS = (HashMap<Long, Long>) in.readObject();
VOTEROLES = (HashMap<Long, LinkedList<Long>>) in.readObject();
MUSICCHANNELS = (HashMap<Long, HashMap<Long, Long>>) in.readObject();
VOLUMES = (HashMap<Long, Integer>) in.readObject();
CHANNELCREATED = (HashMap<Long, Long>) in.readObject();
in.reset();
} catch (IOException exception) {
PREFIXES = (Map<Long, String>) in.readObject();
LANGUAGES = (Map<Long, String>) in.readObject();
CHANNELS = (Map<Long, Long>) in.readObject();
VOTEROLES = (Map<Long, LinkedList<Long>>) in.readObject();
MUSICCHANNELS = (Map<Long, HashMap<Long, Long>>) in.readObject();
VOLUMES = (Map<Long, Integer>) in.readObject();
CHANNELCREATED = (Map<Long, Long>) in.readObject();
} catch (Exception exception) {
System.out.println("An error occurred during process...");
} catch (ClassNotFoundException exception) {
System.out.println("Class not found.");
}
} else {
System.out.println("Database file not found.");
}
System.out.println("All languages and prefixed are loaded from database.");
if (Config.get("dbltoken").length() == 0 && Config.get("botid").length() == 0) {
System.out.println("Token and ID for Top.GG are not specified." +
"\nYou can also specify them in .env by manually in order to use Top.GG Java API.");
} else {
dblToken = Config.get("DBLTOKEN");
botId = Config.get("BOTID");
}
}

public static void saveForAQuarter() { // save database per 15 minutes
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/TzeBot/essentials/Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public class Listener extends ListenerAdapter {
@Override
public void onReady(@Nonnull ReadyEvent event) {
LOGGER.info("{} is ready", event.getJDA().getSelfUser().getAsTag());
botListManager = new BotListManager();
botListManager.setStats(event.getJDA());
if (Config.get("dbltoken").length() != 0) {
botListManager = new BotListManager();
botListManager.setStats(event.getJDA());
}
for (Long guildID : Config.MUSICCHANNELS.keySet()) {
HashMap<Long, Long> IDs = Config.MUSICCHANNELS.get(guildID);
for (Long channelID : IDs.keySet()) {
Expand Down Expand Up @@ -178,6 +180,7 @@ private void checkMembersAndLeave(Guild guild, VoiceChannel channelLeft, @Nonnul

@Override
public void onGuildJoin(@Nonnull GuildJoinEvent event) {
if (this.botListManager != null)
botListManager.setStats(event.getJDA());
TextChannel defaultChannel = event.getGuild().getDefaultChannel();
if (defaultChannel != null && event.getGuild().getSelfMember().hasPermission(defaultChannel, Permission.MESSAGE_WRITE))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/TzeBot/gui/TzeGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public class TzeGUI extends javax.swing.JFrame {

public TzeGUI() {
Config.createENV();
Config.getDatabase();
initComponents();
updateButton.setVisible(false);
TextAreaOutputStream taos = new TextAreaOutputStream(console, 60);
Expand All @@ -57,6 +56,7 @@ public TzeGUI() {
System.setErr(ps);
checkVariables();
checkVersion();
Config.getDatabase();
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
Expand Down
2 changes: 1 addition & 1 deletion versioncontrol.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.51
version=2.52

0 comments on commit b98f27d

Please sign in to comment.