use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class MiscCmds method iamFunction.
protected static void iamFunction(String autoroleName, GuildMessageReceivedEvent event) {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
Map<String, String> autoroles = dbGuild.getData().getAutoroles();
if (autoroles.containsKey(autoroleName)) {
Role role = event.getGuild().getRoleById(autoroles.get(autoroleName));
if (role == null) {
event.getChannel().sendMessage(EmoteReference.ERROR + "The role that this autorole corresponded to has been deleted").queue();
// delete the non-existent autorole.
dbGuild.getData().getAutoroles().remove(autoroleName);
dbGuild.saveAsync();
} else {
if (event.getMember().getRoles().stream().filter(r1 -> r1.getId().equals(role.getId())).collect(Collectors.toList()).size() > 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You already have this role, silly!").queue();
return;
}
try {
event.getGuild().getController().addSingleRoleToMember(event.getMember(), role).reason("Auto-assignable roles assigner (~>iam)").queue(aVoid -> event.getChannel().sendMessage(String.format("%s%s, you've been given the **%s** role", EmoteReference.OK, event.getMember().getEffectiveName(), role.getName())).queue());
} catch (PermissionException pex) {
event.getChannel().sendMessage(String.format("%sI couldn't take from you **%s. Make sure that I have permission to add roles and that my role is above **%s**", EmoteReference.ERROR, role.getName(), role.getName())).queue();
}
}
} else {
event.getChannel().sendMessage(EmoteReference.ERROR + "There isn't an autorole with the name ``" + autoroleName + "``!").queue();
}
}
use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent 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");
}
use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent 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");
}
use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class MoneyCmds method gamble.
@Subscribe
public void gamble(CommandRegistry cr) {
cr.register("gamble", new SimpleCommand(Category.CURRENCY) {
final RateLimiter rateLimiter = new RateLimiter(TimeUnit.SECONDS, 20, true);
SecureRandom r = new SecureRandom();
@Override
public void call(GuildMessageReceivedEvent event, String content, String[] args) {
Player player = MantaroData.db().getPlayer(event.getMember());
if (!handleDefaultRatelimit(rateLimiter, event.getAuthor(), event))
return;
if (player.getMoney() <= 0) {
event.getChannel().sendMessage(EmoteReference.ERROR2 + "You're broke. Search for some credits first!").queue();
return;
}
if (player.getMoney() > GAMBLE_ABSOLUTE_MAX_MONEY) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You have too much money! Maybe transfer or buy items? Now you can also use `~>slots`" + " for all your gambling needs! Thanks for not breaking the local bank. *(Gamble limit: " + GAMBLE_ABSOLUTE_MAX_MONEY + ")*").queue();
return;
}
double multiplier;
long i;
int luck;
try {
switch(content) {
case "all":
case "everything":
i = player.getMoney();
multiplier = 1.3d + (r.nextInt(1450) / 1000d);
luck = 21 + (int) (multiplier * 13) + r.nextInt(18);
break;
case "half":
i = player.getMoney() == 1 ? 1 : player.getMoney() / 2;
multiplier = 1.2d + (r.nextInt(1350) / 1000d);
luck = 19 + (int) (multiplier * 13) + r.nextInt(18);
break;
case "quarter":
i = player.getMoney() == 1 ? 1 : player.getMoney() / 4;
multiplier = 1.1d + (r.nextInt(1250) / 1000d);
luck = 18 + (int) (multiplier * 12) + r.nextInt(18);
break;
default:
i = content.endsWith("%") ? Math.round(PERCENT_FORMAT.get().parse(content).doubleValue() * player.getMoney()) : Long.parseLong(content);
if (i > player.getMoney() || i < 0)
throw new UnsupportedOperationException();
multiplier = 1.1d + (i / player.getMoney() * r.nextInt(1300) / 1000d);
luck = 17 + (int) (multiplier * 13) + r.nextInt(12);
break;
}
} catch (NumberFormatException e) {
event.getChannel().sendMessage(EmoteReference.ERROR2 + "Please type a valid number less than or equal to your current balance or" + " `all` to gamble all your credits.").queue();
return;
} catch (UnsupportedOperationException e) {
event.getChannel().sendMessage(EmoteReference.ERROR2 + "Please type a value within your balance.").queue();
return;
} catch (ParseException e) {
event.getChannel().sendMessage(EmoteReference.ERROR2 + "Please type a valid percentage value.").queue();
return;
}
User user = event.getAuthor();
long gains = (long) (i * multiplier);
gains = Math.round(gains * 0.45);
final int finalLuck = luck;
final long finalGains = gains;
if (i >= Integer.MAX_VALUE / 4) {
player.setLocked(true);
player.save();
event.getChannel().sendMessage(String.format("%sYou're about to bet **%d** credits (which seems to be a lot). " + "Are you sure? Type **yes** to continue and **no** otherwise.", EmoteReference.WARNING, i)).queue();
InteractiveOperations.create(event.getChannel(), 30, new InteractiveOperation() {
@Override
public int run(GuildMessageReceivedEvent e) {
if (e.getAuthor().getId().equals(user.getId())) {
if (e.getMessage().getContentRaw().equalsIgnoreCase("yes")) {
proceedGamble(event, player, finalLuck, random, i, finalGains);
return COMPLETED;
} else if (e.getMessage().getContentRaw().equalsIgnoreCase("no")) {
e.getChannel().sendMessage(EmoteReference.ZAP + "Cancelled bet.").queue();
player.setLocked(false);
player.saveAsync();
return COMPLETED;
}
}
return IGNORED;
}
@Override
public void onExpire() {
event.getChannel().sendMessage(EmoteReference.ERROR + "Time to complete the operation has ran out.").queue();
player.setLocked(false);
player.saveAsync();
}
});
return;
}
proceedGamble(event, player, luck, random, i, gains);
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Gamble command").setDescription("Gambles your money").addField("Usage", "~>gamble <all/half/quarter> or ~>gamble <amount>\n" + "You can also use percentages now, for example `~>gamble 35%`", false).build();
}
});
}
use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class MoneyCmds method balance.
@Subscribe
public void balance(CommandRegistry cr) {
cr.register("balance", new SimpleCommand(Category.CURRENCY) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
User user = event.getAuthor();
boolean isExternal = false;
List<Member> found = FinderUtil.findMembers(content, event.getGuild());
if (found.isEmpty() && !content.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Your search yielded no results :(").queue();
return;
}
if (found.size() > 1 && !content.isEmpty()) {
event.getChannel().sendMessage(String.format("%sToo many users found, maybe refine your search? (ex. use name#discriminator)\n" + "**Users found:** %s", EmoteReference.THINKING, found.stream().map(m -> m.getUser().getName() + "#" + m.getUser().getDiscriminator()).collect(Collectors.joining(", ")))).queue();
return;
}
if (found.size() == 1) {
user = found.get(0).getUser();
isExternal = true;
}
long balance = MantaroData.db().getPlayer(user).getMoney();
event.getChannel().sendMessage(EmoteReference.DIAMOND + (isExternal ? user.getName() + "'s balance is: **$" : "Your balance is: **$") + balance + "**").queue();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return baseEmbed(event, "Balance command").setDescription("**Shows your current balance or another person's balance.**").build();
}
});
cr.registerAlias("balance", "credits");
cr.registerAlias("balance", "bal");
}
Aggregations