Search in sources :

Example 1 with UserData

use of com.discordbolt.boltbot.system.mysql.data.persistent.UserData in project BoltBot by DiscordBolt.

the class SeenModule method seenCommand.

@BotCommand(command = "seen", module = "Seen Module", description = "See when the user was last online.", usage = "Seen [User]", minArgs = 2, maxArgs = 100)
public static void seenCommand(CommandContext cc) throws CommandException {
    IUser searchUser = UserUtil.findUser(cc.getMessage(), cc.getMessageContent().indexOf(' ') + 1);
    String name = cc.getMessageContent().substring(cc.getMessageContent().indexOf(' ') + 1, cc.getMessageContent().length());
    if (searchUser == null)
        throw new CommandArgumentException("Sorry, I could not find '" + name + "'.");
    Optional<UserData> userData = UserData.getById(searchUser.getLongID());
    if (!userData.isPresent() || userData.get().getLastStatusChange() == null)
        throw new CommandArgumentException("Sorry, I could not find \"" + name + "\".");
    cc.replyWith(searchUser.getName() + " has been " + userData.get().getStatus().name().replace("dnd", "do not disturb").toLowerCase() + " since " + format(userData.get().getLastStatusChange()) + '.');
}
Also used : UserData(com.discordbolt.boltbot.system.mysql.data.persistent.UserData) IUser(sx.blah.discord.handle.obj.IUser) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) BotCommand(com.discordbolt.api.command.BotCommand)

Aggregations

BotCommand (com.discordbolt.api.command.BotCommand)1 CommandArgumentException (com.discordbolt.api.command.exceptions.CommandArgumentException)1 UserData (com.discordbolt.boltbot.system.mysql.data.persistent.UserData)1 IUser (sx.blah.discord.handle.obj.IUser)1