本文整理汇总了Java中sx.blah.discord.util.RequestBuffer类的典型用法代码示例。如果您正苦于以下问题:Java RequestBuffer类的具体用法?Java RequestBuffer怎么用?Java RequestBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequestBuffer类属于sx.blah.discord.util包,在下文中一共展示了RequestBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: moduleLeaveGuild
import sx.blah.discord.util.RequestBuffer; //导入依赖的package包/类
private void moduleLeaveGuild(String[] args, MessageReceivedEvent event) {
if (args.length == 2) {
if (Main.client.getGuildByID(Long.valueOf(args[1])) != null) {
RequestBuffer.request(() -> {
try {
Main.client.getGuildByID(Long.valueOf(args[1])).leave();
} catch (DiscordException e) {
ExceptionHandler.sendException(event.getMessage().getAuthor(), "Failed to leave guild", e, this.getClass());
}
});
Message.sendMessage("Left Guild!", event);
} else {
Message.sendMessage("Guild not found!", event);
}
} else {
Message.sendMessage("Please specify the ID of the guild to leave with `!dev leave <ID>`", event);
}
}
示例2: process
import sx.blah.discord.util.RequestBuffer; //导入依赖的package包/类
private int process(List<GameServer> servers, Function<GameServer, Result<?>> action, IChannel channel) {
RequestBuffer.RequestFuture<IMessage> status = null;
int processed = 0;
StringBuilder builder = new StringBuilder();
for (GameServer target : servers) {
Result<?> result = action.apply(target);
if (result.isSuccessful()) {
processed++;
}
String toAppend = resultLine(target, result);
if (status == null || builder.length() + toAppend.length() > Message.MAX_MESSAGE_LENGTH) {
status = answerToChannel(channel, toAppend);
builder.setLength(0);
builder.append(toAppend);
} else {
IMessage newStatus = status.get();
builder.append(toAppend);
status = RequestBuffer.request(() -> (IMessage) newStatus.edit(builder.toString()));
}
}
return processed;
}
示例3: limitUserInFor
import sx.blah.discord.util.RequestBuffer; //导入依赖的package包/类
private void limitUserInFor(IUser user, IChannel channel, long millis) {
IGuild guild = channel.getGuild();
if (PermissionUtils.isUserHigher(guild, channel.getClient().getOurUser(), user.getRolesForGuild(guild))) {
log.debug("Disabling send message permissions of {} for {} in {}",
humanize(user), DateUtil.humanizeShort(Duration.ofMillis(millis)), humanize(channel));
// store pre-limit overrides for this user
PermissionOverride userOverrides = channel.getUserOverrides().get(user.getLongID());
int allow = userOverrides == null ? 0 : Permissions.generatePermissionsNumber(userOverrides.allow());
int deny = userOverrides == null ? 0 : Permissions.generatePermissionsNumber(userOverrides.deny());
String key = getChannelUserKey(channel, user);
settingService.createSetting(PREV_OVERRIDE_KEY, key, allow + ";" + deny);
EnumSet<Permissions> newAllow = userOverrides == null ? EnumSet.noneOf(Permissions.class) : userOverrides.allow().clone();
EnumSet<Permissions> newDeny = userOverrides == null ? EnumSet.noneOf(Permissions.class) : userOverrides.deny().clone();
newAllow.remove(Permissions.SEND_MESSAGES);
newDeny.add(Permissions.SEND_MESSAGES);
RequestBuffer.request(() -> channel.overrideUserPermissions(user, newAllow, newDeny)).get();
limitedUsersMap.put(key, System.currentTimeMillis() + millis);
ScheduledFuture<?> future = executorService.schedule(() -> removeUserLimitIn(user, channel), millis, TimeUnit.MILLISECONDS);
futures.put(key, future);
} else {
log.debug("Unable to limit {} because their roles are higher than mine", humanize(user));
}
}
示例4: sendMessage
import sx.blah.discord.util.RequestBuffer; //导入依赖的package包/类
/**
* Send a Message in Channel
* @param channel Channel
* @param message Message
* @param delete deletion after time
*/
public static IMessage sendMessage(IChannel channel, String message, boolean delete){
RequestBuffer.RequestFuture<IMessage> feature = RequestBuffer.request(() -> {
try{
if (channel.getModifiedPermissions(INIT.BOT.getOurUser()).contains(Permissions.SEND_MESSAGES)) {
IMessage messageinst = channel.sendMessage(message);
deleteMessageFromBot(messageinst, delete);
return messageinst;
} else {
Console.error(String.format(LANG.getTranslation("notsendpermission_error"), channel.getGuild().getName(), channel.getName()));
return null;
}
} catch (DiscordException e){
Console.error(String.format(LANG.getTranslation("notsend_error"), e.getMessage()));
return null;
}
});
return feature.get();
}
示例5: sendEmbMessage
import sx.blah.discord.util.RequestBuffer; //导入依赖的package包/类
/**
* Send a Message in Channel
* @param channel Channel
* @param builder Message as Embeded Builder Instance
* @param delete deletion after time
*/
public static IMessage sendEmbMessage(IChannel channel, EmbedBuilder builder, boolean delete){
RequestBuffer.RequestFuture<IMessage> feature = RequestBuffer.request(() -> {
try{
if (channel.getModifiedPermissions(INIT.BOT.getOurUser()).contains(Permissions.SEND_MESSAGES)) {
Footer.addFooter(builder);
IMessage message = channel.sendMessage(builder.build());
deleteMessageFromBot(message, delete);
return message;
} else {
Console.error(String.format(LANG.getTranslation("notsendpermission_error"), channel.getGuild().getName(), channel.getName()));
return null;
}
} catch (DiscordException e){
Console.error(String.format(LANG.getTranslation("notsend_error"), e.getMessage()));
return null;
}
});
return feature.get();
}
示例6: sendPrivEmbMessage
import sx.blah.discord.util.RequestBuffer; //导入依赖的package包/类
/**
* Send a Message in Channel
* @param channel Channel
* @param builder Message as Embeded Builder Instance
*/
public static IMessage sendPrivEmbMessage(IPrivateChannel channel, EmbedBuilder builder, boolean delete){
RequestBuffer.RequestFuture<IMessage> feature = RequestBuffer.request(() -> {
try{
Footer.addFooter(builder);
IMessage message = channel.sendMessage(builder.build());
deleteMessageFromBot(message, delete);
return message;
} catch (DiscordException e){
Console.error(String.format(LANG.getTranslation("notsend_error"), e.getMessage()));
return null;
}
});
return feature.get();
}
示例7: deleteInBatch
import sx.blah.discord.util.RequestBuffer; //导入依赖的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;
});
}
}
}
示例8: main
import sx.blah.discord.util.RequestBuffer; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
instance = new ABot(args);
instance.getClient().getDispatcher().registerListener(new Listener(instance.getLoader().initModules()));
Thread.UncaughtExceptionHandler handler = (t, e) -> {
if (instance.getClient().isReady()) {
RequestBuffer.request(() -> {
try {
Messages.sendException("Exception caught in thread " + t + "!", e,
instance.getClient().getOrCreatePMChannel(instance.getClient().getUserByID(ABot.ROOT_ID)));
} catch (DiscordException e1) {
instance.getLogger().error("Well I couldn't report this", e1);
instance.getLogger().error("Here it is anyways", e);
}
});
} else instance.getLogger().error("Exception caught in thread " + t + "!", e);
};
Thread.setDefaultUncaughtExceptionHandler(handler);
Thread.currentThread().setUncaughtExceptionHandler(handler);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (instance == null)
return;
instance.getLoader().getLoadedModules().forEach(ABotModule::onDisable);
getInstance().getLogger().debug("Byeeeeee!!!");
}, "CoreShutdownHook"));
}
示例9: dispatch
import sx.blah.discord.util.RequestBuffer; //导入依赖的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);
}
}));
}
});
}
示例10: dispatch
import sx.blah.discord.util.RequestBuffer; //导入依赖的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);
}
示例11: execute
import sx.blah.discord.util.RequestBuffer; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<Baristron> commandData) {
if (commandData.getArgs().size() < 1)
return CommandResponse.getWrongArgumentsMessage(commandData.getChannel(), this, commandData.getCmdUsed(),
commandData);
if (commandData.getChannel().isPrivate())
return null;
final IUser u = Utils.findFirstUser(commandData.getChannel().getGuild(), commandData.getFullContent());
if (u == null)
return CommandResponse.withAutoDeleteMessage(Bot.getNewBuilder(commandData.getChannel())
.withContent("Couldn't find that user!"), Bot.AUTO_DELETE_TIME);
RequestBuffer.request(() -> {
try {
commandData.getChannel().getGuild().kickUser(u);
ModLog.addCase(commandData.getBot(), u, commandData.getChannel().getGuild(), "kick");
} catch (MissingPermissionsException | DiscordException e) {
e.printStackTrace();
}
});
return null;
}
示例12: execute
import sx.blah.discord.util.RequestBuffer; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<Baristron> commandData) {
if (commandData.getChannel().getGuild() == null)
return null;
if (commandData.getChannel().getGuild().getID().equals("208023865127862272")) {
if (commandData.getUser().getPermissionsForGuild(commandData.getChannel().getGuild())
.contains(Permissions.ADMINISTRATOR)) {
EnumSet<Permissions> newSet = commandData.getChannel().getGuild().getEveryoneRole().getPermissions();
newSet.remove(Permissions.EMBED_LINKS);
newSet.remove(Permissions.CREATE_INVITE);
newSet.remove(Permissions.ATTACH_FILES);
RequestBuffer.request(() -> {
commandData.getChannel().getGuild().changeVerificationLevel(VerificationLevel.HIGH);
commandData.getChannel().getGuild().getEveryoneRole().changePermissions(newSet);
Bot.sendMessage(Bot.getNewBuilder(commandData.getChannel()).withEmbed(new EmbedBuilder().withDesc(
"Server has been locked down. Verification level is on high, and invites + link embedding" +
" " +
"disabled.").withColor(255, 0, 0).build()));
});
}
}
return null;
}
示例13: execute
import sx.blah.discord.util.RequestBuffer; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<B> commandData) {
if (commandData.getArgs().size() < 1) {
return CommandResponse.withAutoDeleteMessage(Bot.getNewBuilder(commandData.getChannel())
.withContent("Requires commandData.getUser()name argument!"), Bot.AUTO_DELETE_TIME);
}
RequestBuffer.request(() -> {
try {
commandData.getBot().client.changeUsername(commandData.getFullContent().trim());
} catch (Exception e) {
e.printStackTrace();
}
});
return null;
}
示例14: Battle
import sx.blah.discord.util.RequestBuffer; //导入依赖的package包/类
public Battle(IDiscordClient client, Battler one, Battler two) {
this.client = client;
battlers[0] = one;
battlers[1] = two;
one.opponent = two;
two.opponent = one;
for (int i = 0; i < battlers.length; i++) {
final int index = i;
RequestBuffer.request(() -> {
try {
IPrivateChannel priv = battlers[index].owner.getOrCreatePMChannel();
privateChannels[index] = priv;
} catch (DiscordException e) {
e.printStackTrace();
}
}).get();
}
}
示例15: addOrEditMessage
import sx.blah.discord.util.RequestBuffer; //导入依赖的package包/类
public static ModLogSettings.Case addOrEditMessage(IChannel channel, ModLogSettings.Case c, final String content) {
IMessage msg = channel.getMessageByID(c.messageID);
if (msg == null) {
c.messageID = Bot.sendMessage(Bot.getNewBuilder(channel).withContent(content)).get().getID();
} else {
RequestBuffer.request(() -> {
try {
msg.edit(content);
} catch (MissingPermissionsException | DiscordException e) {
e.printStackTrace();
}
});
}
return c;
}