net.dv8tion.jda.api.events.guild.GuildJoinEvent Java Examples

The following examples show how to use net.dv8tion.jda.api.events.guild.GuildJoinEvent. 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: GuildListener.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onEvent(@Nonnull GenericEvent event) {
    if (event instanceof GuildJoinEvent) {
        this.onGuildJoin((GuildJoinEvent) event);
    } else if (event instanceof GuildLeaveEvent) {
        this.onGuildLeave((GuildLeaveEvent) event);
    } else if (event instanceof GuildVoiceLeaveEvent) {
        this.onGuildVoiceLeave((GuildVoiceLeaveEvent) event);
    } else if (event instanceof GuildVoiceJoinEvent) {
        this.onGuildVoiceJoin((GuildVoiceJoinEvent) event);
    } else if (event instanceof GuildVoiceMoveEvent) {
        this.onGuildVoiceMove((GuildVoiceMoveEvent) event);
    } else if (event instanceof GuildBanEvent) {
        this.onGuildBan((GuildBanEvent) event);
    } else if (event instanceof GuildUnbanEvent) {
        this.onGuildUnban((GuildUnbanEvent) event);
    }
}
 
Example #2
Source File: GuildListener.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
private void onGuildJoin(GuildJoinEvent event) {
    final Guild guild = event.getGuild();

    if (isBotfarm(guild)) {
        return;
    }

    logger.info("{}Joining guild {}, ID: {} on shard {}{}",
        TextColor.GREEN,
        guild.getName(),
        guild.getId(),
        guild.getJDA().getShardInfo().getShardId(),
        TextColor.RESET
    );

    GuildSettingsUtils.registerNewGuild(guild, variables);
}
 
Example #3
Source File: GuildSetupNode.java    From JDA with Apache License 2.0 5 votes vote down vote up
private void completeSetup()
{
    updateStatus(GuildSetupController.Status.BUILDING);
    JDAImpl api = getController().getJDA();
    for (TLongIterator it = removedMembers.iterator(); it.hasNext(); )
        members.remove(it.next());
    removedMembers.clear();
    GuildImpl guild = api.getEntityBuilder().createGuild(id, partialGuild, members, expectedMemberCount);
    updateAudioManagerReference(guild);
    switch (type)
    {
    case AVAILABLE:
        api.handleEvent(new GuildAvailableEvent(api, api.getResponseTotal(), guild));
        getController().remove(id);
        break;
    case JOIN:
        api.handleEvent(new GuildJoinEvent(api, api.getResponseTotal(), guild));
        if (requestedChunk)
            getController().ready(id);
        else
            getController().remove(id);
        break;
    default:
        api.handleEvent(new GuildReadyEvent(api, api.getResponseTotal(), guild));
        getController().ready(id);
        break;
    }
    updateStatus(GuildSetupController.Status.READY);
    GuildSetupController.log.debug("Finished setup for guild {} firing cached events {}", id, cachedEvents.size());
    api.getClient().handle(cachedEvents);
    api.getEventCache().playbackCache(EventCache.Type.GUILD, id);
}
 
Example #4
Source File: GuildListener.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onGuildJoin(GuildJoinEvent event) {
    Guild guild = event.getGuild();
    Member self = guild.getSelfMember();

    TextChannel channel = guild.getDefaultChannel();
    if (channel != null && !self.hasPermission(channel,
            Permission.MESSAGE_WRITE, Permission.MESSAGE_EMBED_LINKS)) {
        channel = null;
    }

    if (channel == null) {
        for (TextChannel textChannel : guild.getTextChannels()) {
            if (self.hasPermission(textChannel,
                    Permission.MESSAGE_WRITE, Permission.MESSAGE_EMBED_LINKS)) {
                channel = textChannel;
                break;
            }
        }
    }

    Gulag gulag = gulagService.getGulag(guild);
    if (gulag != null) {
        if (channel != null) {
            EmbedBuilder builder = messageService.getBaseEmbed();
            builder.setDescription(messageService.getMessage("discord.gulag.message"));
            builder.addField(messageService.getMessage("discord.gulag.reason"),
                    CommonUtils.trimTo(gulag.getReason(), MessageEmbed.VALUE_MAX_LENGTH), true);
            channel.sendMessage(builder.build()).queue(e -> guild.leave().queue(), e -> guild.leave().queue());
        } else {
            guild.leave().queue();
        }
        return;
    }

    GuildConfig config = entityAccessor.getOrCreate(event.getGuild());
    switch (event.getGuild().getRegion()) {
        case RUSSIA:
            config.setLocale(LocaleUtils.RU_LOCALE);
            config.setCommandLocale(LocaleUtils.RU_LOCALE);
            break;
        default:
            config.setLocale(LocaleUtils.DEFAULT_LOCALE);
            config.setCommandLocale(LocaleUtils.DEFAULT_LOCALE);
            break;
    }
    configService.save(config);
    contextService.initContext(event.getGuild()); // reinit context with updated locale
    sendWelcome(channel, event);
}
 
Example #5
Source File: StatisticsListener.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onGuildJoin(GuildJoinEvent event) {
    statisticsService.notifyProviders(event.getJDA());
}
 
Example #6
Source File: GuildListener.java    From Arraybot with Apache License 2.0 2 votes vote down vote up
/**
 * When the bot is added to a guild.
 * This may be triggered due to downtime.
 * @param event The event.
 */
@Override
public void onGuildJoin(GuildJoinEvent event) {
    update(event.getJDA());
}