本文整理汇总了Java中net.dv8tion.jda.core.OnlineStatus类的典型用法代码示例。如果您正苦于以下问题:Java OnlineStatus类的具体用法?Java OnlineStatus怎么用?Java OnlineStatus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OnlineStatus类属于net.dv8tion.jda.core包,在下文中一共展示了OnlineStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initDiscord
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
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: action
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
@Override
public void action(String[] args, MessageReceivedEvent event) {
EmbedBuilder builder = new EmbedBuilder();
builder.setAuthor("Server Info", null, "http://i.imgur.com/880AyL6.png");
builder.setColor(Color.decode(SelfBot.getConfig().getColor()));
builder.setThumbnail(event.getGuild().getIconUrl());
builder.addField("Name", event.getGuild().getName(), true);
builder.addBlankField(true);
builder.addField("Owner", event.getGuild().getOwner().getUser().getName() + "#" + event.getGuild().getOwner().getUser().getDiscriminator() , true);
builder.addField("Server ID", event.getGuild().getId(), true);
builder.addField("Region", event.getGuild().getRegion().name(), true);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy h:mm a");
builder.addField("Creation Date", event.getGuild().getCreationTime().format(formatter), true);
builder.addField("Total Members", String.valueOf(event.getGuild().getMembers().size()), true);
int online = 0;
for(Member member : event.getGuild().getMembers()) {
if(!member.getOnlineStatus().equals(OnlineStatus.OFFLINE)) {
++online;
}
}
builder.addField("Online Members", String.valueOf(online), true);
event.getMessage().editMessage(builder.build()).queue();
}
示例3: setup
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
/**
* Setup this bot.
*/
private void setup() {
if (Configs.getMainConfig().getDiscordToken() == null) {
Core.warn("Discord Token is not set, discord integrations will not function.");
return;
}
try {
bot = new JDABuilder(AccountType.BOT).setToken(Configs.getMainConfig().getDiscordToken())
.addEventListener(this).setAutoReconnect(true).setGame(Game.of("Kineticraft"))
.setStatus(OnlineStatus.ONLINE).buildAsync(); // Setup listener and connect to discord.
active = true;
} catch (Exception e) {
e.printStackTrace();
Core.warn("Failed to setup discord bot.");
}
}
示例4: onIntent
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
@Override
public void onIntent(Message message, AIResponse response) {
if (!message.getChannelType().isGuild()) {
MessageFactory.makeWarning(message, "Right now it's just me and you online ;)").queue();
return;
}
int online = 0;
for (Member member : message.getGuild().getMembers()) {
if (!member.getOnlineStatus().equals(OnlineStatus.OFFLINE)) {
online++;
}
}
MessageFactory.makeInfo(message, "There are **:online** people online out of **:total** people on the server.")
.set("online", online)
.set("total", message.getGuild().getMembers().size())
.queue();
}
示例5: start
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
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();
}
示例6: onDisable
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
@Override
public void onDisable() {
//fjs.stop();
McLink.instance.bot.bot.getPresence().setStatus(OnlineStatus.INVISIBLE);
McLink.instance.bot.shutdown();
try {
McLink.instance.database.getConnection().commit();
} catch (SQLException e) {
e.printStackTrace();
}
bott.enabled = false;
database.commit();
//database.closeConnection();
System.out.println("Shutdown Database");
Bukkit.getLogger().removeHandler(customLogHandler);
getLogger().removeHandler(customLogHandler);
Bukkit.getServer().getLogger().removeHandler(customLogHandler);
}
示例7: execute
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
@Override
protected void execute(CommandEvent event) {
try {
OnlineStatus status = OnlineStatus.fromKey(event.getArgs());
if(status==OnlineStatus.UNKNOWN)
{
event.replyError("Please include one of the following statuses: `ONLINE`, `IDLE`, `DND`, `INVISIBLE`");
}
else
{
event.getJDA().getPresence().setStatus(status);
event.replySuccess("Set the status to `"+status.getKey().toUpperCase()+"`");
}
} catch(Exception e) {
event.reply(event.getClient().getError()+" The status could not be set!");
}
}
示例8: onReady
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
@Override
public void onReady(ReadyEvent event)
{
if(!event.getJDA().getSelfUser().isBot())
{
LOG.error("JDA-Utilities does not support CLIENT accounts.");
event.getJDA().shutdown();
return;
}
textPrefix = prefix.equals(DEFAULT_PREFIX) ? "@"+event.getJDA().getSelfUser().getName()+" " : prefix;
event.getJDA().getPresence().setStatus(status==null ? OnlineStatus.ONLINE : status);
if(game!=null)
event.getJDA().getPresence().setGame("default".equals(game.getName()) ?
Game.playing("Type "+textPrefix+helpWord) :
game);
sendStats(event.getJDA());
}
示例9: onExecute
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
/**
* Called when command is executed.
*
* @param args Arguments provided by user.
*/
@Override
void onExecute(String[] args) {
String opponentUsername = "";
if (args.length > 0) {
opponentUsername = args[0];
}
if (opponentUsername.isEmpty()) {
getMessageChannel().sendMessage("Who do you want to play against?");
opponentUsername = nextMessage().getContent().split(" ")[0];
}
this.opponent = getJda().getUsersByName(opponentUsername, true).get(0);
if (opponent == null || getGuild().getMember(opponent).getOnlineStatus() != OnlineStatus.ONLINE) {
getMessageChannel().sendMessage("This user isn't online, or doesn't exist.");
return;
}
getMessageChannel().sendMessage("Starting Tic Tac Toe game!\n" +
"Opposing " + getExecutor().getName() + "(X) and " + opponent.getName() + "(O) !\n" +
"To play, enter the letter A B or C followed by 1 2 or 3 when it's your turn.");
startGame();
}
示例10: setPresence
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
@Override
public void setPresence(OnlineStatus status, Game game, boolean idle)
{
JSONObject gameObj = getGameJson(game);
Checks.check(status != OnlineStatus.UNKNOWN,
"Cannot set the presence status to an unknown OnlineStatus!");
if (status == OnlineStatus.OFFLINE || status == null)
status = OnlineStatus.INVISIBLE;
JSONObject object = new JSONObject();
if (gameObj == null)
object.put("game", JSONObject.NULL);
else
object.put("game", gameObj);
object.put("afk", idle);
object.put("status", status.getKey());
object.put("since", System.currentTimeMillis());
update(object);
this.idle = idle;
this.status = status;
this.game = gameObj == null ? null : game;
}
示例11: main
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
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();
}
}
示例12: guildinfo
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
@RegisterCommand
public static void guildinfo(CommandRegistry cr) {
cr.register("serverinfo", SimpleCommand.builder(Category.INFO)
.permission(CommandPermission.USER)
.code((thiz, event, content, args) -> {
Guild guild = event.getGuild();
TextChannel channel = event.getChannel();
String roles = guild.getRoles().stream()
.filter(role -> !guild.getPublicRole().equals(role))
.map(Role::getName)
.collect(Collectors.joining(", "));
if (roles.length() > 1024)
roles = roles.substring(0, 1024 - 4) + "...";
channel.sendMessage(new EmbedBuilder()
.setAuthor("Server Information", null, guild.getIconUrl())
.setColor(guild.getOwner().getColor() == null ? Color.ORANGE : guild.getOwner().getColor())
.setDescription("Server information for " + guild.getName())
.setThumbnail(guild.getIconUrl())
.addField("Users (Online/Unique)", (int) guild.getMembers().stream().filter(u -> !u.getOnlineStatus().equals(OnlineStatus.OFFLINE)).count() + "/" + guild.getMembers().size(), true)
.addField("Main Channel", guild.getPublicChannel().getAsMention(), true)
.addField("Creation Date", guild.getCreationTime().format(DateTimeFormatter.ISO_DATE_TIME).replaceAll("[^0-9.:-]", " "), true)
.addField("Voice/Text Channels", guild.getVoiceChannels().size() + "/" + guild.getTextChannels().size(), true)
.addField("Owner", guild.getOwner().getUser().getName() + "#" + guild.getOwner().getUser().getDiscriminator(), true)
.addField("Region", guild.getRegion() == null ? "Unknown." : guild.getRegion().getName(), true)
.addField("Roles (" + guild.getRoles().size() + ")", roles, false)
.setFooter("Server ID: " + String.valueOf(guild.getId()), null)
.build()
).queue();
})
.help((thiz, event) -> thiz.helpEmbed(event, "Server Info Command")
.addField("Description:", "See your server's current stats.", false)
.setColor(event.getGuild().getOwner().getColor() == null ? Color.ORANGE : event.getGuild().getOwner().getColor())
.build())
.build());
}
示例13: execute
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
@Override
protected void execute(CommandEvent event)
{
if(event.getArgs().isEmpty())
{
event.replyError("Please provide me a valid OnlineStatus!");
return;
}
if(event.getArgs().equals("help"))
{
event.replyInDM("Help for subcommand `bot status`\n"
+ "Valid options: `ONLINE`, `DO_NOT_DISTURB`, `INVISIBLE`, `AWAY`");
event.reactSuccess();
return;
}
try
{
String status = event.getArgs();
event.getJDA().getPresence().setStatus(OnlineStatus.valueOf(status));
event.replySuccess("Changed status to "+event.getJDA().getPresence().getStatus()+" without error!");
}
catch(Exception e)
{
event.replyError("Error when changing the status! Check the Bot console for more information.");
e.printStackTrace();
}
}
示例14: onUserOnlineStatusUpdate
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
public void onUserOnlineStatusUpdate(UserOnlineStatusUpdateEvent event) {
OnlineStatus on = event.getGuild().getMember(event.getUser()).getOnlineStatus();
if (event.getGuild().getOwner().getUser().getId().equals("153507094933274624")){
event.getGuild().getTextChannelsByName("botlog", true).get(0).sendMessage(
new EmbedBuilder()
.setColor(Color.cyan)
.setDescription("User **" + event.getUser().getAsMention() + "** is now **" + on + "**!")
.build()
).queue();
}else return;
}
示例15: login
import net.dv8tion.jda.core.OnlineStatus; //导入依赖的package包/类
@Override
public void login(String token, ShardInfo shardInfo, SessionReconnectQueue reconnectQueue) throws LoginException, RateLimitedException {
setStatus(Status.LOGGING_IN);
if(token == null || token.isEmpty()) throw new LoginException("Provided token was null or empty!");
setToken(token);
verifyToken();
this.shardInfo = shardInfo;
JDAImpl.LOG.info("Login Successful!");
client = new ServerWebSocketClient(this, reconnectQueue, gatewayServer);
JSONObject cachedPresence = gatewayServer.cachedPresence;
if(cachedPresence != null) {
JSONObject game = cachedPresence.optJSONObject("game");
if(game != null) {
getPresence().setPresence(
OnlineStatus.fromKey(cachedPresence.getString("status")),
Game.of(game.getString("name"), game.optString("url")),
cachedPresence.getBoolean("afk")
);
} else {
getPresence().setPresence(
OnlineStatus.fromKey(cachedPresence.getString("status")),
null,
cachedPresence.getBoolean("afk")
);
}
gatewayServer.cachedPresence = null;
}
if(shutdownHook != null) {
Runtime.getRuntime().addShutdownHook(shutdownHook);
}
}