discord4j.core.event.domain.lifecycle.ReadyEvent Java Examples

The following examples show how to use discord4j.core.event.domain.lifecycle.ReadyEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReadyEventListener.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void handle(ReadyEvent event) {
	Logger.getLogger().debug("Ready!", false);
	try {
		//Start keep-alive
		KeepAliveHandler.startKeepAlive(60);

		TimeManager.getManager().init();

		//Lets test the new announcement multi-threader...
		AnnouncementThreader.getThreader().init();

		GlobalConst.iconUrl = DisCalClient.getClient().getApplicationInfo().block().getIcon(Image.Format.PNG).get();

		MessageManager.reloadLangs();

		Logger.getLogger().debug("[ReadyEvent] Connection success! Session ID: " + event.getSessionId(), false);

		Logger.getLogger().status("Ready Event Success!", null);
	} catch (Exception e) {
		Logger.getLogger().exception(null, "BAD!!!", e, true, ReadyEventListener.class);
	}
}
 
Example #2
Source File: ReadyEventListener.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void handle(ReadyEvent event) {
	Logger.getLogger().debug("Ready!", false);
	try {
		//Start keep-alive
		KeepAliveHandler.startKeepAlive(60);

		TimeManager.getManager().init();

		//Lets test the new announcement multi-threader...
		AnnouncementThreader.getThreader().init();

		GlobalConst.iconUrl = DisCalClient.getClient().getApplicationInfo().block().getIcon(Image.Format.PNG).get();

		MessageManager.reloadLangs();

		Logger.getLogger().debug("[ReadyEvent] Connection success! Session ID: " + event.getSessionId(), false);

		Logger.getLogger().status("Ready Event Success!", null);
	} catch (Exception e) {
		Logger.getLogger().exception(null, "BAD!!!", e, true, ReadyEventListener.class);
	}
}
 
Example #3
Source File: ExampleQuickstartBlocking.java    From Discord4J with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
    DiscordClient.create(System.getenv("token"))
            .withGateway(client -> {
                client.on(ReadyEvent.class)
                        .subscribe(ready -> System.out.println("Logged in as " + ready.getSelf().getUsername()));

                client.on(MessageCreateEvent.class)
                        .subscribe(event -> {
                            Message message = event.getMessage();
                            if (message.getContent().equals("!ping")) {
                                message.getChannel().block().createMessage("Pong!").block();
                            }
                        });

                return client.onDisconnect();
            })
            .block();
}
 
Example #4
Source File: ExampleQuickstart.java    From Discord4J with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
    DiscordClient.create(System.getenv("token"))
            .withGateway(client -> {
                client.getEventDispatcher().on(ReadyEvent.class)
                        .subscribe(ready -> System.out.println("Logged in as " + ready.getSelf().getUsername()));

                client.getEventDispatcher().on(MessageCreateEvent.class)
                        .map(MessageCreateEvent::getMessage)
                        .filter(msg -> msg.getContent().equals("!ping"))
                        .flatMap(Message::getChannel)
                        .flatMap(channel -> channel.createMessage("Pong!"))
                        .subscribe();

                return client.onDisconnect();
            })
            .block();
}
 
Example #5
Source File: ExampleWithEventDispatcher.java    From Discord4J with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
    DiscordClient.create(System.getenv("token"))
            .gateway()
            .setSharding(ShardingStrategy.fixed(2))
            .withEventDispatcher(eventDispatcher -> eventDispatcher.on(ReadyEvent.class)
                    .doOnNext(ready -> log.info("Logged in as {}", ready.getSelf().getUsername())))
            .login()
            .block()
            .onDisconnect()
            .block();
}
 
Example #6
Source File: ExampleWithGateway.java    From Discord4J with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
    DiscordClient.create(System.getenv("token"))
            .gateway()
            .setInitialStatus(s -> Presence.invisible())
            .withGateway(client -> client.on(ReadyEvent.class)
                    .doOnNext(ready -> log.info("Logged in as {}", ready.getSelf().getUsername()))
                    .then())
            .block();
}
 
Example #7
Source File: ExampleStore.java    From Discord4J with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
    JacksonResources jackson = JacksonResources.create();
    Map<String, AtomicLong> counts = new ConcurrentHashMap<>();
    DiscordClientBuilder.create(System.getenv("token"))
            .setJacksonResources(jackson)
            .build()
            .gateway()
            .setStoreService(MappingStoreService.create()
                    .setMapping(new NoOpStoreService(), MessageData.class)
                    .setFallback(new JdkStoreService()))
            .withGateway(gateway -> {
                log.info("Start!");

                Mono<Void> server = startHttpServer(gateway, counts, jackson.getObjectMapper()).then();

                Mono<Void> listener = gateway.on(GatewayLifecycleEvent.class)
                        .filter(e -> !e.getClass().equals(ReadyEvent.class))
                        .doOnNext(e -> log.info("[shard={}] {}", e.getShardInfo().format(), e.toString()))
                        .then();

                Mono<Void> eventCounter = Flux.fromIterable(reflections.getSubTypesOf(Event.class))
                        .filter(cls -> reflections.getSubTypesOf(cls).isEmpty())
                        .flatMap(type -> gateway.on(type).doOnNext(event -> {
                            String key = event.getClass().getSimpleName();
                            counts.computeIfAbsent(key, k -> new AtomicLong()).addAndGet(1);
                        }))
                        .then();

                return Mono.when(server, listener, eventCounter);
            })
            .block();
}
 
