本文整理汇总了Java中net.dv8tion.jda.core.AccountType.BOT属性的典型用法代码示例。如果您正苦于以下问题:Java AccountType.BOT属性的具体用法?Java AccountType.BOT怎么用?Java AccountType.BOT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类net.dv8tion.jda.core.AccountType
的用法示例。
在下文中一共展示了AccountType.BOT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initDiscord
private static void initDiscord() {
JDABuilder builder = new JDABuilder(AccountType.BOT);
try {
builder.setToken(BotConfig.DISCORD_TOKEN);
builder.setAutoReconnect(true);
builder.setStatus(OnlineStatus.ONLINE);
builder.addEventListener(new ReadyListener());
builder.addEventListener(new MessageListener());
builder.buildBlocking();
} catch (Throwable e) {
e.printStackTrace();
} finally {
builder.setStatus(OnlineStatus.OFFLINE);
}
}
示例2: start
public void start() throws LoginException, InterruptedException, RateLimitedException {
running = true;
// init logger
AnsiConsole.systemInstall();
log = Logger.getLogger("Kyoko");
log.setUseParentHandlers(false);
ColoredFormatter formatter = new ColoredFormatter();
ConsoleHandler handler = new ConsoleHandler();
handler.setFormatter(formatter);
log.addHandler(handler);
log.info("Kyoko v" + Constants.VERSION + " is starting...");
i18n.loadMessages();
JDABuilder builder = new JDABuilder(AccountType.BOT);
if (settings.getToken() != null) {
if (settings.getToken().equalsIgnoreCase("Change me")) {
System.out.println("No token specified, please set it in config.json");
System.exit(1);
}
builder.setToken(settings.getToken());
}
boolean gameEnabled = false;
if (settings.getGame() != null && !settings.getGame().isEmpty()) {
gameEnabled = true;
builder.setGame(Game.of("booting..."));
}
builder.setAutoReconnect(true);
builder.setBulkDeleteSplittingEnabled(false);
builder.addEventListener(eventHandler);
builder.setAudioEnabled(true);
builder.setStatus(OnlineStatus.IDLE);
jda = builder.buildBlocking();
log.info("Invite link: " + "https://discordapp.com/oauth2/authorize?&client_id=" + jda.getSelfUser().getId() + "&scope=bot&permissions=" + Constants.PERMISSIONS);
if (gameEnabled) {
Thread t = new Thread(new Kyoko.BlinkThread());
t.start();
}
registerCommands();
}
示例3: main
public static final void main(String[] args) {
try {
Standard.setStarted(Instant.now());
System.setOut(new SystemOutputStream(System.out, false));
System.setErr(new SystemOutputStream(System.err, true));
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
//Standard.STANDARD_SETTINGS.saveSettings(); //FIXME WTF This is deleting the settings file all the time?!
Standard.saveAllGuildSettings();
}));
Standard.JDA_SUPPLIER = () -> jda;
NetworkUtil.init();
reload();
MySQL.init();
builder = new JDABuilder(AccountType.BOT);
builder.setAutoReconnect(true);
//builder.setAudioSendFactory(null);
builder.setStatus(OnlineStatus.ONLINE);
builder.setGame(game = Game.of("Supreme-Bot"));
initListeners();
initCommands();
init();
initPlugins();
loadAllGuilds();
startJDA();
} catch (Exception ex) {
System.err.println("Main Error: " + ex);
ex.printStackTrace();
}
}
示例4: onMessageReceived
@Override
public void onMessageReceived(MessageReceivedEvent event) {
if (event.getMessage().getRawContent().startsWith(jba.getPrefix(event.getGuild())) &&
(jba.getClient().getAccountType() == AccountType.BOT && !event.getAuthor().isBot() || jba.getClient().getAccountType() == AccountType.CLIENT && event.getMessage()
.getAuthor().getId().equals(jba.getClient().getSelfUser().getId()))) {
String message = event.getMessage().getRawContent();
String command = message.replaceFirst(Pattern.quote(jba.getPrefix(event.getGuild())), "");
String[] args = new String[0];
if (message.contains(" ")) {
command = command.substring(0, command.indexOf(" "));
args = message.substring(message.indexOf(" ") + 1).split(" ");
}
for (Command cmd : jba.getCommands()) {
if (cmd.getCommand().equalsIgnoreCase(command)) {
execute(cmd, args, event);
return;
} else {
for (String alias : cmd.getAliases()) {
if (alias.equalsIgnoreCase(command)) {
execute(cmd, args, event);
return;
}
}
}
}
}
}
示例5: init
public void init(){
// This is the new config system, here you make a JSON file which you can hold a bunch of configurable values.
// In this case we are using it to store token and prefix.
// The parameter for Config is the config name (If it doesn't have a .json extension it will be added itself!)
config = new Config("config");
// This is your account type so AccountType.BOT or AccountType.CLIENT
// Then pass your bot/client token
// Third argument is the command prefix. You can chose to not include this for no command system.
super.init(AccountType.BOT, config.getString("token"), config.getString("prefix"));
}
示例6: initJDA
/**
* Initializes the JDA instance.
*/
public static void initJDA() {
if (instance == null)
throw new NullPointerException("RubiconBot has not been initialized yet.");
JDABuilder builder = new JDABuilder(AccountType.BOT);
builder.setToken(instance.configuration.getString("token"));
builder.setGame(Game.playing("Starting...."));
// add all EventListeners
for (EventListener listener : instance.eventListeners)
builder.addEventListener(listener);
new ListenerManager(builder);
try {
instance.jda = builder.buildBlocking();
} catch (LoginException | InterruptedException e) {
Logger.error(e.getMessage());
}
CommandVote.loadPolls(instance.jda);
Info.lastRestart = new Date();
// CommandGiveaway.startGiveawayManager(instance.jda);
getJDA().getPresence().setGame(Game.playing("Started."));
GameAnimator.start();
}
示例7: JDAImpl
public JDAImpl(AccountType accountType, String token, SessionController controller, OkHttpClient.Builder httpClientBuilder, WebSocketFactory wsFactory,
boolean autoReconnect, boolean audioEnabled, boolean useShutdownHook, boolean bulkDeleteSplittingEnabled, boolean retryOnTimeout, boolean enableMDC,
int corePoolSize, int maxReconnectDelay, ConcurrentMap<String, String> contextMap)
{
this.accountType = accountType;
this.setToken(token);
this.httpClientBuilder = httpClientBuilder;
this.wsFactory = wsFactory;
this.autoReconnect = autoReconnect;
this.audioEnabled = audioEnabled;
this.shutdownHook = useShutdownHook ? new Thread(this::shutdown, "JDA Shutdown Hook") : null;
this.bulkDeleteSplittingEnabled = bulkDeleteSplittingEnabled;
this.pool = new ScheduledThreadPoolExecutor(corePoolSize, new JDAThreadFactory());
this.maxReconnectDelay = maxReconnectDelay;
this.sessionController = controller == null ? new SessionControllerAdapter() : controller;
if (enableMDC)
this.contextMap = contextMap == null ? new ConcurrentHashMap<>() : contextMap;
else
this.contextMap = null;
this.presence = new PresenceImpl(this);
this.requester = new Requester(this);
this.requester.setRetryOnTimeout(retryOnTimeout);
this.jdaClient = accountType == AccountType.CLIENT ? new JDAClientImpl(this) : null;
this.jdaBot = accountType == AccountType.BOT ? new JDABotImpl(this) : null;
}
示例8: setToken
public void setToken(String token)
{
if (getAccountType() == AccountType.BOT)
this.token = "Bot " + token;
else
this.token = token;
}
示例9: verifyAccountType
private void verifyAccountType(JSONObject userResponse)
{
if (getAccountType() == AccountType.BOT)
{
if (!userResponse.has("bot") || !userResponse.getBoolean("bot"))
throw new AccountTypeException(AccountType.BOT, "Attempted to login as a BOT with a CLIENT token!");
}
else
{
if (userResponse.has("bot") && userResponse.getBoolean("bot"))
throw new AccountTypeException(AccountType.CLIENT, "Attempted to login as a CLIENT with a BOT token!");
}
}
示例10: checkVerification
@Override
public boolean checkVerification()
{
if (api.getAccountType() == AccountType.BOT)
return true;
if(canSendVerification)
return true;
if (api.getSelfUser().getPhoneNumber() != null)
return canSendVerification = true;
switch (verificationLevel)
{
case VERY_HIGH:
break; // we already checked for a verified phone number
case HIGH:
if (ChronoUnit.MINUTES.between(getSelfMember().getJoinDate(), OffsetDateTime.now()) < 10)
break;
case MEDIUM:
if (ChronoUnit.MINUTES.between(MiscUtil.getCreationTime(api.getSelfUser()), OffsetDateTime.now()) < 5)
break;
case LOW:
if (!api.getSelfUser().isVerified())
break;
case NONE:
canSendVerification = true;
return true;
case UNKNOWN:
return true; // try and let discord decide
}
return false;
}
示例11: Requester
public Requester(JDA api, AccountType accountType)
{
if (accountType == null)
throw new NullPointerException("Provided accountType was null!");
this.api = (JDAImpl) api;
if (accountType == AccountType.BOT)
rateLimiter = new BotRateLimiter(this, 5);
else
rateLimiter = new ClientRateLimiter(this, 5);
this.httpClient = this.api.getHttpClientBuilder().build();
}
示例12: RestJDA
public RestJDA(String token)
{
fakeJDA = new JDAImpl(AccountType.BOT, token, null, new OkHttpClient.Builder(), null, false, false, false, false, true, false, 2, 900, null);
}
示例13: GatewayClientJDABuilder
protected GatewayClientJDABuilder(GatewayClient gatewayClient) {
super(AccountType.BOT);
this.gatewayClient = gatewayClient;
}
示例14: GatewayServerJDABuilder
protected GatewayServerJDABuilder(GatewayServer gatewayServer) {
super(AccountType.BOT);
this.gatewayServer = gatewayServer;
}
示例15: buildInstance
protected JDAImpl buildInstance(final int shardId) throws LoginException, InterruptedException
{
final JDAImpl jda = new JDAImpl(AccountType.BOT, this.token, this.controller, this.httpClientBuilder, this.wsFactory,
this.autoReconnect, this.enableVoice, false, this.enableBulkDeleteSplitting, this.retryOnTimeout, this.enableMDC,
this.corePoolSize, this.maxReconnectDelay, this.contextProvider == null || !this.enableMDC ? null : contextProvider.apply(shardId));
jda.asBot().setShardManager(this);
if (this.eventManager != null)
jda.setEventManager(this.eventManager);
if (this.audioSendFactory != null)
jda.setAudioSendFactory(this.audioSendFactory);
this.listeners.forEach(jda::addEventListener);
jda.setStatus(JDA.Status.INITIALIZED); //This is already set by JDA internally, but this is to make sure the listeners catch it.
// Set the presence information before connecting to have the correct information ready when sending IDENTIFY
PresenceImpl presence = ((PresenceImpl) jda.getPresence());
if (gameProvider != null)
presence.setCacheGame(this.gameProvider.apply(shardId));
if (idleProvider != null)
presence.setCacheIdle(this.idleProvider.apply(shardId));
if (statusProvider != null)
presence.setCacheStatus(this.statusProvider.apply(shardId));
if (this.gatewayURL == null)
{
try
{
Pair<String, Integer> gateway = jda.getGatewayBot();
this.gatewayURL = gateway.getLeft();
if (this.shardsTotal == -1)
{
this.shardsTotal = gateway.getRight();
this.shards = new ShardCacheViewImpl(this.shardsTotal);
synchronized (queue)
{
for (int i = 0; i < shardsTotal; i++)
queue.add(i);
}
}
}
catch (RuntimeException e)
{
if (e.getCause() instanceof InterruptedException)
throw (InterruptedException) e.getCause();
//We check if the LoginException is masked inside of a ExecutionException which is masked inside of the RuntimeException
Throwable ex = e.getCause() instanceof ExecutionException ? e.getCause().getCause() : null;
if (ex instanceof LoginException)
throw new LoginException(ex.getMessage());
else
throw e;
}
}
final JDA.ShardInfo shardInfo = new JDA.ShardInfo(shardId, this.shardsTotal);
final int shardTotal = jda.login(this.gatewayURL, shardInfo);
if (this.shardsTotal == -1)
this.shardsTotal = shardTotal;
return jda;
}