Java Code Examples for net.dv8tion.jda.api.AccountType#BOT

The following examples show how to use net.dv8tion.jda.api.AccountType#BOT . 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: DiscordService.java    From Game with GNU General Public License v3.0 5 votes vote down vote up
private void startPlayerBot(final String token) {
	this.builder = new JDABuilder(AccountType.BOT);
	this.builder.setEventManager(new AnnotatedEventManager());
	this.builder.addEventListeners(this);
	this.builder.setToken(token);
	try {
		this.jda = this.builder.build();
	} catch (final LoginException a) {
		a.printStackTrace();
	}
}
 
Example 2
Source File: GuildImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Override
@Deprecated
public boolean checkVerification()
{
    if (getJDA().getAccountType() == AccountType.BOT)
        return true;
    if(canSendVerification)
        return true;

    switch (verificationLevel)
    {
        case VERY_HIGH:
            break; // we already checked for a verified phone number
        case HIGH:
            if (ChronoUnit.MINUTES.between(getSelfMember().getTimeJoined(), OffsetDateTime.now()) < 10)
                break;
        case MEDIUM:
            if (ChronoUnit.MINUTES.between(getJDA().getSelfUser().getTimeCreated(), OffsetDateTime.now()) < 5)
                break;
        case LOW:
            if (!getJDA().getSelfUser().isVerified())
                break;
        case NONE:
            canSendVerification = true;
            return true;
        case UNKNOWN:
            return true; // try and let discord decide
    }
    return false;
}
 
Example 3
Source File: AuthorizationConfig.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
public AccountType getAccountType()
{
    return AccountType.BOT;
}
 
Example 4
Source File: PrivateChannelImpl.java    From JDA with Apache License 2.0 4 votes vote down vote up
private void checkBot()
{
    if (getUser().isBot() && getJDA().getAccountType() == AccountType.BOT)
        throw new UnsupportedOperationException("Cannot send a private message between bots.");
}
 
Example 5
Source File: TextChannelImpl.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
@SuppressWarnings("ConstantConditions")
public List<CompletableFuture<Void>> purgeMessagesById(@Nonnull long... messageIds)
{
    if (messageIds == null || messageIds.length == 0)
        return Collections.emptyList();
    if (getJDA().getAccountType() != AccountType.BOT
        || !getGuild().getSelfMember().hasPermission(this, Permission.MESSAGE_MANAGE))
        return TextChannel.super.purgeMessagesById(messageIds);

    // remove duplicates and sort messages
    List<CompletableFuture<Void>> list = new LinkedList<>();
    TreeSet<Long> bulk = new TreeSet<>(Comparator.reverseOrder());
    TreeSet<Long> norm = new TreeSet<>(Comparator.reverseOrder());
    long twoWeeksAgo = TimeUtil.getDiscordTimestamp(System.currentTimeMillis() - (14 * 24 * 60 * 60 * 1000) + 10000);
    for (long messageId : messageIds)
    {
        if (messageId > twoWeeksAgo)
            bulk.add(messageId);
        else
            norm.add(messageId);
    }

    // delete chunks of 100 messages each
    if (!bulk.isEmpty())
    {
        List<String> toDelete = new ArrayList<>(100);
        while (!bulk.isEmpty())
        {
            toDelete.clear();
            for (int i = 0; i < 100 && !bulk.isEmpty(); i++)
                toDelete.add(Long.toUnsignedString(bulk.pollLast()));
            if (toDelete.size() == 1)
                list.add(deleteMessageById(toDelete.get(0)).submit());
            else if (!toDelete.isEmpty())
                list.add(deleteMessages0(toDelete).submit());
        }
    }

    // delete messages too old for bulk delete
    if (!norm.isEmpty())
    {
        for (long message : norm)
            list.add(deleteMessageById(message).submit());
    }
    return list;
}
 
Example 6
Source File: WebSocketClient.java    From JDA with Apache License 2.0 4 votes vote down vote up
protected String getToken()
{
    if (api.getAccountType() == AccountType.BOT)
        return api.getToken().substring("Bot ".length());
    return api.getToken();
}