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());
}
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());
}
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());
}
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());
}
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;
}
Aggregations