use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class FunCmds method ratewaifu.
@Command
public static void ratewaifu(CommandRegistry cr) {
cr.register("ratewaifu", new SimpleCommand(Category.FUN) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (args.length == 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Give me a waifu to rate!").queue();
return;
}
int waifuRate = r.nextInt(100);
if (content.equalsIgnoreCase("mantaro"))
waifuRate = 100;
event.getChannel().sendMessage(EmoteReference.THINKING + "I rate " + content + " with a **" + waifuRate + "/100**").queue();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Rate your waifu").setDescription("**Just rates your waifu from zero to 100. Results may vary.**").build();
}
});
cr.registerAlias("ratewaifu", "rw");
}
use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class GameCmds method startGame.
private static void startGame(Game game, GuildMessageReceivedEvent event) {
if (GameLobby.LOBBYS.containsKey(event.getChannel())) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Cannot start a new game when there is a game currently running.").queue();
return;
}
LinkedList<Game> list = new LinkedList<>();
list.add(game);
HashMap<Member, Player> map = new HashMap<>();
map.put(event.getMember(), MantaroData.db().getPlayer(event.getMember()));
if (!event.getMessage().getMentionedRoles().isEmpty()) {
StringBuilder b = new StringBuilder();
event.getMessage().getMentionedRoles().forEach(role -> event.getGuild().getMembersWithRoles(role).forEach(user -> {
if (!user.getUser().getId().equals(event.getJDA().getSelfUser().getId()))
map.put(user, MantaroData.db().getPlayer(user));
b.append(user.getEffectiveName()).append(" ");
}));
event.getChannel().sendMessage(EmoteReference.MEGA + "Started a MP game with all users with the specfied role: " + b.toString()).queue();
}
if (!event.getMessage().getMentionedUsers().isEmpty()) {
StringBuilder builder = new StringBuilder();
event.getMessage().getMentionedUsers().forEach(user -> {
if (!user.getId().equals(event.getJDA().getSelfUser().getId()))
map.put(event.getGuild().getMember(user), MantaroData.db().getPlayer(event.getGuild().getMember(user)));
builder.append(user.getName()).append(" ");
});
event.getChannel().sendMessage(EmoteReference.MEGA + "Started a MP game with users: " + builder.toString()).queue();
}
GameLobby lobby = new GameLobby(event, map, list);
lobby.startFirstGame();
}
use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class MusicCmds method repeat.
@Command
public static void repeat(CommandRegistry cr) {
cr.register("repeat", new SimpleCommand(Category.MUSIC) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (!event.getMember().getVoiceState().inVoiceChannel() || !event.getMember().getVoiceState().getChannel().equals(event.getGuild().getAudioManager().getConnectedChannel())) {
sendNotConnectedToMyChannel(event.getChannel());
return;
}
GuildMusicManager musicManager = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
try {
switch(args[0].toLowerCase()) {
case "queue":
if (musicManager.getTrackScheduler().getRepeat() == Repeat.QUEUE) {
musicManager.getTrackScheduler().setRepeat(null);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Continuing with the current queue.").queue();
} else {
musicManager.getTrackScheduler().setRepeat(Repeat.QUEUE);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Repeating the current queue.").queue();
}
break;
}
} catch (Exception e) {
if (musicManager.getTrackScheduler().getRepeat() == Repeat.SONG) {
musicManager.getTrackScheduler().setRepeat(null);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Continuing with the normal queue.").queue();
} else {
musicManager.getTrackScheduler().setRepeat(Repeat.SONG);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Repeating the current song.").queue();
}
}
TextChannelGround.of(event).dropItemWithChance(0, 10);
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Repeat command").setDescription("**Repeats a song.**").addField("Usage", "`~>repeat` - **Toggles repeat**\n" + "`~>repeat queue` - **Repeats the entire queue**.", false).addField("Warning", "Might not work correctly if I leave the voice channel after you have disabled repeat. *To fix, just " + "add a song to the queue*", true).build();
}
});
}
use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class MoneyCmds method gamble.
@Command
public static void gamble(CommandRegistry cr) {
RateLimiter rateLimiter = new RateLimiter(TimeUnit.SECONDS, 15);
Random r = new Random();
cr.register("gamble", new SimpleCommand(Category.CURRENCY) {
@Override
public void call(GuildMessageReceivedEvent event, String content, String[] args) {
String id = event.getAuthor().getId();
Player player = MantaroData.db().getPlayer(event.getMember());
if (!rateLimiter.process(id)) {
event.getChannel().sendMessage(EmoteReference.STOPWATCH + "Halt! You're gambling so fast that I can't print enough money!").queue();
return;
}
if (player.getMoney() <= 0) {
event.getChannel().sendMessage(EmoteReference.ERROR2 + "You're broke. Search for some credits first!").queue();
return;
}
if (player.getMoney() > (long) (Integer.MAX_VALUE) * 3) {
event.getChannel().sendMessage(EmoteReference.ERROR2 + "You have too much money! Maybe transfer or buy items?").queue();
return;
}
double multiplier;
long i;
int luck;
try {
switch(content) {
case "all":
case "everything":
i = player.getMoney();
multiplier = 1.4d + (r.nextInt(1500) / 1000d);
luck = 30 + (int) (multiplier * 10) + r.nextInt(20);
break;
case "half":
i = player.getMoney() == 1 ? 1 : player.getMoney() / 2;
multiplier = 1.2d + (r.nextInt(1500) / 1000d);
luck = 20 + (int) (multiplier * 15) + r.nextInt(20);
break;
case "quarter":
i = player.getMoney() == 1 ? 1 : player.getMoney() / 4;
multiplier = 1.1d + (r.nextInt(1100) / 1000d);
luck = 25 + (int) (multiplier * 10) + r.nextInt(18);
break;
default:
i = Long.parseLong(content);
if (i > player.getMoney() || i < 0)
throw new UnsupportedOperationException();
multiplier = 1.1d + (i / player.getMoney() * r.nextInt(1300) / 1000d);
luck = 15 + (int) (multiplier * 15) + r.nextInt(10);
break;
}
} catch (NumberFormatException e) {
event.getChannel().sendMessage(EmoteReference.ERROR2 + "Please type a valid number equal or less than your credits or" + " `all` to gamble all your credits.").queue();
return;
} catch (UnsupportedOperationException e) {
event.getChannel().sendMessage(EmoteReference.ERROR2 + "Please type a value within your credits amount.").queue();
return;
}
User user = event.getAuthor();
long gains = (long) (i * multiplier);
gains = Math.round(gains * 0.55);
final int finalLuck = luck;
final long finalGains = gains;
if (i >= Integer.MAX_VALUE / 4) {
event.getChannel().sendMessage(EmoteReference.WARNING + "You're about to bet **" + i + "** " + "credits (which seems to be a lot). Are you sure? Type **yes** to continue and **no** otherwise.").queue();
InteractiveOperations.create(event.getChannel(), "Gambling", (int) TimeUnit.SECONDS.toMillis(30), OptionalInt.empty(), new InteractiveOperation() {
@Override
public boolean run(GuildMessageReceivedEvent e) {
if (e.getAuthor().getId().equals(user.getId())) {
if (e.getMessage().getContent().equalsIgnoreCase("yes")) {
proceedGamble(event, player, finalLuck, random, i, finalGains);
return true;
} else if (e.getMessage().getContent().equalsIgnoreCase("no")) {
e.getChannel().sendMessage(EmoteReference.ZAP + "Cancelled bet.").queue();
return true;
}
}
return false;
}
@Override
public void onExpire() {
event.getChannel().sendMessage(EmoteReference.ERROR + "Time to complete the operation has ran out.").queue();
}
});
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>", false).build();
}
});
}
use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class MoneyCmds method daily.
@Command
public static void daily(CommandRegistry cr) {
RateLimiter rateLimiter = new RateLimiter(TimeUnit.HOURS, 24);
Random r = new Random();
cr.register("daily", new SimpleCommand(Category.CURRENCY) {
@Override
public void call(GuildMessageReceivedEvent event, String content, String[] args) {
String id = event.getAuthor().getId();
long money = 150L;
User mentionedUser = null;
try {
mentionedUser = event.getMessage().getMentionedUsers().get(0);
} catch (IndexOutOfBoundsException ignored) {
}
Player player;
if (!rateLimiter.process(id)) {
event.getChannel().sendMessage(EmoteReference.STOPWATCH + "Halt! You can only do this once every 24 hours.\n**You'll be able to use this command again in " + Utils.getVerboseTime(rateLimiter.tryAgainIn(id)) + ".**").queue();
return;
}
if (mentionedUser != null && !mentionedUser.getId().equals(event.getAuthor().getId())) {
money = money + r.nextInt(2);
player = MantaroData.db().getPlayer(event.getGuild().getMember(mentionedUser));
if (player.getInventory().containsItem(Items.COMPANION))
money = Math.round(money + (money * 0.10));
if (mentionedUser.getId().equals(player.getData().getMarriedWith()) && player.getData().getMarriedSince() != null && Long.parseLong(player.getData().anniversary()) - player.getData().getMarriedSince() > TimeUnit.DAYS.toMillis(1)) {
money = money + r.nextInt(20);
if (player.getInventory().containsItem(Items.RING_2)) {
money = money + r.nextInt(10);
}
}
player.addMoney(money);
player.save();
event.getChannel().sendMessage(EmoteReference.CORRECT + "I gave your **$" + money + "** daily credits to " + mentionedUser.getName()).queue();
return;
}
player = MantaroData.db().getPlayer(event.getMember());
player.addMoney(money);
player.save();
event.getChannel().sendMessage(EmoteReference.CORRECT + "You got **$" + money + "** daily credits.").queue();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Daily command").setDescription("**Gives you $150 credits per day (or between 150 and 180 if you transfer it to another person)**.").build();
}
});
}
Aggregations