Search in sources :

Example 51 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.

the class GameCmds method startGame.

private void startGame(Game game, GuildMessageReceivedEvent event) {
    if (checkRunning(event))
        return;
    LinkedList<Game> list = new LinkedList<>();
    list.add(game);
    List<String> players = new ArrayList<>();
    players.add(event.getAuthor().getId());
    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()))
                players.add(user.getUser().getId());
            b.append(user.getEffectiveName()).append(" ");
        }));
        event.getChannel().sendMessage(EmoteReference.MEGA + "Started a MP game with all users with the specified 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()) && !user.isBot())
                players.add(user.getId());
            builder.append(user.getName()).append(" ");
        });
        if (players.size() > 1) {
            event.getChannel().sendMessage(EmoteReference.MEGA + "Started a MP game with users: " + builder.toString()).queue();
        }
    }
    GameLobby lobby = new GameLobby(event, players, list);
    lobby.startFirstGame();
}
Also used : GuessTheNumber(net.kodehawa.mantarobot.commands.game.GuessTheNumber) Module(net.kodehawa.mantarobot.core.modules.Module) GameLobby(net.kodehawa.mantarobot.commands.game.core.GameLobby) Member(net.dv8tion.jda.core.entities.Member) SimpleTreeCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleTreeCommand) Utils(net.kodehawa.mantarobot.utils.Utils) RateLimiter(net.kodehawa.mantarobot.utils.commands.RateLimiter) NewRateLimiter(net.kodehawa.mantarobot.utils.commands.NewRateLimiter) ArrayList(java.util.ArrayList) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) CommandRegistry(net.kodehawa.mantarobot.core.CommandRegistry) Subscribe(com.google.common.eventbus.Subscribe) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) LinkedList(java.util.LinkedList) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) Character(net.kodehawa.mantarobot.commands.game.Character) SubCommand(net.kodehawa.mantarobot.core.modules.commands.SubCommand) Game(net.kodehawa.mantarobot.commands.game.core.Game) Category(net.kodehawa.mantarobot.core.modules.commands.base.Category) SPLIT_PATTERN(net.kodehawa.mantarobot.utils.StringUtils.SPLIT_PATTERN) Trivia(net.kodehawa.mantarobot.commands.game.Trivia) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Pokemon(net.kodehawa.mantarobot.commands.game.Pokemon) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Pattern(java.util.regex.Pattern) Game(net.kodehawa.mantarobot.commands.game.core.Game) GameLobby(net.kodehawa.mantarobot.commands.game.core.GameLobby) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 52 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent 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");
}
Also used : SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SimpleFileDataManager(net.kodehawa.mantarobot.utils.data.SimpleFileDataManager) Subscribe(com.google.common.eventbus.Subscribe)

Example 53 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent 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");
}
Also used : MantaroInfo(net.kodehawa.mantarobot.MantaroInfo) Module(net.kodehawa.mantarobot.core.modules.Module) java.util(java.util) DefaultCommandProcessor(net.kodehawa.mantarobot.core.processor.DefaultCommandProcessor) Command(net.kodehawa.mantarobot.core.modules.commands.base.Command) Utils(net.kodehawa.mantarobot.utils.Utils) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) MantaroBot(net.kodehawa.mantarobot.MantaroBot) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Permission(net.dv8tion.jda.core.Permission) CommandRegistry(net.kodehawa.mantarobot.core.CommandRegistry) SnowflakeCacheView(net.dv8tion.jda.core.utils.cache.SnowflakeCacheView) Subscribe(com.google.common.eventbus.Subscribe) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) net.kodehawa.mantarobot.commands.info.stats.manager(net.kodehawa.mantarobot.commands.info.stats.manager) SimpleFileDataManager(net.kodehawa.mantarobot.utils.data.SimpleFileDataManager) ManagementFactory(java.lang.management.ManagementFactory) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) CommandListener(net.kodehawa.mantarobot.core.listeners.command.CommandListener) SubCommand(net.kodehawa.mantarobot.core.modules.commands.SubCommand) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) Category(net.kodehawa.mantarobot.core.modules.commands.base.Category) AsyncInfoMonitor(net.kodehawa.mantarobot.commands.info.AsyncInfoMonitor) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) OnlineStatus(net.dv8tion.jda.core.OnlineStatus) TreeCommand(net.kodehawa.mantarobot.core.modules.commands.TreeCommand) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CommandPermission(net.kodehawa.mantarobot.core.modules.commands.base.CommandPermission) StatsHelper.calculateInt(net.kodehawa.mantarobot.commands.info.stats.StatsHelper.calculateInt) BLUE_SMALL_MARKER(net.kodehawa.mantarobot.utils.commands.EmoteReference.BLUE_SMALL_MARKER) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) DateTimeFormatter(java.time.format.DateTimeFormatter) MantaroData(net.kodehawa.mantarobot.data.MantaroData) HelpUtils.forType(net.kodehawa.mantarobot.commands.info.HelpUtils.forType) StatsHelper.calculateDouble(net.kodehawa.mantarobot.commands.info.stats.StatsHelper.calculateDouble) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.core.modules.commands.base.Command) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) SubCommand(net.kodehawa.mantarobot.core.modules.commands.SubCommand) TreeCommand(net.kodehawa.mantarobot.core.modules.commands.TreeCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 54 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent 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();
        }
    });
}
Also used : SubCommand(net.kodehawa.mantarobot.core.modules.commands.SubCommand) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) List(java.util.List) TreeCommand(net.kodehawa.mantarobot.core.modules.commands.TreeCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 55 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent 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");
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)68 Subscribe (com.google.common.eventbus.Subscribe)50 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)48 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)42 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)36 MantaroData (net.kodehawa.mantarobot.data.MantaroData)34 List (java.util.List)28 Category (net.kodehawa.mantarobot.core.modules.commands.base.Category)27 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)26 Utils (net.kodehawa.mantarobot.utils.Utils)26 TimeUnit (java.util.concurrent.TimeUnit)25 Collectors (java.util.stream.Collectors)25 CommandRegistry (net.kodehawa.mantarobot.core.CommandRegistry)25 Module (net.kodehawa.mantarobot.core.modules.Module)25 MantaroBot (net.kodehawa.mantarobot.MantaroBot)19 SubCommand (net.kodehawa.mantarobot.core.modules.commands.SubCommand)18 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)18 RateLimiter (net.kodehawa.mantarobot.utils.commands.RateLimiter)18 Slf4j (lombok.extern.slf4j.Slf4j)17 Player (net.kodehawa.mantarobot.db.entities.Player)17