当前位置: 首页>>代码示例>>Java>>正文


Java MessageReceivedEvent类代码示例

本文整理汇总了Java中sx.blah.discord.handle.impl.events.MessageReceivedEvent的典型用法代码示例。如果您正苦于以下问题:Java MessageReceivedEvent类的具体用法?Java MessageReceivedEvent怎么用?Java MessageReceivedEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MessageReceivedEvent类属于sx.blah.discord.handle.impl.events包,在下文中一共展示了MessageReceivedEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendHelloWorld

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
private void sendHelloWorld(@NotNull MessageReceivedEvent event, boolean isMention, @Nullable String[] to) throws DiscordException, MissingPermissionsException, RateLimitException {
    @NotNull StringBuilder builder = new StringBuilder(40);
    if (isMention) {
        if (to == null) {
            builder.append(event.getMessage().getAuthor().mention())
                    .append(" ")
                    .append("Hello!");
        } else {
            builder.append("Hello");
            for (String str : to) {
                builder.append(" ")
                        .append(str);
            }
            builder.append("!");
        }
    } else {
        builder.append("Hello World!");
    }
    new MessageBuilder(event.getClient())
            .withChannel(event.getMessage().getChannel())
            .withContent(builder.toString())
            .send();
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:24,代码来源:SimpleCommandHandler.java

示例2: handle

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
@Override
public boolean handle(@NotNull MessageReceivedEvent event, String command, @NotNull String matchedText) throws
        RateLimitException, DiscordException, MissingPermissionsException {

    if (HELLO_COMMAND.mainCommand().equalsIgnoreCase(command)) {
        try {
            CommandLine cmd = HELLO_COMMAND.parse(matchedText);

            if (HELLO_COMMAND.showHelpIfPresent(event.getClient(), event.getMessage().getChannel(), cmd)) {
                return true;
            }

            boolean isMention = cmd.hasOption("m");
            String[] to = cmd.getOptionValues("m");

            sendHelloWorld(event, isMention, to);

        } catch (ParseException e) {
            logger.info("Parsing failed", e);
            EventUtils.sendIncorrectUsageMessage(event.getClient(), event.getMessage().getChannel(), HELLO_COMMAND.mainCommand(), e.getMessage());
        }
        return true;
    }
    return false;
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:26,代码来源:SimpleCommandHandler.java

示例3: handle

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
/**
 * Called when the event is sent.
 *
 * @param event The event object.
 */
@Override
public void handle(@NotNull final MessageReceivedEvent event) {
    logger.traceEntry("MessageReceivedEventReceiver will handle {}.", event::getMessage);

    @NotNull String text = event.getMessage().getContent().trim();

    boolean someoneHandled;
    @NotNull Matcher matcher = Regexes.BOT_COMMAND_NO_ARGS.pattern().matcher(text);

    if (!matcher.find()) {
        logger.traceExit("Message {} received but did not pass the command regex.", text);
        return;
    }
    logger.debug("Event receiver {} received commannd: {}", CLASS_NAME, matcher.group());

    someoneHandled = CommandDelegator.getInstance().degelateCommand(event, matcher.group(1), text);

    logger.traceExit("MessageReceivedEvent was handled: {} times.", someoneHandled);
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:25,代码来源:MessageReceivedEventReceiver.java

示例4: handle

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
/**
 * Called when the event is sent.
 *
 * @param event The event object.
 */
@Override
public void handle(@NotNull MessageReceivedEvent event) {
    if (!isUptimeCommand(event)) {
        return;
    }
    logger.traceEntry("Received uptime command");

    try {
        MessageUtils.getDefaultRequestBuilder(event.getMessage())
                    .doAction(Actions.ofSuccess(() -> MessageUtils.getMessageBuilder(event.getMessage())
                                                                  .appendContent("This bot has been online for: ")
                                                                  .appendContent(TimeUtils.formatAsElapsed())
                                                                  .send()))
                    .andThen(Actions.ofSuccess(event.getMessage()::delete))
                    .execute();

    } catch (Exception e) {
        logger.error(e);
    }
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:26,代码来源:UptimeCommand.java

示例5: handle

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
/**
 * Called when the event is sent.
 *
 * @param event The event object.
 */
@Override
public void handle(@NotNull final MessageReceivedEvent event) {
    if (!isPingCommand(event)) {
        return;
    }
    logger.traceEntry("Received ping command.");

    try {
        MessageUtils.getDefaultRequestBuilder(event.getMessage())
                    .doAction(Actions.ofSuccess(() -> MessageUtils.getMessageBuilder(event.getMessage())
                        .appendContent("Pong!")
                        .appendContent(System.lineSeparator())
                        .appendContent("Last reponse time in: ")
                        .appendContent(TimeUtils.formatToString(event.getMessage().getShard().getResponseTime(), TimeUnit.MILLISECONDS))
                        .send()))
                    .andThen(Actions.ofSuccess(event.getMessage()::delete))
                    .execute();

    } catch (@NotNull RateLimitException | MissingPermissionsException | DiscordException e) {
        logger.error(e);
    }
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:28,代码来源:PingCommand.java

示例6: handleCoinToss

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
private void handleCoinToss(@NotNull MessageReceivedEvent event, @NotNull List<String> args) {
    int iterations = 1;
    if (args.size() > 1 && INT_PATTERN.matcher(args.get(1)).find()) {
        iterations = Math.min(12, Integer.parseUnsignedInt(args.get(1)));
    }
    int sIterations = 0;
    ThreadLocalRandom random = ThreadLocalRandom.current();
    EmbedBuilder builder = MessageUtils.getEmbedBuilder(event.getMessage().getAuthor());
    int heads = 0;
    int tails = 0;
    while (sIterations++ != iterations) {
        boolean res = random.nextBoolean();

        if (res) heads++;
        else tails++;

        builder.appendField("Round " + (sIterations), res ? "Head" : "Tail", true);
    }
    builder.withTitle("Tossed " + (sIterations - 1) + (sIterations == 1 ? " coin" : " coins"));
    builder.withDescription("Heads: " + heads + ". Tails: " + tails);

    sendThenDelete(MessageUtils.getMessageBuilder(event.getMessage())
            .withEmbed(builder.build()));
    delete(event.getMessage());
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:26,代码来源:RandomNumberCommand.java

示例7: handleDiceRoll

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
private void handleDiceRoll(@NotNull MessageReceivedEvent event, @NotNull List<String> args) {
    int upper = Integer.parseUnsignedInt(args.get(0).substring(2));
    int iterations = 1;
    if (args.size() > 1 && INT_PATTERN.matcher(args.get(1)).find()) {
        iterations = Math.min(12, Integer.parseUnsignedInt(args.get(1)));
    }
    int sIterations = iterations;
    ThreadLocalRandom random = ThreadLocalRandom.current();
    EmbedBuilder builder = MessageUtils.getEmbedBuilder(event.getMessage().getAuthor());
    int sum = 0;
    while (iterations-- != 0) {
        int num = random.nextInt(1, upper + 1);
        sum += num;
        builder.appendField(":game_die: [1," + upper + "]", num + "", true);
    }
    builder.withTitle("Tossed " + sIterations + (sIterations == 1 ? " dice" : " dices"));
    builder.withDescription("Average result: " + (sum / sIterations));

    sendThenDelete(MessageUtils.getMessageBuilder(event.getMessage())
            .withEmbed(builder.build()));
    delete(event.getMessage());
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:23,代码来源:RandomNumberCommand.java

示例8: onMessageReceived

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
@EventSubscriber
public void onMessageReceived(MessageReceivedEvent event) {
    if (discordService.isOwnUser(event.getMessage().getAuthor())) {
        return;
    }
    IMessage m = event.getMessage();
    String content = m.getContent();
    Optional<Command> match = commandList.stream().filter(c -> c.matches(content)).findFirst();
    if (match.isPresent()) {
        Command command = match.get();
        CompletableFuture.runAsync(() -> tryExecute(event, command), taskExecutor)
            .exceptionally(t -> {
                log.warn("Something happened while trying to execute command", t);
                return null;
            });
    }
}
 
开发者ID:quanticc,项目名称:ugc-bot-redux,代码行数:18,代码来源:CommandService.java

示例9: handle

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
@Override
public void handle(MessageReceivedEvent event) {
	if (!event.getMessage().getAuthor().equals(user))
		return;

	if (!event.getMessage().getContent().startsWith(bot.getPrefixForGuild(channel.getGuild()))) {

		act(event);

		channel.getClient().getDispatcher().unregisterListener(this);
		ProfileCommand.editMenus.remove(user.getID(), this);

		Userdata.setGson("profile_" + user.getID(), profile);
		Userdata.instance().save();
	}
}
 
开发者ID:chrislo27,项目名称:Baristron,代码行数:17,代码来源:ProfileCommand.java

示例10: onMessageReceivedEvent

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
@EventSubscriber
public void onMessageReceivedEvent(MessageReceivedEvent event) {
    IMessage m = event.getMessage();
    ChannelConfig cc = wrapper.getChannel(m.getChannel().getID());

    // Don't listen to this event if the channel is not configured, or
    // we are not listening to the channel
    if(cc == null || !cc.isDiscordListen()) {
        return;
    }

    // Not listening to our messages
    if(m.getAuthor().getID().equals(wrapper.getClient().getOurUser().getID())) {
        return;
    }

    // Send message to Minecraft
    String msgLog = cc.getPrefix() + m.getAuthor().getName() + ": " + m.getContent();
    plugin.getServer().broadcastMessage(msgLog);
}
 
开发者ID:jkcgs,项目名称:DiscordChat,代码行数:21,代码来源:DiscordListener.java

示例11: answerWithError

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
private void answerWithError(@NotNull MessageReceivedEvent event, String message) throws RateLimitException, DiscordException, MissingPermissionsException {
    new MessageBuilder(event.getClient())
            .appendContent("Error")
            .appendQuote(message)
            .withChannel(event.getMessage().getChannel())
            .send();
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:8,代码来源:LeagueCommandHandler.java

示例12: handle

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
@Override
public boolean handle(MessageReceivedEvent event, String command, String matchedText) {
    /*IMessage message = event.getMessage();
    Matcher matcher = Regexes.SIMPLE_ARGS.getRegex().matcher(message.getContent().trim());

    if (matcher.find()) {
        EventUtils.logMessageEventReceived(event, this.getClass());
        try {
            String[] command = matcher.group(1).split("::");
            if (command.length < 2 || !StringUtils.startsWithIgnoreCase(command[0], "league")) {
                return;
            }
            switch (command[1].toLowerCase()) {
                case "stats":
                    if (command.length < 3) {
                        answerWithError(event, ErrorMessages.MISSING_LADDER);
                        return;
                    } else if (!LADDER_VALUE_PATTERN.matcher(command[2]).find()) {
                        answerWithError(event, ErrorMessages.WRONG_FORMAT_LADDER);
                        return;
                    }
                    String ladder = command[2].split("=")[1];
                    showRandedStats(event, ladder, matcher.group(2));
                default:
                    break;
            }
        } catch (Exception e) {
            LOGGER.error("Failed during " + this.getClass().getSimpleName() + " event handling.", e);
        }
    }*/
    return false;
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:33,代码来源:LeagueCommandHandler.java

示例13: shortenURL

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
private void shortenURL(@NotNull MessageReceivedEvent event, String url) throws RateLimitException, DiscordException, MissingPermissionsException {
    if (!UrlValidator.getInstance().isValid(url)) {
        EventUtils.sendIncorrectUsageMessage(event.getClient(), event.getMessage().getChannel(), "ShortUrl", "URL is not a valid http/https URL!");
        return;
    }
    try {
        Url shortUrl = GoogleClientServiceFactory.getInstance().getUrlShortenerService()
                                                 .url()
                                                 .insert(new Url().setLongUrl(url))
                                                 .execute();

        @NotNull StringBuilder builder = new StringBuilder(StringUtils.defaultIfEmpty(shortUrl.getId(), "URL was removed by google."));

        if (shortUrl.getStatus() != null && !"OK".equalsIgnoreCase(shortUrl.getStatus())) {
            builder.append("\n")
                   .append("Attention:")
                   .append("   ")
                   .append(shortUrl.getStatus());
        }

        new MessageBuilder(event.getClient())
                .withChannel(event.getMessage().getChannel())
                .withContent("Short URL: ")
                .appendContent(builder.toString(), Styles.UNDERLINE)
                .appendContent("\n")
                .appendContent("Full URL: ")
                .appendContent(url, Styles.UNDERLINE)
                .send();

    } catch (IOException e) {
        logger.error("I/O Error during call to URLShortening service", e);
        new MessageBuilder(event.getClient())
                .withChannel(event.getMessage().getChannel())
                .withContent("Fail during google URL Shortening API Contact.")
                .send();
    }
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:38,代码来源:GoogleCommandHandler.java

示例14: showInfo

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
private void showInfo(@org.jetbrains.annotations.NotNull @NotNull MessageReceivedEvent event, boolean verbose) throws RateLimitException, DiscordException, MissingPermissionsException {
    @org.jetbrains.annotations.NotNull StringBuilder builder = new StringBuilder(verbose ? 300 : 150);
    @org.jetbrains.annotations.NotNull EventManager manager = EventManager.getInstance();
    builder.append(manager.getName())
            .append(" - Version: ")
            .append(manager.getVersion())
            .append(lineSeparator())
            .append("Created by: ")
            .append(manager.getAuthor())
            .append(lineSeparator());
    if (verbose) {
        builder.append("Uptime: ").append(ManagementFactory.getRuntimeMXBean().getUptime())
                .append(" (Since: ").append(DATE_TIME_FORMATTER.format(ZonedDateTime.now())).append(')')
                .append(lineSeparator())
                .append("Commands Handled: ").append(StatsCounter.commandsHandled())
                .append(lineSeparator())
                .append("Commands handle time :")
                .append(lineSeparator())
                .append("Max: ").append(TimeUtils.formatToString(StatsCounter.maxCommandHandleTime())).append(' ')
                .append("Mean: ").append(TimeUtils.formatToString(StatsCounter.meanCommandHandleTime())).append(' ')
                .append("Min: ").append(TimeUtils.formatToString(StatsCounter.minCommandHandleTime())).append(' ')
                .append(lineSeparator());
    }
    builder.append("   Have fun!");

    new MessageBuilder(event.getClient())
            .appendQuote(builder.toString())
            .withChannel(event.getMessage().getChannel())
            .send();
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:31,代码来源:BotInfoCommandHandler.java

示例15: degelateCommand

import sx.blah.discord.handle.impl.events.MessageReceivedEvent; //导入依赖的package包/类
public final boolean degelateCommand(MessageReceivedEvent event, String command, String matchedText) {
    EntryMessage entryMessage = logger.traceEntry("CommandDelegator will delegate command {}.", matchedText);

    int handleCount = 0;
    for (@NotNull ICommandHandler handler : HANDLERS) {
        try {
            if (handler.handle(event, command, matchedText)) {
                handleCount++;
            }
        } catch (Exception e) {
            logger.error("Handler " + handler.getClass().getSimpleName() + " failed to handle command.", e);
        }
    }
    return logger.traceExit(entryMessage, handleCount > 0);
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:16,代码来源:CommandDelegator.java


注:本文中的sx.blah.discord.handle.impl.events.MessageReceivedEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。