当前位置: 首页>>代码示例>>Java>>正文


Java OnlineStatus.fromKey方法代码示例

本文整理汇总了Java中net.dv8tion.jda.core.OnlineStatus.fromKey方法的典型用法代码示例。如果您正苦于以下问题:Java OnlineStatus.fromKey方法的具体用法?Java OnlineStatus.fromKey怎么用?Java OnlineStatus.fromKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.dv8tion.jda.core.OnlineStatus的用法示例。


在下文中一共展示了OnlineStatus.fromKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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!");
    }
}
 
开发者ID:jagrosh,项目名称:MusicBot,代码行数:18,代码来源:SetstatusCmd.java

示例2: Member

import net.dv8tion.jda.core.OnlineStatus; //导入方法依赖的package包/类
private Member(JSONObject json, Widget widget)
{
    this.widget = widget;
    this.bot = Helpers.optBoolean(json, "bot");
    this.id = json.getLong("id");
    this.username = json.getString("username");
    this.discriminator = json.getString("discriminator");
    this.avatar = json.optString("avatar", null);
    this.nickname = json.optString("nick", null);
    this.status = OnlineStatus.fromKey(json.getString("status"));
    this.game = json.isNull("game") ? null : EntityBuilder.createGame(json.getJSONObject("game"));
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:13,代码来源:WidgetUtil.java

示例3: Config

import net.dv8tion.jda.core.OnlineStatus; //导入方法依赖的package包/类
public Config() throws Exception
{
    List<String> lines = Files.readAllLines(Paths.get("config.txt"));
    for(String str : lines)
    {
        String[] parts = str.split("=",2);
        String key = parts[0].trim().toLowerCase();
        String value = parts.length>1 ? parts[1].trim() : null;
        switch(key) 
        {
            case "token":
                userToken = value;
                break;
            case "prefix":
                if(value==null)
                {
                    prefix = "";
                    LOG.warn("The prefix was defined as empty!");
                }
                else
                    prefix = value;
                break;
            case "timezone":
                if(value==null)
                {
                    zone = ZoneId.systemDefault();
                    LOG.warn("An empty timezone was provided; using the system default!");
                }
                else
                {
                    try {
                        zone = ZoneId.of(value);
                    } catch(Exception e) {
                        zone = ZoneId.systemDefault();
                        LOG.warn("\""+value+"\" is not a valid timezone; using the system default!");
                    }
                }
                break;
            case "status":
                status = OnlineStatus.fromKey(value);
                if(status == OnlineStatus.UNKNOWN)
                {
                    status = OnlineStatus.IDLE;
                    LOG.warn("\""+value+"\" is not a valid status; using the default IDLE! Valid statuses are ONLINE, IDLE, DND, and INVISIBLE.");
                }
                break;
            case "bot":
                bot = "true".equalsIgnoreCase(value);
        }
    }
    if(userToken==null)
        throw new Exception("No token provided int he config file!");
    if(prefix==null)
        throw new Exception("No prefix provided in the config file!");
    if(zone==null)
    {
        zone = ZoneId.systemDefault();
        LOG.warn("No timezone provided; using the system default!");
    }
    if(status==null)
    {
        status = OnlineStatus.IDLE;
        LOG.warn("No status provided; using IDLE!");
    }
}
 
开发者ID:jagrosh,项目名称:Selfbot,代码行数:66,代码来源:Config.java

示例4: createPresence

import net.dv8tion.jda.core.OnlineStatus; //导入方法依赖的package包/类
public void createPresence(Object memberOrFriend, JSONObject presenceJson)
{
    if (memberOrFriend == null)
        throw new NullPointerException("Provided memberOrFriend was null!");

    JSONObject gameJson = presenceJson.isNull("game") ? null : presenceJson.getJSONObject("game");
    OnlineStatus onlineStatus = OnlineStatus.fromKey(presenceJson.getString("status"));
    Game game = null;
    boolean parsedGame = false;

    if (gameJson != null && !gameJson.isNull("name"))
    {
        try
        {
            game = createGame(gameJson);
            parsedGame = true;
        }
        catch (Exception ex)
        {
            String userId;
            if (memberOrFriend instanceof Member)
                userId = ((Member) memberOrFriend).getUser().getId();
            else if (memberOrFriend instanceof Friend)
                userId = ((Friend) memberOrFriend).getUser().getId();
            else
                userId = "unknown";
            if (LOG.isDebugEnabled())
                LOG.warn("Encountered exception trying to parse a presence! UserId: {} JSON: {}", userId, gameJson, ex);
            else
                LOG.warn("Encountered exception trying to parse a presence! UserId: {} Message: {} Enable debug for details", userId, ex.getMessage());
        }
    }
    if (memberOrFriend instanceof Member)
    {
        MemberImpl member = (MemberImpl) memberOrFriend;
        member.setOnlineStatus(onlineStatus);
        if (parsedGame)
            member.setGame(game);
    }
    else if (memberOrFriend instanceof Friend)
    {
        FriendImpl friend = (FriendImpl) memberOrFriend;
        friend.setOnlineStatus(onlineStatus);
        if (parsedGame)
            friend.setGame(game);

        OffsetDateTime lastModified = OffsetDateTime.ofInstant(
                Instant.ofEpochMilli(presenceJson.getLong("last_modified")),
                TimeZone.getTimeZone("GMT").toZoneId());

        friend.setOnlineStatusModifiedTime(lastModified);
    }
    else
        throw new IllegalArgumentException("An object was provided to EntityBuilder#createPresence that wasn't a Member or Friend. JSON: " + presenceJson);
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:56,代码来源:EntityBuilder.java


注:本文中的net.dv8tion.jda.core.OnlineStatus.fromKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。