Search in sources :

Example 11 with MessageReceivedEvent

use of net.dv8tion.jda.core.events.message.MessageReceivedEvent in project Gary by help-chat.

the class RMSUtils method checkMessage.

private boolean checkMessage(GenericMessageEvent e) {
    User author = null;
    Message message = null;
    if (e instanceof MessageReceivedEvent) {
        MessageReceivedEvent ev = (MessageReceivedEvent) e;
        author = ev.getAuthor();
        message = ev.getMessage();
    }
    if (e instanceof MessageUpdateEvent) {
        MessageUpdateEvent ev = (MessageUpdateEvent) e;
        author = ev.getAuthor();
        message = ev.getMessage();
    }
    if (author != null && message != null) {
        MessageChannel channel = e.getChannel();
        String msg = message.getContentRaw();
        List<String> items = new ArrayList<>();
        Stream.of("[name]", "[ip]", "[description]").forEach(items::add);
        if (mutil.contains(msg, items) || mutil.startsWith(msg, "[REVIEW]")) {
            System.out.println(author.getName() + "#" + author.getDiscriminator() + " has successfully created a request.");
            return true;
        } else {
            message.delete().queue();
            sendHelp(author, channel, msg);
        }
    }
    return false;
}
Also used : User(net.dv8tion.jda.core.entities.User) Message(net.dv8tion.jda.core.entities.Message) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) MessageUpdateEvent(net.dv8tion.jda.core.events.message.MessageUpdateEvent) ArrayList(java.util.ArrayList) MessageReceivedEvent(net.dv8tion.jda.core.events.message.MessageReceivedEvent)

Example 12 with MessageReceivedEvent

use of net.dv8tion.jda.core.events.message.MessageReceivedEvent in project Gary by help-chat.

the class RequestUtils method checkMessage.

public void checkMessage(GenericMessageEvent e) {
    User author = null;
    Message message = null;
    if (e instanceof MessageReceivedEvent) {
        MessageReceivedEvent ev = (MessageReceivedEvent) e;
        author = ev.getAuthor();
        message = ev.getMessage();
    }
    if (e instanceof MessageUpdateEvent) {
        MessageUpdateEvent ev = (MessageUpdateEvent) e;
        author = ev.getAuthor();
        message = ev.getMessage();
    }
    if (author != null && message != null) {
        MessageChannel channel = e.getChannel();
        String msg = message.getContentRaw();
        List<String> items = new ArrayList<>();
        Stream.of("service:", "what i want:").forEach(items::add);
        if (mutil.startsWith(msg, "[paid]")) {
            items.add("budget:");
        }
        if (mutil.contains(msg, items) && mutil.startsWith(msg, "[unpaid]/[paid]")) {
            System.out.println(author.getName() + "#" + author.getDiscriminator() + " has successfully created a request.");
        } else {
            message.delete().queue();
            String requirements = "- You must have '[PAID]' or '[UNPAID]' at the top of your request\n" + "- You must have 'Service:' in your request\n" + "- You must have 'What I want:' in your request\n" + "- If paid, you must have 'Budget:' in your request";
            String example = "[PAID]/[UNPAID]\n" + "Service: plugin development\n" + "What I want: I need a plugin that spawns llamas all over spawn\n" + "Budget (Only if paid request): $231.95";
            User finalAuthor = author;
            author.openPrivateChannel().queue(privateChannel -> {
                String string = "Your latest request is not following the requirements for <#297996869173379072>.\n\n" + "The requirements are as below:\n```" + requirements + "```\nFor example,\n```" + example + "```\nPlease edit your message below to fit the requirements:\n```" + msg + "```";
                privateChannel.sendMessage(string).queue(message1 -> {
                }, throwable -> {
                    String hastebin = wutil.hastebin("Your latest request is not following the requirements for <#297996869173379072>.\n\n" + "The requirements are as below:\n" + requirements + "\n\nFor example,\n\n" + example + "\n\nPlease edit your message below to fit the requirements:\n\n" + msg);
                    String toSend = !hastebin.equals("fail") ? "**THIS MESSAGE WILL BE REMOVED IN 30 SECONDS!**\n" + finalAuthor.getAsMention() + " Your message does not follow the requirements for <#297996869173379072>, " + "please read this:\n" + hastebin : "**THIS MESSAGE WILL BE REMOVED IN 30 SECONDS!**\n" + finalAuthor.getAsMention() + " Your message does not follow the requirements for <#297996869173379072>, " + "please fix any mistakes.\nhastebin.com is down and you have pm's disabled, " + "I cannot show you your message, you will have to try remember it.";
                    channel.sendMessage(toSend).queue(message1 -> message1.delete().completeAfter(30, TimeUnit.SECONDS));
                });
            });
        }
    }
}
Also used : User(net.dv8tion.jda.core.entities.User) Message(net.dv8tion.jda.core.entities.Message) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) MessageUpdateEvent(net.dv8tion.jda.core.events.message.MessageUpdateEvent) ArrayList(java.util.ArrayList) MessageReceivedEvent(net.dv8tion.jda.core.events.message.MessageReceivedEvent)

