Java Code Examples for net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent#getJDA()
The following examples show how to use
net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent#getJDA() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommandManager.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
private void runCustomCommand(ICommand cmd, String invoke, List<String> args, GuildMessageReceivedEvent event) { final CustomCommand cc = (CustomCommand) cmd; if (cc.getGuildId() != event.getGuild().getIdLong()) { return; } try { MDC.put("command.custom.message", cc.getMessage()); final Parser parser = CommandUtils.getParser(new CommandContext(invoke, args, event, variables)); final String message = parser.parse(cc.getMessage()); final MessageBuilder messageBuilder = new MessageBuilder(); final DataObject object = parser.get("embed"); if (!message.isEmpty()) { messageBuilder.setContent("\u200B" + message); } if (object != null) { final JDAImpl jda = (JDAImpl) event.getJDA(); final MessageEmbed embed = jda.getEntityBuilder().createMessageEmbed(object); messageBuilder.setEmbed(embed); } if (!messageBuilder.isEmpty()) { sendMsg(event, messageBuilder.build()); } parser.clear(); } catch (Exception e) { sendMsg(event, "Error with parsing custom command: " + e.getMessage()); Sentry.capture(e); } }
Example 2
Source File: DiscordGuildMessagePreProcessEvent.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
public DiscordGuildMessagePreProcessEvent(GuildMessageReceivedEvent jdaEvent) { super(jdaEvent.getJDA(), jdaEvent); this.author = jdaEvent.getAuthor(); this.channel = jdaEvent.getChannel(); this.guild = jdaEvent.getGuild(); this.member = jdaEvent.getMember(); this.message = jdaEvent.getMessage(); }
Example 3
Source File: DiscordGuildMessagePostProcessEvent.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
public DiscordGuildMessagePostProcessEvent(GuildMessageReceivedEvent jdaEvent, boolean cancelled, String processedMessage) { super(jdaEvent.getJDA(), jdaEvent); this.author = jdaEvent.getAuthor(); this.channel = jdaEvent.getChannel(); this.guild = jdaEvent.getGuild(); this.member = jdaEvent.getMember(); this.message = jdaEvent.getMessage(); this.setCancelled(cancelled); this.processedMessage = processedMessage; }
Example 4
Source File: DiscordGuildMessageReceivedEvent.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
public DiscordGuildMessageReceivedEvent(GuildMessageReceivedEvent jdaEvent) { super(jdaEvent.getJDA(), jdaEvent); this.author = jdaEvent.getAuthor(); this.channel = jdaEvent.getChannel(); this.guild = jdaEvent.getGuild(); this.member = jdaEvent.getMember(); this.message = jdaEvent.getMessage(); }
Example 5
Source File: AimlServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
@Override public boolean handleMessage(GuildMessageReceivedEvent event) { if (!workerProperties.getAiml().isEnabled() || StringUtils.isEmpty(workerProperties.getAiml().getBrainsPath())) { return false; } GuildConfig config = configService.get(event.getGuild()); if (config == null || !config.isAssistantEnabled() || !event.getMessage().isMentioned(event.getJDA().getSelfUser()) || !event.getGuild().getSelfMember().hasPermission(event.getChannel(), Permission.MESSAGE_WRITE)) { return false; } String content = event.getMessage().getContentRaw().trim(); if (StringUtils.isEmpty(content)) { return false; } JDA jda = event.getJDA(); boolean usingMention; String mention = jda.getSelfUser().getAsMention(); if (!(usingMention = content.startsWith(mention))) { mention = String.format("<@!%s>", jda.getSelfUser().getId()); usingMention = content.startsWith(mention); } if (usingMention) { String input = content.substring(mention.length()).trim(); if (StringUtils.isNotBlank(input)) { contextService.withContextAsync(event.getGuild(), () -> { event.getChannel().sendTyping().queue(); Chat chatSession = getSession("juniper_en", event.getAuthor()); if (chatSession != null) { String respond = chatSession.multisentenceRespond(createRequest(event, input)); if (StringUtils.isNotBlank(respond)) { event.getChannel().sendMessage(respond).queue(); } } }); return true; } } return false; }
Example 6
Source File: BaseCommandsService.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
@Override @Transactional public boolean handleMessage(GuildMessageReceivedEvent event) { JDA jda = event.getJDA(); String content = event.getMessage().getContentRaw().trim(); if (StringUtils.isEmpty(content)) { return false; } String prefix = null; String input = content; boolean usingMention = false; if (event.getMessage().isMentioned(jda.getSelfUser())) { String mention = jda.getSelfUser().getAsMention(); if (!(usingMention = content.startsWith(mention))) { mention = String.format("<@!%s>", jda.getSelfUser().getId()); usingMention = content.startsWith(mention); } if (usingMention) { prefix = mention; input = content.substring(prefix.length()).trim(); } } String firstPart = input.split("\\s+", 2)[0].trim(); if (!isValidKey(event, firstPart)) { return false; } GuildConfig guildConfig = entityAccessor.getOrCreate(event.getGuild()); if (!usingMention) { prefix = guildConfig != null ? guildConfig.getPrefix() : commonProperties.getDiscord().getDefaultPrefix(); if (prefix.length() > content.length()) { return true; } input = content.substring(prefix.length()).trim(); } if (StringUtils.isNotEmpty(prefix) && content.toLowerCase().startsWith(prefix.toLowerCase())) { String[] args = input.split("\\s+", 2); input = args.length > 1 ? args[1] : ""; return sendCommand(event, input, args[0], guildConfig); } return true; }