Search in sources :

Example 61 with IUser

use of sx.blah.discord.handle.obj.IUser in project Shadbot by Shadorc.

the class InfoCmd method execute.

@Override
public void execute(Context context) {
    long ping = TimeUtils.getMillisUntil(context.getMessage().getCreationDate());
    long uptime = TimeUtils.getMillisUntil(Discord4J.getLaunchTime());
    Runtime runtime = Runtime.getRuntime();
    int mbUnit = 1024 * 1024;
    long usedMemory = (runtime.totalMemory() - runtime.freeMemory()) / mbUnit;
    long maxMemory = runtime.maxMemory() / mbUnit;
    IUser owner = context.getClient().getApplicationOwner();
    String info = new String("```prolog" + String.format("%n-= Performance Info =-") + String.format("%nMemory: %s/%s MB", FormatUtils.formatNum(usedMemory), FormatUtils.formatNum(maxMemory)) + String.format("%nCPU Usage: %.1f%%", Utils.getProcessCpuLoad()) + String.format("%nThreads Count: %s", FormatUtils.formatNum(Thread.activeCount())) + String.format("%n%n-= APIs Info =-") + String.format("%nJava Version: %s", System.getProperty("java.version")) + String.format("%n%s Version: %s", Discord4J.NAME, Discord4J.VERSION) + String.format("%nLavaPlayer Version: %s", PlayerLibrary.VERSION) + String.format("%n%n-= Shadbot Info =-") + String.format("%nUptime: %s", DurationFormatUtils.formatDuration(uptime, "d 'days,' HH 'hours and' mm 'minutes'", true)) + String.format("%nDeveloper: %s#%s", owner.getName(), owner.getDiscriminator()) + String.format("%nShadbot Version: %s", Shadbot.VERSION) + String.format("%nShard: %d/%d", context.getShadbotShard().getID() + 1, context.getClient().getShardCount()) + String.format("%nServers: %s", FormatUtils.formatNum(context.getClient().getGuilds().size())) + String.format("%nVoice Channels: %d", context.getClient().getConnectedVoiceChannels().size()) + String.format("%nUsers: %s", FormatUtils.formatNum(context.getClient().getUsers().size())) + String.format("%nPing: %dms", ping) + "```");
    BotUtils.sendMessage(info, context.getChannel());
}
Also used : IUser(sx.blah.discord.handle.obj.IUser)

Example 62 with IUser

use of sx.blah.discord.handle.obj.IUser in project Shadbot by Shadorc.

the class TransferCoinsCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    if (!context.hasArg()) {
        throw new MissingArgumentException();
    }
    if (context.getMessage().getMentions().isEmpty()) {
        throw new MissingArgumentException();
    }
    List<String> splitCmd = StringUtils.split(context.getArg(), 2);
    if (splitCmd.size() != 2) {
        throw new MissingArgumentException();
    }
    IUser receiverUser = context.getMessage().getMentions().get(0);
    IUser senderUser = context.getAuthor();
    if (receiverUser.equals(senderUser)) {
        throw new IllegalCmdArgumentException("You cannot transfer coins to yourself.");
    }
    Integer coins = CastUtils.asPositiveInt(splitCmd.get(0));
    if (coins == null) {
        throw new IllegalCmdArgumentException(String.format("`%s` is not a valid amount for coins.", splitCmd.get(0)));
    }
    if (Database.getDBUser(context.getGuild(), senderUser).getCoins() < coins) {
        BotUtils.sendMessage(TextUtils.notEnoughCoins(context.getAuthor()), context.getChannel());
        return;
    }
    if (Database.getDBUser(context.getGuild(), receiverUser).getCoins() + coins >= Config.MAX_COINS) {
        BotUtils.sendMessage(String.format(Emoji.BANK + " This transfer cannot be done because %s would exceed the maximum coins cap.", receiverUser.getName()), context.getChannel());
        return;
    }
    Database.getDBUser(context.getGuild(), senderUser).addCoins(-coins);
    Database.getDBUser(context.getGuild(), receiverUser).addCoins(coins);
    BotUtils.sendMessage(String.format(Emoji.BANK + " %s has transfered **%s** to %s", senderUser.mention(), FormatUtils.formatCoins(coins), receiverUser.mention()), context.getChannel());
}
Also used : IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) IUser(sx.blah.discord.handle.obj.IUser)

Example 63 with IUser

use of sx.blah.discord.handle.obj.IUser in project Shadbot by Shadorc.