Example 13 with MessageReceivedEvent

use of net.dv8tion.jda.core.events.message.MessageReceivedEvent in project legendarybot by greatman.

the class LinkWoWCharsCommand method execute.

@Override
public void execute(MessageReceivedEvent event, String[] args) {
    String region = plugin.getBot().getGuildSettings(event.getGuild()).getRegionName();
    if (region == null) {
        event.getChannel().sendMessage("The Region is not configured. Please ask a server admin to configure it with the setup command").queue();
        return;
    }
    OAuth20Service service = new ServiceBuilder(plugin.getProps().getProperty("battlenetoauth.key")).scope("wow.profile").callback("https://legendarybot.greatmancode.com/auth/battlenetcallback").state(region + ":" + event.getAuthor().getId()).build(new OAuthBattleNetApi(region));
    event.getAuthor().openPrivateChannel().queue((privateChannel -> privateChannel.sendMessage("Please follow this link to connect your WoW account to this bot: " + service.getAuthorizationUrl()).queue()));
    log.info("User " + event.getAuthor().getName() + ":" + event.getAuthor().getId() + " requested to link his characters. Link generated: " + service.getAuthorizationUrl());
}
Also used : OAuthBattleNetApi(com.greatmancode.legendarybot.plugins.wowlink.utils.OAuthBattleNetApi) ZeroArgsCommand(com.greatmancode.legendarybot.api.commands.ZeroArgsCommand) ServiceBuilder(com.github.scribejava.core.builder.ServiceBuilder) Logger(org.slf4j.Logger) MessageReceivedEvent(net.dv8tion.jda.core.events.message.MessageReceivedEvent) LoggerFactory(org.slf4j.LoggerFactory) OAuth20Service(com.github.scribejava.core.oauth.OAuth20Service) PublicCommand(com.greatmancode.legendarybot.api.commands.PublicCommand) WoWLinkPlugin(com.greatmancode.legendarybot.plugins.wowlink.WoWLinkPlugin) OAuthBattleNetApi(com.greatmancode.legendarybot.plugins.wowlink.utils.OAuthBattleNetApi) OAuth20Service(com.github.scribejava.core.oauth.OAuth20Service) ServiceBuilder(com.github.scribejava.core.builder.ServiceBuilder)

Example 14 with MessageReceivedEvent

use of net.dv8tion.jda.core.events.message.MessageReceivedEvent in project legendarybot by greatman.

the class DebugGuildCommand method execute.

