本文整理汇总了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();
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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());
}
示例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());
}
示例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;
});
}
}
示例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();
}
}
示例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);
}
示例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();
}
示例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;
}
示例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();
}
}
示例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();
}
示例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);
}