use of org.geysermc.discordbot.listeners.FileHandler in project GeyserDiscordBot by GeyserMC.
the class GeyserBot method main.
public static void main(String[] args) throws IOException, LoginException {
// Load properties into the PropertiesManager
Properties prop = new Properties();
prop.load(new FileInputStream("bot.properties"));
PropertiesManager.loadProperties(prop);
// Setup sentry.io
if (PropertiesManager.getSentryDsn() != null) {
LOGGER.info("Loading sentry.io...");
Sentry.init(options -> {
options.setDsn(PropertiesManager.getSentryDsn());
options.setEnvironment(PropertiesManager.getSentryEnv());
LOGGER.info("Sentry.io loaded");
});
}
// Connect to github
github = new GitHubBuilder().withOAuthToken(PropertiesManager.getGithubToken()).build();
// Initialize the waiter
EventWaiter waiter = new EventWaiter();
// Load filters
SwearHandler.loadFilters();
// Load the db
StorageType storageType = StorageType.getByName(PropertiesManager.getDatabaseType());
if (storageType == StorageType.UNKNOWN) {
LOGGER.error("Invalid database type! '" + PropertiesManager.getDatabaseType() + "'");
System.exit(1);
}
try {
storageManager = storageType.getStorageManager().getDeclaredConstructor().newInstance();
storageManager.setupStorage();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
LOGGER.error("Unable to create database link!");
System.exit(1);
}
// Setup the main client
CommandClientBuilder client = new CommandClientBuilder();
client.setActivity(null);
// No owner
client.setOwnerId("0");
client.setPrefix(PropertiesManager.getPrefix());
client.useHelpBuilder(false);
client.addCommands(COMMANDS.toArray(new Command[0]));
client.addSlashCommands(SLASH_COMMANDS.toArray(new SlashCommand[0]));
client.setListener(new CommandErrorHandler());
client.setCommandPreProcessBiFunction((event, command) -> !SwearHandler.filteredMessages.contains(event.getMessage().getIdLong()));
// Setup the tag client
CommandClientBuilder tagClient = new CommandClientBuilder();
tagClient.setActivity(null);
// No owner
tagClient.setOwnerId("0");
String tagPrefix = PropertiesManager.getPrefix() + PropertiesManager.getPrefix();
tagClient.setPrefix(tagPrefix);
tagClient.setPrefixes(new String[] { "!tag " });
tagClient.useHelpBuilder(false);
tagClient.addCommands(TagsManager.getTags().toArray(new Command[0]));
tagClient.setListener(new TagsListener());
tagClient.setCommandPreProcessBiFunction((event, command) -> !SwearHandler.filteredMessages.contains(event.getMessage().getIdLong()));
tagClient.setManualUpsert(true);
// Disable pings on replies
MessageAction.setDefaultMentionRepliedUser(false);
// Setup the thread pool
generalThreadPool = Executors.newScheduledThreadPool(5);
// Register JDA
try {
jda = JDABuilder.createDefault(PropertiesManager.getToken()).setChunkingFilter(ChunkingFilter.ALL).setMemberCachePolicy(MemberCachePolicy.ALL).enableIntents(GatewayIntent.GUILD_MEMBERS).enableIntents(GatewayIntent.GUILD_PRESENCES).enableCache(CacheFlag.ACTIVITY).enableCache(CacheFlag.ROLE_TAGS).setStatus(OnlineStatus.ONLINE).setActivity(Activity.playing("Booting...")).setEnableShutdownHook(true).setEventManager(new SentryEventManager()).addEventListeners(waiter, new LogHandler(), new SwearHandler(), new PersistentRoleHandler(), new FileHandler(), new LevelHandler(), new DumpHandler(), new ErrorAnalyzer(), new ShutdownHandler(), new VoiceGroupHandler(), new BadLinksHandler(), client.build(), tagClient.build()).build();
} catch (IllegalArgumentException exception) {
LOGGER.error("Failed to initialize JDA!", exception);
System.exit(1);
}
// Register listeners
jda.addEventListener();
// Setup the http server
if (PropertiesManager.enableWeb()) {
try {
httpServer = new Server();
httpServer.start();
} catch (Exception e) {
// TODO
e.printStackTrace();
}
}
// Setup the update check scheduler
UpdateManager.setup();
// Setup the health check scheduler
HealthCheckerManager.setup();
// Setup the rss feed check scheduler
RssFeedManager.setup();
// Setup all slow mode handlers
generalThreadPool.schedule(() -> {
for (Guild guild : jda.getGuilds()) {
for (SlowModeInfo info : storageManager.getSlowModeChannels(guild)) {
jda.addEventListener(new SlowmodeHandler(info.getChannel(), info.getDelay()));
}
}
}, 5, TimeUnit.SECONDS);
// Start the bStats tracking thread
generalThreadPool.scheduleAtFixedRate(() -> {
JSONArray servers = new JSONArray(RestClient.get("https://bstats.org/api/v1/plugins/5273/charts/servers/data"));
JSONArray players = new JSONArray(RestClient.get("https://bstats.org/api/v1/plugins/5273/charts/players/data"));
int serverCount = servers.getJSONArray(servers.length() - 1).getInt(1);
int playerCount = players.getJSONArray(players.length() - 1).getInt(1);
jda.getPresence().setActivity(Activity.playing(BotHelpers.coolFormat(serverCount) + " servers, " + BotHelpers.coolFormat(playerCount) + " players"));
}, 5, 60 * 5, TimeUnit.SECONDS);
}
Aggregations