@Override
public void execute(MessageReceivedEvent event, String[] args) {
    if (args.length == 2) {
        List<Guild> userGuilds = new ArrayList<>();
        getBot().getJDA().forEach((jda) -> userGuilds.addAll(jda.getUserById(args[1]).getMutualGuilds()));
        StringBuilder builder = new StringBuilder();
        userGuilds.forEach(guild -> {
            builder.append(guild.getName() + ":" + guild.getId());
        });
        event.getAuthor().openPrivateChannel().queue(new Consumer<PrivateChannel>() {

            @Override
            public void accept(PrivateChannel privateChannel) {
                privateChannel.sendMessage(builder.toString()).queue();
            }
        });
        return;
    }
    final Guild[] guildEntry = { null };
    getBot().getJDA().forEach((jda -> {
        if (guildEntry[0] == null) {
            guildEntry[0] = jda.getGuildById(args[0]);
        }
    }));
    if (guildEntry[0] != null) {
        Guild guild = guildEntry[0];
        StringBuilder builder = new StringBuilder();
        PrivateChannel channel = event.getAuthor().openPrivateChannel().complete();
        builder.append("Guild " + guild.getName() + "\n");
        builder.append("Roles:\n");
        guild.getRoles().forEach((role -> builder.append(role.getName() + "\n")));
        builder.append("Config:\n");
        builder.append("Guild Name: " + getBot().getGuildSettings(guild).getGuildName() + "\n");
        builder.append("Region Name: " + getBot().getGuildSettings(guild).getRegionName() + "\n");
        builder.append("Realm name: " + getBot().getGuildSettings(guild).getWowServerName() + "\n");
        builder.append("WoW Rank config:\n");
        builder.append("Rank 0: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_0") + "\n");
        builder.append("Rank 1: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_1") + "\n");
        builder.append("Rank 2: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_2") + "\n");
        builder.append("Rank 3: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_3") + "\n");
        builder.append("Rank 4: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_4") + "\n");
        builder.append("Rank 5: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_5") + "\n");
        builder.append("Rank 6: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_6") + "\n");
        builder.append("Rank 7: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_7") + "\n");
        builder.append("Rank 8: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_8") + "\n");
        builder.append("Rank 9: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_9") + "\n");
        builder.append("Rank Enabled: " + getBot().getGuildSettings(guild).getSetting("wowlink_rankset") + "\n");
        channel.sendMessage(builder.toString()).queue();
    }
}
Also used : PrivateChannel(net.dv8tion.jda.core.entities.PrivateChannel) Consumer(java.util.function.Consumer) Guild(net.dv8tion.jda.core.entities.Guild) List(java.util.List) LegendaryBotPlugin(com.greatmancode.legendarybot.api.plugin.LegendaryBotPlugin) Member(net.dv8tion.jda.core.entities.Member) MessageReceivedEvent(net.dv8tion.jda.core.events.message.MessageReceivedEvent) PrivateChannel(net.dv8tion.jda.core.entities.PrivateChannel) Command(com.greatmancode.legendarybot.api.commands.Command) PluginWrapper(org.pf4j.PluginWrapper) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Guild(net.dv8tion.jda.core.entities.Guild)

Aggregations

MessageReceivedEvent (net.dv8tion.jda.core.events.message.MessageReceivedEvent)14 ArrayList (java.util.ArrayList)4 Consumer (java.util.function.Consumer)4 Message (net.dv8tion.jda.core.entities.Message)4 Main (ws.nmathe.saber.Main)4 Command (ws.nmathe.saber.commands.Command)4 CommandInfo (ws.nmathe.saber.commands.CommandInfo)4 MessageUtilities (ws.nmathe.saber.utils.MessageUtilities)4 Filters.eq (com.mongodb.client.model.Filters.eq)3 java.util (java.util)3 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)3 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)3 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)3 PublicCommand (com.greatmancode.legendarybot.api.commands.PublicCommand)2 ZeroArgsCommand (com.greatmancode.legendarybot.api.commands.ZeroArgsCommand)2 LegendaryBotPlugin (com.greatmancode.legendarybot.api.plugin.LegendaryBotPlugin)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Permission (net.dv8tion.jda.core.Permission)2 Channel (net.dv8tion.jda.core.entities.Channel)2