use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class FunCmds method coinflip.
@Subscribe
public void coinflip(CommandRegistry cr) {
cr.register("coinflip", new SimpleCommand(Category.FUN) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
int times;
if (args.length == 0 || content.length() == 0)
times = 1;
else {
try {
times = Integer.parseInt(args[0]);
if (times > 1000) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Hold in there! The limit is 1,000 coin flips").queue();
return;
}
} catch (NumberFormatException nfe) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify an Integer for the amount of repetitions").queue();
return;
}
}
final int[] heads = { 0 };
final int[] tails = { 0 };
doTimes(times, () -> {
if (r.nextBoolean())
heads[0]++;
else
tails[0]++;
});
String flips = times == 1 ? "time" : "times";
event.getChannel().sendMessage(String.format("%s Your result from **%d** %s yielded **%d** heads and **%d** tails", EmoteReference.PENNY, times, flips, heads[0], tails[0])).queue();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Coinflip command").setDescription("**Flips a coin with a defined number of repetitions**").addField("Usage", "`~>coinflip <number of times>` - **Flips a coin x number of times**", false).build();
}
});
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class InfoCmds method tips.
@Subscribe
public void tips(CommandRegistry cr) {
final List<String> tips = new SimpleFileDataManager("assets/mantaro/texts/tips.txt").get();
final Random r = new Random();
cr.register("tips", new SimpleCommand(Category.INFO) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
event.getChannel().sendMessage(EmoteReference.TALKING + "Tip: " + tips.get(r.nextInt(tips.size()))).queue();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Tips Command").setDescription("**Shows tips about the bot!**").build();
}
});
cr.registerAlias("tips", "bottips");
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class InfoCmds method help.
@Subscribe
public void help(CommandRegistry cr) {
Random r = new Random();
List<String> jokes = Collections.unmodifiableList(Arrays.asList("Yo damn I heard you like help, because you just issued the help command to get the help about the help command.", "Congratulations, you managed to use the help command.", "Helps you to help yourself.", "Help Inception.", "A help helping helping helping help.", "I wonder if this is what you are looking for..."));
cr.register("help", new SimpleCommand(Category.INFO) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (content.isEmpty()) {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
String defaultPrefix = MantaroData.config().get().prefix[0], guildPrefix = dbGuild.getData().getGuildCustomPrefix();
String prefix = guildPrefix == null ? defaultPrefix : guildPrefix;
GuildData guildData = dbGuild.getData();
EmbedBuilder embed = baseEmbed(event, "Mantaro Help").setColor(Color.PINK).setDescription("Command list. For a detailed guide on the usage of Mantaro, please check the [wiki](https://github.com/Mantaro/MantaroBot/wiki).\n" + "If you have issues or inquiries while using Mantaro, please join the [support server](https://is.gd/mantaroguild)\n" + "[We need your help to keep Mantaro online! Click here for more info.](https://www.patreon.com/mantaro)\n" + (guildData.getDisabledCommands().isEmpty() ? "" : "\nOnly showing non-disabled commands. Total disabled commands: " + guildData.getDisabledCommands().size()) + (guildData.getChannelSpecificDisabledCommands().get(event.getChannel().getId()) == null || guildData.getChannelSpecificDisabledCommands().get(event.getChannel().getId()).isEmpty() ? "" : "\nOnly showing non-disabled commands. Total channel-specific disabled commands: " + guildData.getChannelSpecificDisabledCommands().get(event.getChannel().getId()).size())).setFooter(String.format("To check command usage, type %shelp <command> // -> Commands: " + DefaultCommandProcessor.REGISTRY.commands().values().stream().filter(c -> c.category() != null).count(), prefix), null);
Arrays.stream(Category.values()).filter(c -> c != Category.CURRENCY || !MantaroData.config().get().isPremiumBot()).filter(c -> c != Category.OWNER || CommandPermission.OWNER.test(event.getMember())).forEach(c -> embed.addField(c + " Commands:", forType(event.getChannel(), guildData, c), false));
event.getChannel().sendMessage(embed.build()).queue();
} else {
Command command = DefaultCommandProcessor.REGISTRY.commands().get(content);
if (command != null) {
final MessageEmbed help = command.help(event);
if (help != null) {
event.getChannel().sendMessage(help).queue();
} else {
event.getChannel().sendMessage(EmoteReference.ERROR + "There's no extended help set for this command.").queue();
}
} else {
event.getChannel().sendMessage(EmoteReference.ERROR + "A command with this name doesn't exist").queue();
}
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Help Command").setColor(Color.PINK).setDescription("**" + jokes.get(r.nextInt(jokes.size())) + "**").addField("Usage", "`~>help` - **Returns a list of commands that you can use**.\n" + "`~>help <command>` - **Return information about the command specified**.", false).build();
}
});
cr.registerAlias("help", "commands");
// why not
cr.registerAlias("help", "halp");
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class MiscCmds method randomFact.
@Subscribe
public void randomFact(CommandRegistry cr) {
cr.register("randomfact", new SimpleCommand(Category.MISC) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
event.getChannel().sendMessage(EmoteReference.TALKING + facts.get().get(rand.nextInt(facts.get().size() - 1))).queue();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Random Fact").setDescription("**Sends a random fact.**").build();
}
});
cr.registerAlias("randomfact", "rf");
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class MiscCmds method eightBall.
@Subscribe
public void eightBall(CommandRegistry cr) {
cr.register("8ball", new SimpleCommand(Category.MISC) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (content.isEmpty()) {
onError(event);
return;
}
String textEncoded;
String answer;
try {
textEncoded = URLEncoder.encode(content, "UTF-8");
String json = Utils.wgetResty(String.format("https://8ball.delegator.com/magic/JSON/%1s", textEncoded), event);
answer = new JSONObject(json).getJSONObject("magic").getString("answer");
} catch (Exception exception) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I ran into an error while fetching 8ball results.").queue();
return;
}
event.getChannel().sendMessage("\uD83D\uDCAC " + answer + ".").queue();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "8ball").setDescription("**Retrieves an answer from the almighty 8ball.**").addField("Usage", "`~>8ball <question>` - **Retrieves an answer from 8ball based on the question or sentence provided.**", false).build();
}
});
cr.registerAlias("8ball", "8b");
}
Aggregations