use of net.kodehawa.mantarobot.core.modules.commands.SubCommand in project MantaroBot by Mantaro.
the class PlayerCmds method profile.
@Subscribe
public void profile(CommandRegistry cr) {
ITreeCommand profileCommand = (TreeCommand) cr.register("profile", new TreeCommand(Category.CURRENCY) {
@Override
public Command defaultTrigger(GuildMessageReceivedEvent event, String mainCommand, String commandName) {
return new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
User userLooked = event.getAuthor();
Player player = MantaroData.db().getPlayer(userLooked);
UserData user = MantaroData.db().getUser(event.getMember()).getData();
Member memberLooked = event.getMember();
List<Member> found = FinderUtil.findMembers(content, event.getGuild());
if (found.isEmpty() && !content.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Didn't find any member with your search criteria :(").queue();
return;
}
if (found.size() > 1 && !content.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.THINKING + "Too many members found, maybe refine your search? (ex. use name#discriminator)\n" + "**Members found:** " + found.stream().map(m -> m.getUser().getName() + "#" + m.getUser().getDiscriminator()).collect(Collectors.joining(", "))).queue();
return;
}
if (found.size() == 1 && !content.isEmpty()) {
userLooked = found.get(0).getUser();
memberLooked = found.get(0);
if (userLooked.isBot()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Bots don't have profiles.").queue();
return;
}
user = MantaroData.db().getUser(userLooked).getData();
player = MantaroData.db().getPlayer(memberLooked);
}
User marriedTo = (player.getData().getMarriedWith() == null || player.getData().getMarriedWith().isEmpty()) ? null : MantaroBot.getInstance().getUserById(player.getData().getMarriedWith());
PlayerData playerData = player.getData();
Inventory inv = player.getInventory();
// start of badge assigning
Guild mh = MantaroBot.getInstance().getGuildById("213468583252983809");
Member mhMember = mh == null ? null : mh.getMemberById(memberLooked.getUser().getId());
boolean saveAfter = false;
if (player.getMoney() > 7526527671L && playerData.addBadgeIfAbsent(Badge.ALTERNATIVE_WORLD))
saveAfter = true;
if (MantaroData.config().get().isOwner(userLooked) && playerData.addBadgeIfAbsent(Badge.DEVELOPER))
saveAfter = true;
if (inv.asList().stream().anyMatch(stack -> stack.getAmount() == 5000) && playerData.addBadgeIfAbsent(Badge.SHOPPER))
saveAfter = true;
if (inv.asList().stream().anyMatch(stack -> stack.getItem().equals(Items.CHRISTMAS_TREE_SPECIAL) || stack.getItem().equals(Items.BELL_SPECIAL)) && playerData.addBadgeIfAbsent(Badge.CHRISTMAS))
saveAfter = true;
if (MantaroBot.getInstance().getShardedMantaro().getDiscordBotsUpvoters().contains(userLooked.getIdLong()) && playerData.addBadgeIfAbsent(Badge.UPVOTER))
saveAfter = true;
if (player.getLevel() >= 10 && playerData.addBadgeIfAbsent(Badge.WALKER))
saveAfter = true;
if (player.getLevel() >= 50 && playerData.addBadgeIfAbsent(Badge.RUNNER))
saveAfter = true;
if (player.getLevel() >= 100 && playerData.addBadgeIfAbsent(Badge.FAST_RUNNER))
saveAfter = true;
if (player.getLevel() >= 150 && playerData.addBadgeIfAbsent(Badge.MARATHON_RUNNER))
saveAfter = true;
if (player.getLevel() >= 200 && playerData.addBadgeIfAbsent(Badge.MARATHON_WINNER))
saveAfter = true;
if (playerData.getMarketUsed() > 1000 && playerData.addBadgeIfAbsent(Badge.COMPULSIVE_BUYER))
saveAfter = true;
if (mhMember != null && mhMember.getRoles().stream().anyMatch(r -> r.getIdLong() == 406920476259123201L) && playerData.addBadgeIfAbsent(Badge.HELPER_2))
saveAfter = true;
if (mhMember != null && mhMember.getRoles().stream().anyMatch(r -> r.getIdLong() == 290257037072531466L || r.getIdLong() == 290902183300431872L) && playerData.addBadgeIfAbsent(Badge.DONATOR_2))
saveAfter = true;
if (saveAfter)
player.saveAsync();
// end of badge assigning
List<Badge> badges = playerData.getBadges();
Collections.sort(badges);
String displayBadges = badges.stream().map(Badge::getUnicode).limit(5).collect(Collectors.joining(" "));
applyBadge(event.getChannel(), badges.isEmpty() ? null : (playerData.getMainBadge() == null ? badges.get(0) : playerData.getMainBadge()), userLooked, baseEmbed(event, (marriedTo == null || !player.getInventory().containsItem(Items.RING) ? "" : EmoteReference.RING) + memberLooked.getEffectiveName() + "'s Profile", userLooked.getEffectiveAvatarUrl()).setThumbnail(userLooked.getEffectiveAvatarUrl()).setDescription((player.getData().isShowBadge() ? (badges.isEmpty() ? "" : String.format("**%s**\n", (playerData.getMainBadge() == null ? badges.get(0) : playerData.getMainBadge()))) : "") + (player.getData().getDescription() == null ? "No description set" : player.getData().getDescription())).addField(EmoteReference.DOLLAR + "Credits", "$ " + player.getMoney(), true).addField(EmoteReference.ZAP + "Level", player.getLevel() + " (Experience: " + player.getData().getExperience() + ")", true).addField(EmoteReference.REP + "Reputation", String.valueOf(player.getReputation()), true).addField(EmoteReference.POPPER + "Birthday", user.getBirthday() != null ? user.getBirthday().substring(0, 5) : "Not specified.", true).addField(EmoteReference.HEART + "Married with", marriedTo == null ? "Nobody." : marriedTo.getName() + "#" + marriedTo.getDiscriminator(), false).addField(EmoteReference.POUCH + "Inventory", ItemStack.toString(inv.asList()), false).addField(EmoteReference.HEART + "Top 5 Badges", displayBadges.isEmpty() ? "No badges (yet!)" : displayBadges, false).setFooter("User's timezone: " + (user.getTimezone() == null ? "No timezone set." : user.getTimezone()) + " | " + "Requested by " + event.getAuthor().getName(), null));
}
};
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Profile command.").setDescription("**Retrieves your current user profile.**").addField("Usage", "- To retrieve your profile, `~>profile`\n" + "- To change your description do `~>profile description set <description>`\n" + " -- To clear it, just do `~>profile description clear`\n" + "- To set your timezone do `~>profile timezone <timezone>`\n" + "- To set your display badge use `~>profile displaybadge` and `~>profile displaybadge reset` to reset it.\n" + " -- You can also use `~>profile displaybadge none` to display no badge on your profile.\n" + "**The profile only shows the 5 most important badges!.** Use `~>badges` to get a complete list.", false).build();
}
});
profileCommand.addSubCommand("timezone", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
DBUser dbUser = MantaroData.db().getUser(event.getAuthor());
String[] args = content.split(" ");
if (args.length < 1) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify the timezone.").queue();
return;
}
String timezone = args[0];
if (timezone.equalsIgnoreCase("reset")) {
dbUser.getData().setTimezone(null);
dbUser.saveAsync();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Reset timezone.").queue();
return;
}
if (!Utils.isValidTimeZone(timezone)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Invalid timezone.").queue();
return;
}
try {
UtilsCmds.dateGMT(event.getGuild(), timezone);
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Not a valid timezone.").queue();
return;
}
dbUser.getData().setTimezone(timezone);
dbUser.saveAsync();
event.getChannel().sendMessage(String.format("%sSaved timezone, your profile timezone is now: **%s**", EmoteReference.CORRECT, timezone)).queue();
}
});
profileCommand.addSubCommand("description", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
String[] args = content.split(" ");
User author = event.getAuthor();
Player player = MantaroData.db().getPlayer(author);
if (args.length == 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to provide an argument! (set or remove)\n" + "for example, ~>profile description set Hi there!").queue();
return;
}
if (args[0].equals("set")) {
int MAX_LENGTH = 300;
if (MantaroData.db().getUser(author).isPremium())
MAX_LENGTH = 500;
String content1 = SPLIT_PATTERN.split(content, 2)[1];
if (content1.length() > MAX_LENGTH) {
event.getChannel().sendMessage(EmoteReference.ERROR + "The description is too long! `(Limit of 300 characters for everyone and 500 for premium users)`").queue();
return;
}
player.getData().setDescription(content1);
event.getChannel().sendMessage(EmoteReference.POPPER + "Set description to: **" + content1 + "**\n" + "Check your shiny new profile with `~>profile`").queue();
player.save();
return;
}
if (args[1].equals("clear")) {
player.getData().setDescription(null);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Successfully cleared description.").queue();
player.save();
}
}
});
profileCommand.addSubCommand("displaybadge", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
String[] args = content.split(" ");
if (args.length == 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify your main badge!").queue();
return;
}
Player player = MantaroData.db().getPlayer(event.getAuthor());
PlayerData data = player.getData();
if (args[0].equalsIgnoreCase("none")) {
data.setShowBadge(false);
event.getChannel().sendMessage(EmoteReference.CORRECT + "No badge will show on the top of your profile now!").queue();
player.saveAsync();
return;
}
if (args[0].equalsIgnoreCase("reset")) {
data.setMainBadge(null);
data.setShowBadge(true);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Your display badge is now the most important one.").queue();
player.saveAsync();
return;
}
Badge badge = Badge.lookupFromString(content);
if (badge == null) {
event.getChannel().sendMessage(EmoteReference.ERROR + "There's no such badge...\n" + "Your available badges: " + player.getData().getBadges().stream().map(Badge::getDisplay).collect(Collectors.joining(", "))).queue();
return;
}
if (!data.getBadges().contains(badge)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You don't have that badge.\n" + "Your available badges: " + player.getData().getBadges().stream().map(Badge::getDisplay).collect(Collectors.joining(", "))).queue();
return;
}
data.setShowBadge(true);
data.setMainBadge(badge);
player.saveAsync();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Your display badge is now: **" + badge.display + "**").queue();
}
});
}
use of net.kodehawa.mantarobot.core.modules.commands.SubCommand in project MantaroBot by Mantaro.
the class CurrencyCmds method market.
@Subscribe
public void market(CommandRegistry cr) {
final RateLimiter rateLimiter = new RateLimiter(TimeUnit.SECONDS, 8);
TreeCommand marketCommand = (TreeCommand) cr.register("market", new TreeCommand(Category.CURRENCY) {
@Override
public Command defaultTrigger(GuildMessageReceivedEvent event, String mainCommand, String commandName) {
return new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
EmbedBuilder embed = baseEmbed(event, "Mantaro's Market").setThumbnail("https://png.icons8.com/metro/540/shopping-cart.png");
List<MessageEmbed.Field> fields = new LinkedList<>();
Stream.of(Items.ALL).forEach(item -> {
if (!item.isHidden()) {
String buyValue = item.isBuyable() ? String.format("$%d", item.getValue()) : "N/A";
String sellValue = item.isSellable() ? String.format("$%d", (int) Math.floor(item.getValue() * 0.9)) : "N/A";
fields.add(new MessageEmbed.Field(String.format("%s %s", item.getEmoji(), item.getName()), EmoteReference.BUY + buyValue + " " + EmoteReference.SELL + sellValue, true));
}
});
List<List<MessageEmbed.Field>> splitFields = DiscordUtils.divideFields(8, fields);
boolean hasReactionPerms = event.getGuild().getSelfMember().hasPermission(event.getChannel(), Permission.MESSAGE_ADD_REACTION);
if (hasReactionPerms) {
DiscordUtils.list(event, 120, false, embed, splitFields);
} else {
DiscordUtils.listText(event, 120, false, embed, splitFields);
}
}
};
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Mantaro's market").setDescription("**List current items for buying and selling.**").addField("Buying and selling", "To buy do ~>market buy <item emoji>. It will subtract the value from your money" + " and give you the item.\n" + "To sell do `~>market sell all` to sell all your items or `~>market sell <item emoji>` to sell the specified item. " + "**You'll get the sell value of the item on coins to spend.**\n" + "You can check the value of a single item using `~>market price <item emoji>`\n" + "You can send an item to the trash using `~>market dump <amount> <item emoji>`\n" + "Use `~>inventory -calculate` to check how much is your inventory worth.", false).addField("To know", "If you don't have enough money you cannot buy the items.\n" + "Note: Don't use the item id, it's just for aesthetic reasons, the internal IDs are different than the ones shown here!", false).addField("Information", "To buy and sell multiple items you need to do `~>market <buy/sell> <amount> <item>`", false).build();
}
});
marketCommand.setPredicate((event) -> {
if (!handleDefaultRatelimit(rateLimiter, event.getAuthor(), event))
return false;
Player player = MantaroData.db().getPlayer(event.getMember());
if (player.isLocked()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot access the market now.").queue();
return false;
}
return true;
});
marketCommand.addSubCommand("dump", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
String[] args = content.split(" ");
String itemName = content;
int itemNumber = 1;
boolean isMassive = !itemName.isEmpty() && itemName.split(" ")[0].matches("^[0-9]*$");
if (isMassive) {
try {
itemNumber = Math.abs(Integer.valueOf(itemName.split(" ")[0]));
itemName = itemName.replace(args[0], "").trim();
} catch (NumberFormatException e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Not a valid number of items to dump.").queue();
return;
} catch (Exception e) {
onHelp(event);
return;
}
}
Item item = Items.fromAny(itemName).orElse(null);
if (item == null) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Cannot check the dump a non-existent item!").queue();
return;
}
Player player = MantaroData.db().getPlayer(event.getAuthor());
if (!player.getInventory().containsItem(item)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Cannot dump an item you don't have!").queue();
return;
}
if (player.getInventory().getAmount(item) < itemNumber) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot dump more items than what you have.").queue();
return;
}
player.getInventory().process(new ItemStack(item, -itemNumber));
player.saveAsync();
event.getChannel().sendMessage(String.format("%sSent %dx **%s %s** to the trash!", EmoteReference.CORRECT, itemNumber, item.getEmoji(), item.getName())).queue();
}
}).createSubCommandAlias("dump", "trash");
marketCommand.addSubCommand("price", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
String[] args = content.split(" ");
String itemName = content.replace(args[0] + " ", "");
Item item = Items.fromAny(itemName).orElse(null);
if (item == null) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Cannot check the price of a non-existent item!").queue();
return;
}
if (!item.isBuyable() && !item.isSellable()) {
event.getChannel().sendMessage(EmoteReference.THINKING + "This item is not available neither for sell or buy (could be an exclusive collectible)").queue();
return;
}
if (!item.isBuyable()) {
event.getChannel().sendMessage(EmoteReference.EYES + "This is a collectible item. (Sell value: " + ((int) (item.getValue() * 0.9)) + " credits)").queue();
return;
}
event.getChannel().sendMessage(String.format("%sThe market value of %s**%s** is %s credits to buy it and you can get %s credits if you sell it.", EmoteReference.MARKET, item.getEmoji(), item.getName(), item.getValue(), (int) (item.getValue() * 0.9))).queue();
}
});
marketCommand.addSubCommand("sell", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
Player player = MantaroData.db().getPlayer(event.getMember());
String[] args = content.split(" ");
String itemName = content;
int itemNumber = 1;
boolean isMassive = !itemName.isEmpty() && itemName.split(" ")[0].matches("^[0-9]*$");
if (isMassive) {
try {
itemNumber = Math.abs(Integer.valueOf(itemName.split(" ")[0]));
itemName = itemName.replace(args[0], "").trim();
} catch (NumberFormatException e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Not a valid number of items to buy.").queue();
return;
} catch (Exception e) {
onHelp(event);
return;
}
}
try {
if (args[0].equals("all")) {
long all = player.getInventory().asList().stream().filter(item -> item.getItem().isSellable()).mapToLong(value -> (long) (value.getItem().getValue() * value.getAmount() * 0.9d)).sum();
player.getInventory().clearOnlySellables();
player.addMoney(all);
event.getChannel().sendMessage(String.format("%sYou sold all your inventory items and gained %d credits!", EmoteReference.MONEY, all)).queue();
player.saveAsync();
return;
}
Item toSell = Items.fromAny(itemName).orElse(null);
if (toSell == null) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot sell a non-existant item.").queue();
return;
}
if (!toSell.isSellable()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot sell an item that cannot be sold.").queue();
return;
}
if (player.getInventory().getAmount(toSell) < 1) {
event.getChannel().sendMessage(EmoteReference.STOP + "You cannot sell an item you don't have.").queue();
return;
}
if (player.getInventory().getAmount(toSell) < itemNumber) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot sell more items than what you have.").queue();
return;
}
int many = itemNumber * -1;
long amount = Math.round((toSell.getValue() * 0.9)) * Math.abs(many);
player.getInventory().process(new ItemStack(toSell, many));
player.addMoney(amount);
player.getData().setMarketUsed(player.getData().getMarketUsed() + 1);
event.getChannel().sendMessage(String.format("%sYou sold %d **%s** and gained %d credits!", EmoteReference.CORRECT, Math.abs(many), toSell.getName(), amount)).queue();
player.saveAsync();
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Invalid syntax.").queue();
}
}
});
marketCommand.addSubCommand("buy", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
Player player = MantaroData.db().getPlayer(event.getMember());
String[] args = content.split(" ");
String itemName = content;
int itemNumber = 1;
boolean isMassive = !itemName.isEmpty() && itemName.split(" ")[0].matches("^[0-9]*$");
if (isMassive) {
try {
itemNumber = Math.abs(Integer.valueOf(itemName.split(" ")[0]));
itemName = itemName.replace(args[0], "").trim();
} catch (Exception e) {
if (e instanceof NumberFormatException) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Not a valid number of items to buy.").queue();
} else {
onHelp(event);
return;
}
}
}
Item itemToBuy = Items.fromAnyNoId(itemName).orElse(null);
if (itemToBuy == null) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot buy an unexistant item.").queue();
return;
}
try {
if (!itemToBuy.isBuyable()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot buy an item that cannot be bought.").queue();
return;
}
ItemStack stack = player.getInventory().getStackOf(itemToBuy);
if (stack != null && !stack.canJoin(new ItemStack(itemToBuy, itemNumber))) {
// assume overflow
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot buy more of that object!").queue();
return;
}
if (player.removeMoney(itemToBuy.getValue() * itemNumber)) {
player.getInventory().process(new ItemStack(itemToBuy, itemNumber));
player.getData().addBadgeIfAbsent(Badge.BUYER);
player.getData().setMarketUsed(player.getData().getMarketUsed() + 1);
player.saveAsync();
event.getChannel().sendMessage(String.format("%sBought %d %s for %d credits successfully. You now have %d credits.", EmoteReference.OK, itemNumber, itemToBuy.getEmoji(), itemToBuy.getValue() * itemNumber, player.getMoney())).queue();
} else {
event.getChannel().sendMessage(EmoteReference.STOP + "You don't have enough money to buy this item.").queue();
}
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Invalid syntax.").queue();
}
}
});
}
use of net.kodehawa.mantarobot.core.modules.commands.SubCommand in project MantaroBot by Mantaro.
the class InfoCmds method about.
@Subscribe
public void about(CommandRegistry cr) {
TreeCommand aboutCommand = (TreeCommand) cr.register("about", new TreeCommand(Category.INFO) {
@Override
public Command defaultTrigger(GuildMessageReceivedEvent event, String thisCommand, String attemptedSubCommand) {
return new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
SnowflakeCacheView<Guild> guilds = MantaroBot.getInstance().getGuildCache();
SnowflakeCacheView<User> users = MantaroBot.getInstance().getUserCache();
SnowflakeCacheView<TextChannel> textChannels = MantaroBot.getInstance().getTextChannelCache();
SnowflakeCacheView<VoiceChannel> voiceChannels = MantaroBot.getInstance().getVoiceChannelCache();
event.getChannel().sendMessage(new EmbedBuilder().setColor(Color.PINK).setAuthor("About Mantaro", "http://is.gd/mantaro", event.getJDA().getSelfUser().getEffectiveAvatarUrl()).setThumbnail(event.getJDA().getSelfUser().getEffectiveAvatarUrl()).setDescription("Hello, I'm **MantaroBot**! I'm here to make your life a little easier. To get started, type `~>help`!\n" + "Some of my features include:\n" + "\u2713 **Moderation made easy** (``Mass kick/ban, prune commands, logs and more!``)\n" + "\u2713 **Funny and useful commands**, see `~>help anime` or `~>help hug` for examples.\n" + "\u2713 **First quality music**, check out `~>help play` for example!.\n" + "\u2713 **[Support server](https://discordapp.com/invite/cMTmuPa)! |" + " [Support Mantaro development!](https://www.patreon.com/mantaro)**\n\n" + EmoteReference.POPPER + "Check ~>about credits!" + (MantaroData.config().get().isPremiumBot() ? "\nRunning a Patreon Bot instance, thanks you for your support! \u2764" : "")).addField("MantaroBot Version", MantaroInfo.VERSION, false).addField("Uptime", Utils.getHumanizedTime(ManagementFactory.getRuntimeMXBean().getUptime()), false).addField("Shards", String.valueOf(MantaroBot.getInstance().getShardedMantaro().getTotalShards()), true).addField("Threads", String.format("%,d", Thread.activeCount()), true).addField("Servers", String.format("%,d", guilds.size()), true).addField("Users (Unique)", String.format("%,d", users.stream().mapToLong(ISnowflake::getIdLong).distinct().count()), true).addField("Text Channels", String.format("%,d", textChannels.size()), true).addField("Voice Channels", String.format("%,d", voiceChannels.size()), true).setFooter(String.format("Invite link: http://is.gd/mantaro (Commands this session: %,d | Current shard: %d)", CommandListener.getCommandTotalInt(), MantaroBot.getInstance().getShardForGuild(event.getGuild().getId()).getId() + 1), event.getJDA().getSelfUser().getEffectiveAvatarUrl()).build()).queue();
}
};
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "About Command").setDescription("**Read info about Mantaro!**").addField("Information", "`~>about credits` - **Lists everyone who has helped on the bot's development**, " + "`~>about patreon` - **Lists our patreon supporters**", false).setColor(Color.PINK).build();
}
});
aboutCommand.addSubCommand("patreon", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
Guild mantaroGuild = MantaroBot.getInstance().getGuildById("213468583252983809");
String donators = mantaroGuild.getMembers().stream().filter(member -> member.getRoles().stream().filter(role -> role.getName().equals("Patron")).collect(Collectors.toList()).size() > 0).map(Member::getUser).map(user -> String.format("%s#%s", user.getName(), user.getDiscriminator())).collect(Collectors.joining("\n"));
boolean hasReactionPerms = event.getGuild().getSelfMember().hasPermission(event.getChannel(), Permission.MESSAGE_ADD_REACTION);
List<String> donatorList = DiscordUtils.divideString(300, donators);
List<String> messages = new LinkedList<>();
for (String s1 : donatorList) {
messages.add("**Mantaro's Patreon Pledgers**\n" + (hasReactionPerms ? "Use the arrow reactions to change pages. " : "Use &page >> and &page << to change pages and &cancel to end") + String.format("```%s```", s1));
}
messages.add("Thanks to **MrLar#8117** for a $1025 donation and many other people who has donated once via paypal.");
if (hasReactionPerms) {
DiscordUtils.list(event, 45, false, messages);
} else {
DiscordUtils.listText(event, 45, false, messages);
}
}
});
aboutCommand.addSubCommand("credits", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
EmbedBuilder builder = new EmbedBuilder();
builder.setAuthor("Credits.", null, event.getJDA().getSelfUser().getEffectiveAvatarUrl()).setColor(Color.BLUE).setDescription(String.join("\n", "**Main developer**: Kodehawa#3457", "**Developer**: AdrianTodt#0722", "**Developer**: Natan#1289", "**Documentation**: MrLar#8117 & Yuvira#7832", "**Community Admin**: MrLar#8117", "**Grammar Nazi**: Desiree#3658")).addField("Special mentions", "Thanks to bots.discord.pw, Carbonitex and discordbots.org for helping us with increasing the bot's visibility.", false).setFooter("Much thanks to everyone above for helping make Mantaro better!", event.getJDA().getSelfUser().getEffectiveAvatarUrl());
event.getChannel().sendMessage(builder.build()).queue();
}
});
}
use of net.kodehawa.mantarobot.core.modules.commands.SubCommand in project MantaroBot by Mantaro.
the class MiscCmds method misc.
@Subscribe
public void misc(CommandRegistry cr) {
ITreeCommand miscCommand = (ITreeCommand) cr.register("misc", new SimpleTreeCommand(Category.MISC) {
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Misc Commands").setDescription("**Miscellaneous funny/useful commands.**").addField("Usage", "`~>misc reverse <sentence>` - **Reverses any given sentence.**\n" + "`~>misc rndcolor` - **Gives you a random hex color.**\n", false).addField("Parameter Explanation", "`sentence` - **A sentence to reverse.**\n" + "`@user` - **A user to mention.**", false).build();
}
}.addSubCommand("reverse", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
if (content.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You didn't provide any message to reverse!").queue();
return;
}
new MessageBuilder().append(new StringBuilder(content).reverse().toString()).stripMentions(event.getGuild(), Message.MentionType.EVERYONE, Message.MentionType.HERE).sendTo(event.getChannel()).queue();
}
}).addSubCommand("rndcolor", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
event.getChannel().sendMessage(String.format(EmoteReference.TALKING + "The random color is %s", randomColor())).queue();
}
}));
miscCommand.createSubCommandAlias("rndcolor", "randomcolor");
}
Aggregations