Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/main/java/com/caobot/application/CaoBotConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.security.auth.login.LoginException;
import java.util.Scanner;

@Service
public class CaoBotConnection {
private static JDA jda;
// private Configuration configuration;

private static String bot_token;
// public CaoBotConnection(Configuration configuration) {
// this.configuration = configuration;
// }

@Value("${user.token}")
private void setBotToken(String value) {
this.bot_token = value;
}
private static JDA jda;

// @Value("${user.token}")
// private void setBotToken(String value) {
// this.bot_token = value;
// }

public static void start() {
try {
jda = JDABuilder.createDefault(AccountType.BOT.name())
.setToken(bot_token)
.setToken(getBotTokenFromUser())
.addEventListeners(new MessageService())
.setActivity(Activity.watching("cao-bot 운영 중!"))
.build();
Expand All @@ -39,4 +42,12 @@ public static void stop() {
jda.shutdown();
System.out.println("Finished Stopping JDA!");
}

private static String getBotTokenFromUser() {
Scanner sc = new Scanner(System.in);
System.out.println("token 값을 입력하세요: ");
String botToken = sc.nextLine();

return botToken;
}
}