本文整理汇总了Java中de.btobastian.sdcf4j.Command.async方法的典型用法代码示例。如果您正苦于以下问题:Java Command.async方法的具体用法?Java Command.async怎么用?Java Command.async使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类de.btobastian.sdcf4j.Command
的用法示例。
在下文中一共展示了Command.async方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMessageCreate
import de.btobastian.sdcf4j.Command; //导入方法依赖的package包/类
/**
* Handles a received message.
*
* @param api The api.
* @param message The received message.
*/
private void handleMessageCreate(DiscordApi api, final Message message) {
if (message.getUserAuthor().map(User::isYourself).orElse(false)) {
return;
}
String[] splitMessage = message.getContent().split("[\\s&&[^\\n]]++");
String commandString = splitMessage[0];
SimpleCommand command = commands.get(commandString.toLowerCase());
if (command == null) {
// maybe it requires a mention
if (splitMessage.length > 1) {
command = commands.get(splitMessage[1].toLowerCase());
if (command == null || !command.getCommandAnnotation().requiresMention()) {
return;
}
// remove the first which is the mention
splitMessage = Arrays.copyOfRange(splitMessage, 1, splitMessage.length);
} else {
return;
}
}
Command commandAnnotation = command.getCommandAnnotation();
if (commandAnnotation.requiresMention() && !commandString.equals(api.getYourself().getMentionTag())) {
return;
}
if (message.getPrivateChannel().isPresent() && !commandAnnotation.privateMessages()) {
return;
}
if (!message.getPrivateChannel().isPresent() && !commandAnnotation.channelMessages()) {
return;
}
if (!hasPermission(message.getUserAuthor().map(User::getId).map(String::valueOf).orElse("-1"), commandAnnotation.requiredPermissions())) {
if (Sdcf4jMessage.MISSING_PERMISSIONS.getMessage() != null) {
message.getChannel().sendMessage(Sdcf4jMessage.MISSING_PERMISSIONS.getMessage());
}
return;
}
final Object[] parameters = getParameters(splitMessage, command, message, api);
if (commandAnnotation.async()) {
final SimpleCommand commandFinal = command;
api.getThreadPool().getExecutorService().submit(() -> invokeMethod(commandFinal, message, parameters));
} else {
invokeMethod(command, message, parameters);
}
}
示例2: handleMessageCreate
import de.btobastian.sdcf4j.Command; //导入方法依赖的package包/类
/**
* Handles a received message.
*
* @param event The MessageReceivedEvent.
*/
private void handleMessageCreate(final MessageReceivedEvent event) {
JDA jda = event.getJDA();
if (event.getAuthor() == jda.getSelfUser()) {
return;
}
String[] splitMessage = event.getMessage().getContentRaw().split("[\\s&&[^\\n]]++");
String commandString = splitMessage[0];
SimpleCommand command = commands.get(commandString.toLowerCase());
if (command == null) {
// maybe it requires a mention
if (splitMessage.length > 1) {
command = commands.get(splitMessage[1].toLowerCase());
if (command == null || !command.getCommandAnnotation().requiresMention()) {
return;
}
// remove the first which is the mention
splitMessage = Arrays.copyOfRange(splitMessage, 1, splitMessage.length);
} else {
return;
}
}
Command commandAnnotation = command.getCommandAnnotation();
if (commandAnnotation.requiresMention() && !commandString.equals(jda.getSelfUser().getAsMention())) {
return;
}
if (event.isFromType(ChannelType.PRIVATE) && !commandAnnotation.privateMessages()) {
return;
}
if (!event.isFromType(ChannelType.PRIVATE) && !commandAnnotation.channelMessages()) {
return;
}
if (!hasPermission(event.getAuthor(), commandAnnotation.requiredPermissions())) {
if (Sdcf4jMessage.MISSING_PERMISSIONS.getMessage() != null) {
event.getChannel().sendMessage(Sdcf4jMessage.MISSING_PERMISSIONS.getMessage()).queue();
}
return;
}
final Object[] parameters = getParameters(splitMessage, command, event);
if (commandAnnotation.async()) {
final SimpleCommand commandFinal = command;
Thread t = new Thread(() -> invokeMethod(commandFinal, event, parameters));
t.setDaemon(true);
t.start();
} else {
invokeMethod(command, event, parameters);
}
}
示例3: handleMessageCreate
import de.btobastian.sdcf4j.Command; //导入方法依赖的package包/类
/**
* Handles a received message.
*
* @param event The MessageReceivedEvent.
*/
private void handleMessageCreate(final MessageReceivedEvent event) {
String[] splitMessage = event.getMessage().getContent().split("[\\s&&[^\\n]]++");
String commandString = splitMessage[0];
SimpleCommand command = commands.get(commandString.toLowerCase());
if (command == null) {
// maybe it requires a mention
if (splitMessage.length > 1) {
command = commands.get(splitMessage[1].toLowerCase());
if (command == null || !command.getCommandAnnotation().requiresMention()) {
return;
}
// remove the first which is the mention
splitMessage = Arrays.copyOfRange(splitMessage, 1, splitMessage.length);
} else {
return;
}
}
Command commandAnnotation = command.getCommandAnnotation();
if (commandAnnotation.requiresMention() &&
!commandString.equals("<@" + event.getClient().getOurUser().getStringID() + ">")) {
return;
}
if (event.getMessage().getChannel().isPrivate() && !commandAnnotation.privateMessages()) {
return;
}
if (!event.getMessage().getChannel().isPrivate() && !commandAnnotation.channelMessages()) {
return;
}
if (!hasPermission(event.getMessage().getAuthor(), commandAnnotation.requiredPermissions())) {
if (Sdcf4jMessage.MISSING_PERMISSIONS.getMessage() != null) {
try {
event.getMessage().getChannel().sendMessage(Sdcf4jMessage.MISSING_PERMISSIONS.getMessage());
} catch (MissingPermissionsException | RateLimitException | DiscordException ignored) { }
}
return;
}
final Object[] parameters = getParameters(splitMessage, command, event);
if (commandAnnotation.async()) {
final SimpleCommand commandFinal = command;
Thread t = new Thread(() -> {
invokeMethod(commandFinal, event, parameters);
});
t.setDaemon(true);
t.start();
} else {
invokeMethod(command, event, parameters);
}
}