Example #8
Source File: DisCalClient.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
	//Get settings
	Properties p = new Properties();
	p.load(new FileReader(new File("settings.properties")));
	BotSettings.init(p);

	//Init logger
	Logger.getLogger().init();

	//Handle client setup
	client = createClient();

	//Register discord events
	client.getEventDispatcher().on(ReadyEvent.class).subscribe(ReadyEventListener::handle);

	//Register discal events
	EventManager.get().init();
	EventManager.get().getEventBus().register(new PubSubListener());

	//Register commands
	CommandExecutor executor = CommandExecutor.getExecutor().enable();
	executor.registerCommand(new HelpCommand());
	executor.registerCommand(new DisCalCommand());
	executor.registerCommand(new CalendarCommand());
	executor.registerCommand(new AddCalendarCommand());
	executor.registerCommand(new TimeCommand());
	executor.registerCommand(new LinkCalendarCommand());
	executor.registerCommand(new EventListCommand());
	executor.registerCommand(new EventCommand());
	executor.registerCommand(new RsvpCommand());
	executor.registerCommand(new AnnouncementCommand());
	executor.registerCommand(new DevCommand());

	//Connect to MySQL
	DatabaseManager.getManager().connectToMySQL();
	DatabaseManager.getManager().handleMigrations();

	//Start Google authorization daemon
	Authorization.getAuth().init();

	//Load lang files
	MessageManager.reloadLangs();

	//Start Spring
	if (BotSettings.RUN_API.get().equalsIgnoreCase("true")) {
		try {
			SpringApplication.run(DisCalClient.class, args);
		} catch (Exception e) {
			e.printStackTrace();
			Logger.getLogger().exception(null, "'Spring ERROR' by 'PANIC! AT THE Communication'", e, true, DisCalClient.class);
		}
	}

	//Start Redis pub/sub listeners
	PubSubManager.get().init(BotSettings.REDIS_HOSTNAME.get(), Integer.valueOf(BotSettings.REDIS_PORT.get()), "N/a", BotSettings.REDIS_PASSWORD.get());
	//We must register each channel we want to use. This is super important.
	PubSubManager.get().register(clientId(), BotSettings.PUBSUB_PREFIX.get() + "/ToClient/All");

	//Login
	client.login().block();
}
 
Example #9
Source File: DisCalClient.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
	//Get settings
	Properties p = new Properties();
	p.load(new FileReader(new File("settings.properties")));
	BotSettings.init(p);

	//Init logger
	Logger.getLogger().init();

	//Handle client setup
	client = createClient();

	//Register discord events
	client.getEventDispatcher().on(ReadyEvent.class).subscribe(ReadyEventListener::handle);

	//Register discal events
	EventManager.get().init();
	EventManager.get().getEventBus().register(new PubSubListener());

	//Register commands
	CommandExecutor executor = CommandExecutor.getExecutor().enable();
	executor.registerCommand(new HelpCommand());
	executor.registerCommand(new DisCalCommand());
	executor.registerCommand(new CalendarCommand());
	executor.registerCommand(new AddCalendarCommand());
	executor.registerCommand(new TimeCommand());
	executor.registerCommand(new LinkCalendarCommand());
	executor.registerCommand(new EventListCommand());
	executor.registerCommand(new EventCommand());
	executor.registerCommand(new RsvpCommand());
	executor.registerCommand(new AnnouncementCommand());
	executor.registerCommand(new DevCommand());

	//Connect to MySQL
	DatabaseManager.getManager().connectToMySQL();
	DatabaseManager.getManager().handleMigrations();

	//Start Google authorization daemon
	Authorization.getAuth().init();

	//Load lang files
	MessageManager.reloadLangs();

	//Start Spring
	if (BotSettings.RUN_API.get().equalsIgnoreCase("true")) {
		try {
			SpringApplication.run(DisCalClient.class, args);
		} catch (Exception e) {
			e.printStackTrace();
			Logger.getLogger().exception(null, "'Spring ERROR' by 'PANIC! AT THE Communication'", e, true, DisCalClient.class);
		}
	}

	//Start Redis pub/sub listeners
	PubSubManager.get().init(BotSettings.REDIS_HOSTNAME.get(), Integer.valueOf(BotSettings.REDIS_PORT.get()), "N/a", BotSettings.REDIS_PASSWORD.get());
	//We must register each channel we want to use. This is super important.
	PubSubManager.get().register(clientId(), BotSettings.PUBSUB_PREFIX.get() + "/ToClient/All");

	//Login
	client.login().block();
}
 
Example #10
Source File: BotSupport.java    From Discord4J with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Mono<Void> readyHandler(GatewayDiscordClient client) {
    return client.on(ReadyEvent.class)
            .doOnNext(ready -> log.info("Logged in as {}", ready.getSelf().getUsername()))
            .then();
}