本文整理汇总了Java中sx.blah.discord.util.RequestBuffer.request方法的典型用法代码示例。如果您正苦于以下问题:Java RequestBuffer.request方法的具体用法?Java RequestBuffer.request怎么用?Java RequestBuffer.request使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sx.blah.discord.util.RequestBuffer
的用法示例。
在下文中一共展示了RequestBuffer.request方法的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: 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();
}
示例4: 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();
}
示例5: 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;
});
}
}
}
示例6: sendMessage
import sx.blah.discord.util.RequestBuffer; //导入方法依赖的package包/类
/**
* Send a message to a channel
* @param channel Channel target
* @param content Content of message
* @param embed EmbedObject to format with
*/
private static void sendMessage(IChannel channel, String content, EmbedObject embed, boolean bypass) {
if(!bypass)
content = content.replaceAll("@", "\\\\@");
if(content.equals("") && embed == null)
return;
final String s = content;
RequestBuffer.request(() -> {
try {
new MessageBuilder(Bot.getInstance().getBot()).withChannel(channel).withContent(s).withEmbed(embed).build();
} catch (MissingPermissionsException | DiscordException e) {
e.printStackTrace();
return;
}
});
}
示例7: 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"));
}
示例8: 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);
}
}));
}
});
}
示例9: 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);
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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;
}
示例14: sendEmbeddedMessage
import sx.blah.discord.util.RequestBuffer; //导入方法依赖的package包/类
/**
* Sends an embedded message to a certain user
*
* @param channel text channel
* @param embeddedMessage encapsulated embedded message
*/
public void sendEmbeddedMessage(IChannel channel,
EmbeddedMessage embeddedMessage) {
EmbedBuilder builder = new EmbedBuilder();
builder.appendField(embeddedMessage.getTitle(),
embeddedMessage.getMessage(), false);
builder.withImage(embeddedMessage.getImage());
RequestBuffer.request(() -> channel.sendMessage(builder.build()));
}
示例15: runBattle
import sx.blah.discord.util.RequestBuffer; //导入方法依赖的package包/类
private IMessage runBattle(CommandContext ctx, long time, Emoji choice1, Emoji choice2, BattleMessageSupplier msgSupplier) {
IMessage msg;
battles.put(ctx.getChannel(), msg = ctx.replyBuffered(msgSupplier.getMessage(time, time)).get());
final long sentTime = System.currentTimeMillis();
final long endTime = sentTime + time;
allBattles.add(msg);
RequestHelper.requestOrdered(
() -> msg.addReaction(choice1),
() -> msg.addReaction(choice2)
);
// Wait at least 2 seconds before initial update
Threads.sleep(Math.min(time, 2000));
// Update remaining time every 5 seconds
long sysTime;
while ((sysTime = System.currentTimeMillis()) <= endTime) {
long remaining = endTime - sysTime;
EmbedObject e = msgSupplier.getMessage(time, remaining);
RequestBuffer.request(() -> msg.edit(e));
Threads.sleep(Math.min(remaining, 5000));
}
allBattles.remove(msg);
return ctx.getChannel().getMessageByID(msg.getLongID());
}