本文整理匯總了Java中net.dv8tion.jda.core.entities.Game類的典型用法代碼示例。如果您正苦於以下問題:Java Game類的具體用法?Java Game怎麽用?Java Game使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Game類屬於net.dv8tion.jda.core.entities包,在下文中一共展示了Game類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import net.dv8tion.jda.core.entities.Game; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
//Code by ZekroTJA(github.com/ZekroTJA)
StartArgumentHandler.args = args;
//MY CODE
builder = new JDABuilder(AccountType.BOT)
.setToken(SECRETS.TOKEN)
.setAudioEnabled(true)
.setAutoReconnect(true)
.setStatus(STATICS.STATUS)
.setGame(Game.of(STATICS.CUSTOM_MESSAGE + " | _help | coded by Lee", "http://twitch.tv/lordleeyt"))
;
initializeListeners();
initializeCommands();
SQL.connect();
LVL.connect();
try {
builder.buildBlocking();
} catch (InterruptedException | RateLimitedException | LoginException e) {
e.printStackTrace();
}
}
示例2: start
import net.dv8tion.jda.core.entities.Game; //導入依賴的package包/類
public void start() throws RateLimitedException, InterruptedException, LoginException {
this.discordAPI = new JDABuilder(AccountType.BOT)
.setToken(settings.getToken())
.setGame(new GameImpl(settings.getGame(), settings.getGameUrl(), settings.isTwitch() ? Game.GameType.TWITCH : Game.GameType.DEFAULT))
.addListener(new EventCaller(this))
.setAutoReconnect(true)
.setAudioEnabled(true)
.setBulkDeleteSplittingEnabled(false)
.buildBlocking();
if (settings.getRedis().isEnabled()) {
redisConnection.start();
keepDataThread.start();
}
initCommands();
initListeners();
}
示例3: updateStatus
import net.dv8tion.jda.core.entities.Game; //導入依賴的package包/類
void updateStatus() {
Runnable changeStatus = () -> {
AtomicInteger users = new AtomicInteger(0), guilds = new AtomicInteger(0);
if (MantaroRPG.getInstance() != null) {
Arrays.stream(MantaroRPG.getInstance().getShards()).map(MantaroShard::getJDA).forEach(jda -> {
users.addAndGet(jda.getUsers().size());
guilds.addAndGet(jda.getGuilds().size());
});
}
String newStatus = random(SPLASHES.get(), RANDOM)
.replace("%ramgb%", String.valueOf(((long) (Runtime.getRuntime().maxMemory() * 1.2D)) >> 30L))
.replace("%usercount%", users.toString())
.replace("%guildcount%", guilds.toString())
.replace("%shardcount%", String.valueOf(getTotalShards()))
.replace("%prettyusercount%", pretty(users.get()))
.replace("%prettyguildcount%", pretty(guilds.get()));
getJDA().getPresence().setGame(Game.of(config().get().prefix + "help | " + newStatus + " | [" + getId() + "]"));
log.debug("Changed status to: " + newStatus);
};
changeStatus.run();
Async.task("Splash Thread", changeStatus, 600);
}
示例4: execute
import net.dv8tion.jda.core.entities.Game; //導入依賴的package包/類
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
Configuration configuration = RubiconBot.getConfiguration();
if(!configuration.has(configKey)) {
configuration.set(configKey, "0");
}
if(parsedCommandInvocation.args.length == 0) {
configuration.set(configKey, "0");
return null;
}
String message = "";
for (String s : parsedCommandInvocation.args)
message += s + " ";
RubiconBot.getConfiguration().set(configKey, message);
parsedCommandInvocation.getMessage().getJDA().getPresence().setGame(Game.playing(message));
return new MessageBuilder().setEmbed(EmbedUtil.success("Status set!", "Successfully set the playing status!").build()).build();
}
示例5: fetch
import net.dv8tion.jda.core.entities.Game; //導入依賴的package包/類
@SuppressWarnings("UnusedReturnValue")
private static String fetch() {
try {
info = Unirest.get("https://gensokyoradio.net/xml").asString().getBody();
JSONObject data = XML.toJSONObject(GensokyoInfoAgent.getInfo()).getJSONObject("GENSOKYORADIODATA");
String newSong = data.getJSONObject("SONGINFO").getString("TITLE");
if (!newSong.equals(lastSong)) {
List<FredBoat> shards = FredBoat.getShards();
for(FredBoat shard : shards) {
shard.getJda().getPresence().setGame(Game.of(newSong));
}
log.info("Now playing " + newSong);
}
lastSong = data.getJSONObject("SONGINFO").getString("TITLE");
return info;
} catch (UnirestException e) {
throw new RuntimeException(e);
}
}
示例6: main
import net.dv8tion.jda.core.entities.Game; //導入依賴的package包/類
public static void main(final String[] args) throws Exception {
Thread.currentThread().setName("JukeBot-Main");
ConfigurationFactory.setConfigurationFactory(new Log4JConfig());
LOG = LogManager.getLogger("JukeBot");
playerManager = new DefaultAudioPlayerManager();
defaultPrefix = Database.getPropertyFromConfig("prefix");
String colour = Database.getPropertyFromConfig("color");
if (colour.equalsIgnoreCase("")) {
LOG.error("Missing property 'color' in the database.");
return;
}
embedColour = Color.decode(colour);
playerManager.setPlayerCleanupThreshold(30000);
playerManager.getConfiguration().setResamplingQuality(AudioConfiguration.ResamplingQuality.LOW);
playerManager.getConfiguration().setOpusEncodingQuality(9);
YoutubeAudioSourceManager yt = new YoutubeAudioSourceManager();
yt.setPlaylistPageCount(Integer.MAX_VALUE);
playerManager.registerSourceManager(yt);
AudioSourceManagers.registerRemoteSources(playerManager);
printBanner();
shardManager = new DefaultShardManagerBuilder()
.setToken(Database.getPropertyFromConfig("token"))
.setShardsTotal(-1)
.addEventListeners(new EventListener(), waiter)
.setAudioSendFactory(new NativeAudioSendFactory())
.setGame(Game.of(Game.GameType.LISTENING, defaultPrefix + "help | jukebot.xyz"))
.build();
}
示例7: onCommand
import net.dv8tion.jda.core.entities.Game; //導入依賴的package包/類
@Override
public boolean onCommand(Message message, String[] args) {
if (args.length == 0) {
return false;
}
Game game = parseGame(args);
message.getJDA().getPresence().setGame(game);
MessageFactory.makeSuccess(message, "Changed status to **:type :status**")
.set("type", getTypeAsString(game.getType()))
.set("status", game.getName())
.queue();
return true;
}
示例8: getGameFromType
import net.dv8tion.jda.core.entities.Game; //導入依賴的package包/類
private Game getGameFromType(String status, AvaireShard shard) {
Game game = Game.playing(status);
if (status.contains(":")) {
String[] split = status.split(":");
status = String.join(":", Arrays.copyOfRange(split, 1, split.length));
switch (split[0].toLowerCase()) {
case "listen":
case "listening":
return Game.listening(formatGame(status, shard));
case "watch":
case "watching":
return Game.watching(formatGame(status, shard));
case "play":
case "playing":
return Game.playing(formatGame(status, shard));
case "stream":
case "streaming":
return Game.streaming(formatGame(status, shard), "https://www.twitch.tv/senither");
}
}
return game;
}
示例9: start
import net.dv8tion.jda.core.entities.Game; //導入依賴的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();
}
示例10: PlaystatusHandler
import net.dv8tion.jda.core.entities.Game; //導入依賴的package包/類
public PlaystatusHandler() {
String json;
try {
json = IOUtils.toString(getClass().getResourceAsStream("/Playstatuses.json"), "UTF-8");
} catch (IOException e) {
LOG.log(Level.SEVERE, "Cannot load play statuses. Disabling playstatus handler.");
return;
}
this.random = new Random();
Gson gson = new Gson();
this.statuses = gson.fromJson(json, PlaystatusFile.class).getData();
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
Grimoire.getInstance().getDiscord().getPresence().setGame(Game.of(getRandomStatus()));
}
}, 0, CHANGE_INTERVAL);
}
示例11: execute
import net.dv8tion.jda.core.entities.Game; //導入依賴的package包/類
@Override
protected void execute(CommandEvent event)
{
String[] parts = event.getArgs().split("\\s+", 2);
if(parts.length<2)
{
event.replyError("Please include a twitch username and the name of the game to 'stream'");
return;
}
try
{
event.getJDA().getPresence().setGame(Game.streaming(parts[1], "https://twitch.tv/"+parts[0]));
event.replySuccess("**"+event.getSelfUser().getName()
+"** is now streaming `"+parts[1]+"`");
}
catch(Exception e)
{
event.reply(event.getClient().getError()+" The game could not be set!");
}
}
示例12: dispatch
import net.dv8tion.jda.core.entities.Game; //導入依賴的package包/類
@Override
public void dispatch(String[] args, MessageChannel channel, Message msg) {
if (args.length > 1 && args[0].toLowerCase().matches("(game)|(stream=.+)")) {
if (args[0].equalsIgnoreCase("game")) {
UserBot.getInstance().getJda().getPresence()
.setGame(Game.of(Arrays.stream(args).skip(1).collect(Collectors.joining(" "))));
msg.deleteMessage().queue();
} else {
Matcher m = GET_STREAM_URL_PATTERN.matcher(args[0]);
if (m.matches()) {
if (Game.isValidStreamingUrl(m.group(1))) {
UserBot.getInstance().getJda().getPresence()
.setGame(Game.of(Arrays.stream(args).skip(1).collect(Collectors.joining(" ")), m.group(1)));
msg.deleteMessage().queue();
} else {
UserBot.getInstance().getJda().getPresence()
.setGame(Game.of(Arrays.stream(args).skip(1).collect(Collectors.joining(" "))));
msg.deleteMessage().queue();
}
}
}
}
}
示例13: onReady
import net.dv8tion.jda.core.entities.Game; //導入依賴的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());
}
示例14: initJda
import net.dv8tion.jda.core.entities.Game; //導入依賴的package包/類
/**
* Starts JDA.
*
* @return {@code true} if everything went well, {@code false} otherwise.
*/
private boolean initJda() {
try {
SimpleLog.Level level = JDAImpl.LOG.getLevel();
SimpleLog.Level socketLevel = WebSocketClient.LOG.getLevel();
JDAImpl.LOG.setLevel(SimpleLog.Level.OFF);
WebSocketClient.LOG.setLevel(SimpleLog.Level.OFF);
jda = new JDABuilder(AccountType.BOT).setToken(botToken).buildBlocking();
jda.getPresence().setGame(Game.of("2.0.2"));
logger.writeFrom("jda", "Successfully connected!");
logger.writeFrom("jda WebSocket", "Connected to WebSocket!");
JDAImpl.LOG.setLevel(level);
WebSocketClient.LOG.setLevel(socketLevel);
} catch (LoginException | InterruptedException | RateLimitedException e) {
logger.writeFrom("jda", "Couldn't connect!");
e.printStackTrace();
return false;
}
return true;
}
示例15: setPresence
import net.dv8tion.jda.core.entities.Game; //導入依賴的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;
}