本文整理汇总了Java中sx.blah.discord.util.MissingPermissionsException类的典型用法代码示例。如果您正苦于以下问题:Java MissingPermissionsException类的具体用法?Java MissingPermissionsException怎么用?Java MissingPermissionsException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MissingPermissionsException类属于sx.blah.discord.util包,在下文中一共展示了MissingPermissionsException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendConnectionErrorMessage
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的package包/类
public static void sendConnectionErrorMessage(IDiscordClient client, IChannel channel, String command, @Nullable String message, @NotNull HttpStatusException httpe) throws RateLimitException, DiscordException, MissingPermissionsException {
@NotNull String problem = message != null ? message + "\n" : "";
if (httpe.getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
problem += "Service unavailable, please try again latter.";
} else if (httpe.getStatusCode() == HttpStatus.SC_FORBIDDEN) {
problem += "Acess dennied.";
} else if (httpe.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
problem += "Not Found";
} else {
problem += httpe.getStatusCode() + SPACE + httpe.getMessage();
}
new MessageBuilder(client)
.appendContent("Error during HTTP Connection ", MessageBuilder.Styles.BOLD)
.appendContent("\n")
.appendContent(EventManager.MAIN_COMMAND_NAME, MessageBuilder.Styles.BOLD)
.appendContent(SPACE)
.appendContent(command, MessageBuilder.Styles.BOLD)
.appendContent("\n")
.appendContent(problem, MessageBuilder.Styles.BOLD)
.withChannel(channel)
.send();
}
示例2: showHelpIfPresent
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的package包/类
public boolean showHelpIfPresent(IDiscordClient client, IChannel channnel, @NotNull CommandLine cmd) throws RateLimitException, DiscordException, MissingPermissionsException {
if (cmd.hasOption("h") || cmd.hasOption("help") || cmd.hasOption("showHelp")) {
@NotNull StringWriter writter = new StringWriter(200);
@NotNull PrintWriter pw = new PrintWriter(writter);
new HelpFormatter()
.printHelp(pw, 200,
EventManager.MAIN_COMMAND_NAME + " " + this.mainCommand,
this.commandInfo,
this.options,
3,
5,
null,
true);
new MessageBuilder(client)
.withChannel(channnel)
.withQuote(writter.toString())
.send();
return true;
}
return false;
}
示例3: sendHelloWorld
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的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();
}
示例4: handle
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的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;
}
示例5: handle
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的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: action
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的package包/类
public static void action(final Predicate<Channel> filter, final Consumer<IChannel> a) {
EEWBot.instance.getChannels().entrySet()
.forEach(entry -> {
final IGuild guild = EEWBot.instance.getClient().getGuildByID(entry.getKey());
if (guild!=null)
entry.getValue().stream().filter(filter)
.forEach(channel -> {
final IChannel dc = guild.getChannelByID(channel.id);
if (dc!=null)
try {
a.accept(dc);
} catch (final MissingPermissionsException ex) {
Log.logger.warn("権限がありません: "+guild.getName()+" #"+dc.getName());
}
});
});
}
示例7: invokeMethod
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的package包/类
/**
* Invokes the method of the command.
*
* @param command The command.
* @param event The event.
* @param parameters The parameters for the method.
*/
private void invokeMethod(SimpleCommand command, MessageReceivedEvent event, Object[] parameters) {
Method method = command.getMethod();
Object reply = null;
try {
method.setAccessible(true);
reply = method.invoke(command.getExecutor(), parameters);
} catch (IllegalAccessException | InvocationTargetException e) {
Discord4J.LOGGER.warn("Cannot invoke method {}!", method.getName(), e);
}
if (reply != null) {
try {
event.getMessage().getChannel().sendMessage(String.valueOf(reply));
} catch (MissingPermissionsException | RateLimitException | DiscordException ignored) { }
}
}
示例8: commonReply
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的package包/类
private CompletableFuture<IMessage> commonReply(IMessage message, Command command, String response, File file) throws InterruptedException, DiscordException, MissingPermissionsException {
ReplyMode replyMode = command.getReplyMode();
if (replyMode == ReplyMode.PRIVATE) {
// always to private - so ignore all permission calculations
return answerPrivately(message, response, file);
} else if (replyMode == ReplyMode.ORIGIN) {
// use the same channel as invocation
return answer(message, response, command.isMention(), file);
} else if (replyMode == ReplyMode.PERMISSION_BASED) {
// the channel must have the needed permission, otherwise fallback to a private message
if (permissionService.canDisplayResult(command, message.getChannel())) {
return answer(message, response, command.isMention(), file);
} else {
return answerPrivately(message, response, file);
}
} else {
log.warn("This command ({}) has an invalid reply-mode: {}", command.getKey(), command.getReplyMode());
return answerPrivately(message, response, null);
}
}
示例9: onUserSpeaking
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的package包/类
@EventSubscriber
public void onUserSpeaking(VoiceUserSpeakingEvent event) {
if (!event.isSpeaking()) {
SettingsService.ResponseConfig config = settingsService.getSettings()
.getUserToVoiceResponse().get(event.getUser().getID());
if (config != null) {
List<String> responses = config.getResponses();
if (!responses.isEmpty() && RandomUtils.nextInt(0, 100) < config.getChance()) {
String text = (responses.size() == 1 ? responses.get(0) :
responses.get(RandomUtils.nextInt(0, responses.size())));
try {
discordService.sendMessage(config.getChannelId(), text);
} catch (DiscordException | MissingPermissionsException | InterruptedException e) {
log.warn("Could not send voice response", e);
}
}
}
}
}
示例10: deleteInBatch
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的package包/类
public static void deleteInBatch(IChannel channel, List<IMessage> toDelete) {
if (toDelete.isEmpty()) {
log.info("No messages to delete");
} else {
log.info("Preparing to delete {} messages from {}", toDelete.size(), DiscordUtil.toString(channel));
for (int x = 0; x < (toDelete.size() / 100) + 1; x++) {
List<IMessage> subList = toDelete.subList(x * 100, Math.min(toDelete.size(), (x + 1) * 100));
RequestBuffer.request(() -> {
try {
acquireDelete();
channel.getMessages().bulkDelete(subList);
} catch (MissingPermissionsException | DiscordException e) {
log.warn("Failed to delete message", e);
}
return null;
});
}
}
}
示例11: dispatch
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的package包/类
@Override
public void dispatch(String[] args, IUser sender, IChannel channel) {
RequestBuffer.request(() -> {
try {
channel.getMessages().bulkDelete(channel.getMessages().stream().filter((message) -> message.getAuthor()
.equals(Launcher.getInstance().getClient().getOurUser())).collect(Collectors.toList()));
} catch (DiscordException | MissingPermissionsException ignored) {
AtomicBoolean cont = new AtomicBoolean(true);
channel.getMessages().stream().filter((message) -> message.getAuthor()
.equals(Launcher.getInstance().getClient().getOurUser()))
.forEach((message) -> RequestBuffer.request(() -> {
if (cont.get())
try {
message.delete();
} catch (MissingPermissionsException | DiscordException e1) {
Messages.sendException("**Could not purge!**", e1, channel);
}
}));
}
});
}
示例12: dispatch
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的package包/类
@Override
public void dispatch(String[] args, IUser sender, IChannel channel) {
if (args.length > 0) {
String nick = "";
for (String s : args) {
nick += s + ' ';
}
nick = nick.trim();
String finalNick = nick;
RequestBuffer.request(() -> {
try {
channel.getGuild().setUserNickname(Launcher.getInstance().getClient().getOurUser(), finalNick);
} catch (MissingPermissionsException | DiscordException e) {
Messages.sendException("Could not edit my own nickname :'(", e, channel);
}
});
} else Messages.send("You need to provide a nickname!", channel);
}
示例13: processCommand
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的package包/类
@Override
public void processCommand(IMessage message, String[] args) {
IGuild guild = message.getGuild();
String name = "";
try {
if (args.length > 1) {
name = args[1];
if (args.length > 2) {
name = name(args[1], args[2]);
if (args.length > 3) {
name = name(args[1], args[2], args[3]);
if (args.length > 4)
name = name(args[1], args[2], args[3], args[4]);
}
}
}
guild.changeName(name);
} catch (RateLimitException | DiscordException | MissingPermissionsException e) {
e.printStackTrace();
}
}
示例14: sendMessage
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的package包/类
public static void sendMessage(IChannel channel, String message, EmbedObject object) {
if (message.length() > 2000 || object.description.length() > 2000) {
Utilities.sendMessage(channel, "I tried to send a message, but it was too long. " + message.length() + "/2000 chars! Embedded: " + object.description.length() + "/2000!");
Discord4J.LOGGER.info(message);
Discord4J.LOGGER.info(object.description);
return;
}
try {
channel.sendMessage(message, object, false);
Thread.sleep(1000);
} catch (RateLimitException | DiscordException | MissingPermissionsException | InterruptedException e) {
e.printStackTrace();
}
}
示例15: execute
import sx.blah.discord.util.MissingPermissionsException; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<Baristron> commandData) {
if (commandData.getChannel().isPrivate())
return null;
if (commandData.getArgs().size() == 0)
return CommandResponse
.getWrongArgumentsMessage(commandData.getChannel(), this, commandData.getCmdUsed(), commandData);
try {
// DiscordUtils.checkPermissions(commandData.getBot().client, commandData.getChannel().getGuild(),
// commandData.getUser().getRolesForGuild(commandData.getChannel().getGuild()),
// EnumSet.of(Permissions.BAN));
commandData.getChannel().getGuild().banUser(Long.parseUnsignedLong(commandData.getArgs().get(0)),
(commandData.getArgs().size() >= 2 ? Integer.parseInt(commandData.getArgs().get(1)) : 0));
} catch (MissingPermissionsException | DiscordException | RateLimitException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return null;
}