Search in sources :

Example 21 with Message

use of net.dv8tion.jda.core.entities.Message in project MOOTBoot by LeshDev.

the class botPing method onMessageReceived.

public void onMessageReceived(MessageReceivedEvent e) {
    Message msg = e.getMessage();
    if (!msg.getRawContent().startsWith("-ping") || bannedList.black.contains(e.getAuthor().getIdLong())) {
        return;
    }
    EmbedBuilder eB = new EmbedBuilder();
    long start = System.currentTimeMillis();
    eB.setAuthor(">> Bot Ping", null, lib.bot_image);
    eB.addField("Ping", "**Bot: **" + e.getJDA().getPing() + "ms\n" + "**User: **" + (System.currentTimeMillis() - start) + "ms", false);
    eB.setColor(java.awt.Color.MAGENTA);
    e.getChannel().sendMessage(eB.build()).queue();
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Message(net.dv8tion.jda.core.entities.Message)

Example 22 with Message

use of net.dv8tion.jda.core.entities.Message in project MantaroBot by Mantaro.

the class TrackScheduler method onTrackSchedulerStop.

private void onTrackSchedulerStop() {
    getVoteStop().clear();
    Guild g = getGuild();
    if (g == null)
        return;
    AudioManager m = g.getAudioManager();
    if (m == null)
        return;
    m.closeAudioConnection();
    AudioTrackContext previousTrack;
    try {
        previousTrack = getPreviousTrack();
        if (previousTrack != null && previousTrack.getRequestedChannel() != null && previousTrack.getRequestedChannel().canTalk())
            previousTrack.getRequestedChannel().sendMessage(":mega: Finished playing queue! Hope you enjoyed it.").queue(message -> message.delete().queueAfter(20, TimeUnit.SECONDS));
    }//fuck
     catch (Exception ignored) {
    }
}
Also used : AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) Getter(lombok.Getter) TextChannel(net.dv8tion.jda.core.entities.TextChannel) MantaroShard(net.kodehawa.mantarobot.MantaroShard) Message(net.dv8tion.jda.core.entities.Message) ArrayList(java.util.ArrayList) MantaroBot(net.kodehawa.mantarobot.MantaroBot) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) AudioTrackEndReason(com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) AudioTrackState(com.sedmelluq.discord.lavaplayer.track.AudioTrackState) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) AudioManager(net.dv8tion.jda.core.managers.AudioManager) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Guild(net.dv8tion.jda.core.entities.Guild) List(java.util.List) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) MantaroData(net.kodehawa.mantarobot.data.MantaroData) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioEventAdapter(com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter) Collections(java.util.Collections) AudioManager(net.dv8tion.jda.core.managers.AudioManager) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) Guild(net.dv8tion.jda.core.entities.Guild) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 23 with Message

use of net.dv8tion.jda.core.entities.Message in project MantaroBot by Mantaro.

the class ReactionOperations method create.