the class SendMessageCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    if (!context.hasArg()) {
        throw new MissingArgumentException();
    }
    List<String> splitArgs = StringUtils.split(context.getArg(), 2);
    if (splitArgs.size() != 2) {
        throw new MissingArgumentException();
    }
    Long userID = CastUtils.asPositiveLong(splitArgs.get(0));
    if (userID == null) {
        throw new IllegalCmdArgumentException(String.format("`%s` is not a valid user ID.", splitArgs.get(0)));
    }
    IUser user = Shadbot.getClient().getUserByID(userID);
    if (user == null) {
        BotUtils.sendMessage(Emoji.GREY_EXCLAMATION + " User not found.", context.getChannel());
        return;
    }
    if (user.equals(context.getOurUser())) {
        throw new IllegalCmdArgumentException("I can't send a private message to myself.");
    }
    if (user.isBot()) {
        throw new IllegalCmdArgumentException("I can't send private message to other bots.");
    }
    context.getClient().getOrCreatePMChannel(user).sendMessage(splitArgs.get(1));
    BotUtils.sendMessage(Emoji.CHECK_MARK + " Message sent.", context.getChannel());
}
Also used : IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) IUser(sx.blah.discord.handle.obj.IUser)

Example 64 with IUser

use of sx.blah.discord.handle.obj.IUser in project Shadbot by Shadorc.

the class LeaderboardCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException {
    Map<String, Integer> unsortedUsersMap = new HashMap<>();
    for (DBUser dbUser : Database.getDBGuild(context.getGuild()).getUsers()) {
        int userCoin = dbUser.getCoins();
        if (userCoin > 0) {
            IUser user = context.getGuild().getUserByID(dbUser.getUserID());
            if (user != null) {
                unsortedUsersMap.put(user.getName(), userCoin);
            }
        }
    }
    Map<String, Integer> sortedUsersMap = Utils.sortByValue(unsortedUsersMap);
    List<String> usersList = new ArrayList<>(sortedUsersMap.keySet());
    String leaderboard = FormatUtils.numberedList(10, sortedUsersMap.size(), count -> String.format("%d. **%s** - %s", count, usersList.get(count - 1), FormatUtils.formatCoins(sortedUsersMap.get(usersList.get(count - 1)))));
    unsortedUsersMap.clear();
    sortedUsersMap.clear();
    if (leaderboard.isEmpty()) {
        leaderboard = "\nEveryone is poor here.";
    }
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName("Leaderboard").appendDescription(leaderboard);
    BotUtils.sendMessage(embed.build(), context.getChannel());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IUser(sx.blah.discord.handle.obj.IUser) DBUser(me.shadorc.shadbot.data.db.DBUser)

Example 65 with IUser

use of sx.blah.discord.handle.obj.IUser in project Shadbot by Shadorc.

the class AbstractGameManager method isCancelCmd.

public final boolean isCancelCmd(IMessage message) {
    IUser user = message.getAuthor();
    if (message.getContent().equals(this.getPrefix() + "cancel") && (author.equals(user) || PermissionUtils.hasPermissions(channel, user, Permissions.ADMINISTRATOR))) {
        BotUtils.sendMessage(String.format(Emoji.CHECK_MARK + " Game cancelled by **%s**.", user.getName()), channel);
        this.stop();
        return true;
    }
    return false;
}
Also used : IUser(sx.blah.discord.handle.obj.IUser)

Aggregations

IUser (sx.blah.discord.handle.obj.IUser)67 ArrayList (java.util.ArrayList)15 IGuild (sx.blah.discord.handle.obj.IGuild)13 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)13 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)9 IMessage (sx.blah.discord.handle.obj.IMessage)9 IRole (sx.blah.discord.handle.obj.IRole)8 List (java.util.List)7 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)7 IllegalCmdArgumentException (me.shadorc.shadbot.exception.IllegalCmdArgumentException)6 IChannel (sx.blah.discord.handle.obj.IChannel)6 HashMap (java.util.HashMap)5 CCommandObject (com.github.vaerys.objects.CCommandObject)4 AbstractCommand (me.shadorc.shadbot.core.command.AbstractCommand)4 CommandCategory (me.shadorc.shadbot.core.command.CommandCategory)4 Context (me.shadorc.shadbot.core.command.Context)4 Command (me.shadorc.shadbot.core.command.annotation.Command)4 BotUtils (me.shadorc.shadbot.utils.BotUtils)4 FormatUtils (me.shadorc.shadbot.utils.FormatUtils)4 TextUtils (me.shadorc.shadbot.utils.TextUtils)4