2022-08-25 21:51:00 +02:00
|
|
|
package wtf.beatrice.hidekobot;
|
|
|
|
|
|
|
|
import net.dv8tion.jda.api.JDA;
|
|
|
|
import net.dv8tion.jda.api.JDABuilder;
|
2022-08-25 22:18:36 +02:00
|
|
|
import net.dv8tion.jda.api.entities.Activity;
|
2022-08-25 23:20:51 +02:00
|
|
|
import net.dv8tion.jda.api.requests.GatewayIntent;
|
|
|
|
import wtf.beatrice.hidekobot.listeners.MessageListener;
|
2022-08-26 00:13:31 +02:00
|
|
|
import wtf.beatrice.hidekobot.listeners.MessageLogger;
|
2022-08-25 22:13:39 +02:00
|
|
|
import wtf.beatrice.hidekobot.utils.Logger;
|
2022-08-25 21:51:00 +02:00
|
|
|
|
|
|
|
import javax.security.auth.login.LoginException;
|
2022-08-26 00:13:31 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2022-08-25 21:51:00 +02:00
|
|
|
|
|
|
|
public class HidekoBot
|
|
|
|
{
|
2022-08-25 22:20:05 +02:00
|
|
|
private static String botToken;
|
2022-08-25 22:29:14 +02:00
|
|
|
private static String standardInviteLink = "https://discord.com/oauth2/authorize?client_id=%userid%&scope=bot&permissions=8";
|
|
|
|
private static String botUserId;
|
2022-08-25 22:59:47 +02:00
|
|
|
private static final String version = "0.0.1"; // we should probably find a way to make this consistent with Maven
|
2022-08-25 21:51:00 +02:00
|
|
|
|
2022-08-26 00:13:31 +02:00
|
|
|
private static JDA jda;
|
|
|
|
|
2022-08-25 22:59:47 +02:00
|
|
|
|
|
|
|
// create a logger instance for ease of use
|
|
|
|
private static final Logger logger = new Logger(HidekoBot.class);
|
2022-08-25 22:54:08 +02:00
|
|
|
|
2022-08-25 21:51:00 +02:00
|
|
|
public static void main(String[] args)
|
|
|
|
{
|
2022-08-25 22:20:05 +02:00
|
|
|
|
|
|
|
// check if bot token was specified as a startup argument
|
|
|
|
if(args.length < 1)
|
|
|
|
{
|
|
|
|
logger.log("Please specify your bot token!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-26 00:13:31 +02:00
|
|
|
// load token from args
|
2022-08-25 22:20:05 +02:00
|
|
|
botToken = args[0];
|
|
|
|
|
2022-08-26 00:13:31 +02:00
|
|
|
// if there are more than 1 args, then iterate through them because we have additional things to do
|
|
|
|
if(args.length > 1) {
|
|
|
|
List<String> argsList = new ArrayList<>();
|
|
|
|
for(int i = 1; i < args.length; i++)
|
|
|
|
{ argsList.add(args[i]); }
|
|
|
|
|
|
|
|
if(argsList.contains("verbose")) Configuration.setVerbose(true);
|
|
|
|
}
|
2022-08-25 22:18:36 +02:00
|
|
|
|
2022-08-25 21:51:00 +02:00
|
|
|
try
|
|
|
|
{
|
2022-08-25 22:37:32 +02:00
|
|
|
// try to create the bot object and authenticate it with discord.
|
2022-08-26 00:13:31 +02:00
|
|
|
JDABuilder jdaBuilder = JDABuilder.createDefault(botToken);
|
2022-08-25 22:18:36 +02:00
|
|
|
jdaBuilder.setActivity(Activity.playing("the piano"));
|
2022-08-25 23:20:51 +02:00
|
|
|
|
2022-08-26 00:13:31 +02:00
|
|
|
// enable necessary intents.
|
|
|
|
jdaBuilder.enableIntents(
|
|
|
|
GatewayIntent.MESSAGE_CONTENT,
|
2022-08-25 23:20:51 +02:00
|
|
|
GatewayIntent.DIRECT_MESSAGES,
|
2022-08-26 00:13:31 +02:00
|
|
|
GatewayIntent.GUILD_MESSAGES
|
|
|
|
);
|
2022-08-25 23:20:51 +02:00
|
|
|
|
|
|
|
jda = jdaBuilder.build().awaitReady();
|
|
|
|
} catch (LoginException | InterruptedException e)
|
2022-08-25 21:51:00 +02:00
|
|
|
{
|
2022-08-25 22:37:32 +02:00
|
|
|
logger.log(e.getMessage()); // print the error message, omit the stack trace.
|
|
|
|
return; // if we failed connecting and authenticating, then quit.
|
2022-08-25 21:51:00 +02:00
|
|
|
}
|
2022-08-25 22:37:32 +02:00
|
|
|
|
|
|
|
// find the bot's user id and generate an invite-link.
|
2022-08-25 22:29:14 +02:00
|
|
|
botUserId = jda.getSelfUser().getId();
|
|
|
|
standardInviteLink = standardInviteLink.replace("%userid%", botUserId);
|
|
|
|
|
2022-08-26 00:13:31 +02:00
|
|
|
// register listeners
|
|
|
|
jda.addEventListener(new MessageListener());
|
|
|
|
if(Configuration.isVerbose()) jda.addEventListener(new MessageLogger());
|
|
|
|
|
2022-08-25 22:54:08 +02:00
|
|
|
// print the bot logo.
|
|
|
|
logger.log("Ready!\n\n" + logger.getLogo() + "\nv" + version + " - bot is ready!\n", 2);
|
|
|
|
|
2022-08-25 22:37:32 +02:00
|
|
|
// log the invite-link to console so noob users can just click on it.
|
2022-08-25 23:03:33 +02:00
|
|
|
logger.log("Bot User ID: " + botUserId, 4);
|
2022-08-25 22:43:04 +02:00
|
|
|
logger.log("Invite Link: " + standardInviteLink, 5);
|
2022-08-25 23:20:51 +02:00
|
|
|
|
2022-08-26 00:13:31 +02:00
|
|
|
}
|
|
|
|
public static JDA getAPI()
|
|
|
|
{
|
|
|
|
return jda;
|
2022-08-25 21:51:00 +02:00
|
|
|
}
|
2022-08-25 22:13:39 +02:00
|
|
|
|
2022-08-25 21:51:00 +02:00
|
|
|
}
|