public static Future<Void> create(Message message, long timeoutSeconds, ReactionOperation operation, String... defaultReactions) {
    if (!message.getAuthor().equals(message.getJDA().getSelfUser()))
        throw new IllegalArgumentException("Must provide a message sent by the bot");
    Future<Void> f = create(message.getIdLong(), timeoutSeconds, operation);
    if (defaultReactions.length > 0) {
        AtomicInteger index = new AtomicInteger();
        AtomicReference<Consumer<Void>> c = new AtomicReference<>();
        Consumer<Throwable> ignore = (t) -> {
        };
        c.set(ignored -> {
            int i = index.incrementAndGet();
            if (i < defaultReactions.length) {
                message.addReaction(defaultReactions[i]).queue(c.get(), ignore);
            }
        });
        message.addReaction(defaultReactions[0]).queue(c.get(), ignore);
    }
    return f;
}
Also used : MessageReactionAddEvent(net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Future(java.util.concurrent.Future) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExpiringMap(net.jodah.expiringmap.ExpiringMap) Event(net.dv8tion.jda.core.events.Event) CompletableFuture(java.util.concurrent.CompletableFuture) EventListener(net.dv8tion.jda.core.hooks.EventListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) Message(net.dv8tion.jda.core.entities.Message) Consumer(java.util.function.Consumer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 24 with Message

use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.

the class TrackScheduler method onTrackStart.

@Override
public void onTrackStart(AudioPlayer player, AudioTrack track) {
    if (manager.isShouldAnnounce()) {
        if (manager.getLastAnnouncementId() != null) {
            try {
                manager.getChannel().getMessageById(manager.getLastAnnouncementId()).queue(message -> message.delete().queue());
            } catch (Exception ignored) {
            }
        }
        User me = manager.getChannel().getGuild().getSelfMember().getUser();
        AudioTrackInfo info = track.getInfo();
        EmbedBuilder builder = MessageUtils.getDefaultEmbed(me);
        builder.setAuthor("Now playing " + info.title, "https://ardentbot.tk", "https://s-media-cache-ak0.pinimg" + ".com/736x/69/96/5c/69965c2849ec9b7148a5547ce6714735.jpg");
        builder.setThumbnail("https://s-media-cache-ak0.pinimg.com/736x/69/96/5c/69965c2849ec9b7148a5547ce6714735.jpg");
        builder.addField("Title", info.title, true).addField("Author", info.author, true).addField("Duration", Music.getDuration(track), true).addField("URL", info.uri, true).addField("Is Stream", String.valueOf(info.isStream), true);
        Message m = GuildUtils.getShard(manager.getChannel().getJDA()).help.sendEmbed(builder, manager.getChannel(), me);
        manager.setLastAnnouncementId(m.getId());
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) User(net.dv8tion.jda.core.entities.User) Message(net.dv8tion.jda.core.entities.Message) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) BotException(tk.ardentbot.core.misc.logging.BotException)

Example 25 with Message

use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.

the class RPGMoney method setupSubcommands.

@Override
public void setupSubcommands() throws Exception {
    subcommands.add(new Subcommand("See who has the most money - globally!", "top", "top") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            if (args.length == 2) {
                HashMap<User, Double> moneyAmounts = new HashMap<>();
                Cursor<HashMap> top = r.db("data").table("profiles").orderBy().optArg("index", r.desc("money")).limit(20).run(connection);
                top.forEach(hashMap -> {
                    Profile profile = asPojo(hashMap, Profile.class);
                    assert profile.getUser() != null;
                    moneyAmounts.put(profile.getUser(), profile.getMoney());
                });
                Map<User, Double> sortedAmounts = MapUtils.sortByValue(moneyAmounts);
                String topMoney = "Global Richest Users";
                EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
                builder.setAuthor(topMoney, getShard().url, guild.getIconUrl());
                StringBuilder description = new StringBuilder();
                final int[] current = { 0 };
                sortedAmounts.forEach((u, money) -> {
                    if (u != null) {
                        description.append("\n#" + (current[0] + 1) + ": **" + u.getName() + "** " + RPGUtils.formatMoney(money));
                        current[0]++;
                    }
                });
                description.append("\n\nGet money by sending commands or asking questions on our support server ( https://ardentbot" + ".tk/guild )\n\nSee people's money by doing /money @User or see yours by just using /money");
                sendEmbed(builder.setDescription(description.toString()), channel, user);
                return;
            }
            try {
                int page = Integer.parseInt(args[2]) - 1;
                HashMap<User, Double> moneyAmounts = new HashMap<>();
                Cursor<HashMap> top = r.db("data").table("profiles").orderBy().optArg("index", r.desc("money")).slice((page * 20), (page * 20) + 11).limit(25).run(connection);
                top.forEach(hashMap -> {
                    Profile profile = asPojo(hashMap, Profile.class);
                    assert profile.getUser() != null;
                    moneyAmounts.put(profile.getUser(), profile.getMoney());
                });
                Map<User, Double> sortedAmounts = MapUtils.sortByValue(moneyAmounts);
                String topMoney = "Global Richest Users | Page " + page;
                EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
                builder.setAuthor(topMoney, getShard().url, guild.getIconUrl());
                StringBuilder description = new StringBuilder();
                final int[] current = { 0 };
                sortedAmounts.forEach((u, money) -> {
                    if (u != null) {
                        description.append("\n#" + ((page * 20) + current[0] + 1) + ": **" + u.getName() + "** " + RPGUtils.formatMoney(money));
                        current[0]++;
                    }
                });
                description.append("\n\nGet money by sending commands or asking questions on our support server ( https://ardentbot" + ".tk/guild )\n\nSee people's money by doing /money @User or see yours by just using /money");
                sendEmbed(builder.setDescription(description.toString()), channel, user);
            } catch (NumberFormatException e) {
                sendTranslatedMessage("You need to specify a valid page number!", channel, user);
            }
        }
    });
    subcommands.add(new Subcommand("See who has the most money in your server", "server", "server", "guild", "topguild") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            if (!generatedFirstTimeFor.contains(guild.getId())) {
                sendTranslatedMessage("Please wait a second, generating and caching your server's statistics", channel, user);
                generatedFirstTimeFor.add(guild.getId());
            }
            HashMap<User, Double> moneyAmounts = new HashMap<>();
            guild.getMembers().forEach(member -> {
                User u = member.getUser();
                moneyAmounts.put(u, Profile.get(u).getMoney());
            });
            Map<User, Double> sortedAmounts = MapUtils.sortByValue(moneyAmounts);
            EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
            builder.setAuthor("Richest Users | This Server", getShard().url, guild.getIconUrl());
            StringBuilder description = new StringBuilder();
            description.append("**Richest Users in this Server**");
            final int[] current = { 0 };
            sortedAmounts.forEach((u, money) -> {
                if (current[0] < 10) {
                    description.append("\n#" + (current[0] + 1) + ": **" + u.getName() + "** " + RPGUtils.formatMoney(money));
                    current[0]++;
                }
            });
            description.append("\n\nGet money by sending commands or asking questions on our support server ( https://ardentbot" + ".tk/guild )\n\nSee people's money by doing /money @User or see yours by just using /money");
            sendEmbed(builder.setDescription(description.toString()), channel, user);
        }
    });
}
Also used : MessageUtils(tk.ardentbot.utils.discord.MessageUtils) Ratelimitable(tk.ardentbot.core.executor.Ratelimitable) Subcommand(tk.ardentbot.core.executor.Subcommand) Database.r(tk.ardentbot.rethink.Database.r) HashMap(java.util.HashMap) Profile(tk.ardentbot.utils.rpg.profiles.Profile) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Message(net.dv8tion.jda.core.entities.Message) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ArrayList(java.util.ArrayList) Guild(net.dv8tion.jda.core.entities.Guild) List(java.util.List) Cursor(com.rethinkdb.net.Cursor) User(net.dv8tion.jda.core.entities.User) RPGUtils(tk.ardentbot.utils.rpg.RPGUtils) MapUtils(tk.ardentbot.utils.MapUtils) Database.connection(tk.ardentbot.rethink.Database.connection) Map(java.util.Map) User(net.dv8tion.jda.core.entities.User) Subcommand(tk.ardentbot.core.executor.Subcommand) Message(net.dv8tion.jda.core.entities.Message) HashMap(java.util.HashMap) Guild(net.dv8tion.jda.core.entities.Guild) Cursor(com.rethinkdb.net.Cursor) Profile(tk.ardentbot.utils.rpg.profiles.Profile) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Message (net.dv8tion.jda.core.entities.Message)30 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)14 Guild (net.dv8tion.jda.core.entities.Guild)13 User (net.dv8tion.jda.core.entities.User)12 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)11 Subcommand (tk.ardentbot.core.executor.Subcommand)8 Command (tk.ardentbot.core.executor.Command)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Database.connection (tk.ardentbot.rethink.Database.connection)4 Database.r (tk.ardentbot.rethink.Database.r)4 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 Consumer (java.util.function.Consumer)3 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)3 MessageUtils (tk.ardentbot.utils.discord.MessageUtils)3 Cursor (com.rethinkdb.net.Cursor)2 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)2 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)2