Search in sources :

Example 1 with MessageDeleteListener

use of dev.cerus.mapads.discordbot.listener.MessageDeleteListener in project map-ads by cerus-mc.

the class DiscordBot method start.

public CompletableFuture<Void> start() {
    final CompletableFuture<Void> future = new CompletableFuture<>();
    this.executorService.execute(() -> {
        try {
            this.jda = JDABuilder.createDefault(this.config.token, Arrays.asList(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGES)).addEventListeners(new MessageDeleteListener(this.storage), new ButtonInteractListener(this.storage, this.config, this.callback)).build().awaitReady();
            Activity.ActivityType type;
            try {
                type = Activity.ActivityType.valueOf(this.config.activityType);
            } catch (final IllegalArgumentException ignored) {
                type = Activity.ActivityType.LISTENING;
            }
            OnlineStatus status;
            try {
                status = OnlineStatus.valueOf(this.config.onlineStatus);
            } catch (final IllegalArgumentException ignored) {
                status = OnlineStatus.ONLINE;
            }
            final Activity activity = Activity.of(type, this.config.activityString);
            this.jda.getPresence().setPresence(status, activity);
            future.complete(null);
        } catch (final InterruptedException | LoginException e) {
            future.completeExceptionally(e);
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ButtonInteractListener(dev.cerus.mapads.discordbot.listener.ButtonInteractListener) MessageDeleteListener(dev.cerus.mapads.discordbot.listener.MessageDeleteListener) OnlineStatus(net.dv8tion.jda.api.OnlineStatus) Activity(net.dv8tion.jda.api.entities.Activity) LoginException(javax.security.auth.login.LoginException)

Aggregations

ButtonInteractListener (dev.cerus.mapads.discordbot.listener.ButtonInteractListener)1 MessageDeleteListener (dev.cerus.mapads.discordbot.listener.MessageDeleteListener)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 LoginException (javax.security.auth.login.LoginException)1 OnlineStatus (net.dv8tion.jda.api.OnlineStatus)1 Activity (net.dv8tion.jda.api.entities.Activity)1