本文整理汇总了Java中sx.blah.discord.util.MessageBuilder类的典型用法代码示例。如果您正苦于以下问题:Java MessageBuilder类的具体用法?Java MessageBuilder怎么用?Java MessageBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageBuilder类属于sx.blah.discord.util包,在下文中一共展示了MessageBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendConnectionErrorMessage
import sx.blah.discord.util.MessageBuilder; //导入依赖的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.MessageBuilder; //导入依赖的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.MessageBuilder; //导入依赖的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: execute
import sx.blah.discord.util.MessageBuilder; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<Baristron> commandData) {
if (commandData.getArgs().size() == 0) {
Bot.sendMessage(Bot.getNewBuilder(commandData.getChannel()).withContent("Here you go™"));
return null;
}
StringBuilder builder = new StringBuilder();
for (int i = 0; i < commandData.getArgs().size(); i++) {
builder.append(commandData.getArgs().get(i)).append("™");
if (i == commandData.getArgs().size() - 1) {
builder.append("™™");
} else {
builder.append(" ");
}
}
Bot.sendMessage(Bot.getNewBuilder(commandData.getChannel()).withContent(builder.toString()));
return null;
}
示例5: execute
import sx.blah.discord.util.MessageBuilder; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<Baristron> commandData) {
long randTime = (long) (System.currentTimeMillis() +
(Utils.lerp(-1, 1, Utils.random.nextDouble()) * 1000 * 60 * 60 * 24 * 365.25 * 100));
if (commandData.getArgs().size() >= 1) {
try {
long l = Long.parseLong(commandData.getArgs().get(0));
randTime = l * 1000;
} catch (NumberFormatException e) {
return CommandResponse.withAutoDeleteMessage(Bot.getNewBuilder(commandData.getChannel())
.withContent("Not a number! Are you sure you used seconds?"), Bot.AUTO_DELETE_TIME);
}
}
Bot.sendMessage(Bot.getNewBuilder(commandData.getChannel()).appendContent(
commandData.getUser().mention() + " Travelling to `" +
new SimpleDateFormat("EEEE, MMMM d, yyyy HH:mm:ss").format(new Date(randTime)) + "`"));
return null;
}
示例6: execute
import sx.blah.discord.util.MessageBuilder; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<Baristron> commandData) {
if (commandData.getArgs().size() == 0)
return CommandResponse.getWrongArgumentsMessage(commandData.getChannel(), this, commandData.getCmdUsed(),
commandData);
MetadataMessageBuilder builder = Bot.getNewBuilder(commandData.getChannel());
builder.appendContent("__Stalk market prediction__\n*Reminder: this is just a prediction*");
StalkMarketPredictor.Prediction p = StalkMarketPredictor.INSTANCE
.getRecommendations(commandData.getArgs().stream().map(Integer::parseInt).collect(Collectors.toList
()));
builder.appendContent("\n\n" + p.toString());
Bot.sendMessage(builder);
return null;
}
示例7: execute
import sx.blah.discord.util.MessageBuilder; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<Baristron> commandData) {
if (commandData.getArgs().size() < 1) {
Bot.sendMessage(Bot.getNewBuilder(commandData.getChannel()).appendContent(
commandData.getUser().mention() + " Your permission tier is " + commandData.getPermLevel())
.appendContent(", you have been " + "tempbanned " +
Userdata.getData("tempbanCount_" + commandData.getUser().getID(), "0") + " times."));
} else {
String content = commandData.getFullContent();
IUser u = Utils.findFirstUser(commandData.getBot().client, content, commandData.getChannel().getGuild());
Bot.sendMessage(Bot.getNewBuilder(commandData.getChannel()).appendContent(
"The permission level of " + content + (u == null
? " (real user not found!)"
: " (" + u.getDisplayName(commandData.getChannel().getGuild()) + "#" +
u.getDiscriminator()) + ")" + " " + "is " +
Userdata.getPermissions(u == null ? content : u.getID()) + "."));
}
return null;
}
示例8: execute
import sx.blah.discord.util.MessageBuilder; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<Baristron> commandData) {
if (commandData.getChannel().isPrivate())
return CommandResponse.withAutoDeleteMessage(Bot.getNewBuilder(commandData.getChannel())
.withContent("Cannot execute in a private commandData.getChannel()!"), Bot.AUTO_DELETE_TIME);
if (commandData.getArgs().size() < 1)
return CommandResponse.getWrongArgumentsMessage(commandData.getChannel(), this, commandData.getCmdUsed(),
commandData);
MetadataMessageBuilder builder = Bot.getNewBuilder(commandData.getChannel());
builder.withContent("__Role IDs that match the name:__\n");
List<IRole> roles = commandData.getChannel().getGuild().getRolesByName(commandData.getFullContent());
roles.forEach(role -> builder.appendContent(role.getName() + " - `" + role.getID() + "`\n"));
Bot.sendMessage(builder);
return null;
}
示例9: execute
import sx.blah.discord.util.MessageBuilder; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<Baristron> commandData) {
IUser u = commandData.getArgs().size() >= 1 ? Utils
.findFirstUser(commandData.getBot().client, commandData.getFullContent(),
commandData.getChannel().getGuild()) : commandData.getUser();
if (u == null)
return CommandResponse.withAutoDeleteMessage(Bot.getNewBuilder(commandData.getChannel())
.withContent("Couldn't find that commandData.getUser()!"), Bot.AUTO_DELETE_TIME);
Bot.sendMessage(Bot.getNewBuilder(commandData.getChannel()).withContent(
"The Battle Code of **" + u.getDisplayName(commandData.getChannel().getGuild()) + "**#" +
u.getDiscriminator() + " is `" + BattleCode.idToCode(u.getID()) + "`"));
return null;
}
示例10: execute
import sx.blah.discord.util.MessageBuilder; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<Baristron> commandData) {
if (commandData.getArgs().size() < 1) {
return CommandResponse.getWrongArgumentsMessage(commandData.getChannel(), this, commandData.getCmdUsed(),
commandData);
} else {
MessageBuilder builder = Bot.getNewBuilder(commandData.getChannel());
IUser u = Utils.findFirstUser(commandData.getBot().client, commandData.getArgs().get(0),
commandData.getChannel().getGuild());
if (u != null) {
builder.appendContent(
"The name of the commandData.getUser() with ID " + commandData.getArgs().get(0) + " is " +
u.getName() + "#" + u.getDiscriminator());
Bot.sendMessage(builder);
}
return CommandResponse.withAutoDeleteMessage(Bot.getNewBuilder(commandData.getChannel())
.withContent("Couldn't find the commandData.getUser() " + commandData.getArgs().get(0)),
Bot.AUTO_DELETE_TIME);
}
}
示例11: execute
import sx.blah.discord.util.MessageBuilder; //导入依赖的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;
}
示例12: execute
import sx.blah.discord.util.MessageBuilder; //导入依赖的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;
}
示例13: execute
import sx.blah.discord.util.MessageBuilder; //导入依赖的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;
}
示例14: execute
import sx.blah.discord.util.MessageBuilder; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<Baristron> commandData) {
if (commandData.getArgs().size() == 0) {
MetadataMessageBuilder builder = Bot.getNewBuilder(commandData.getChannel());
// TODO get status
// for (int i = 0; i < commandData.getBot().client.getShardCount(); i++) {
// builder.appendContent(
// "Status " + i + " - " + commandData.getBot().client.getShards().get(i)..getStatusMessage() +
// "\n");
// }
Bot.sendMessage(builder);
} else {
commandData.getBot().setStatus(
commandData.getArgs().size() < 1 ? null : Utils.getContent(commandData.getFullContent(), 1),
Integer.parseInt(commandData.getArgs().get(0)));
commandData.getBot().timeUntilNextPlayingChange = Baristron.DEF_PLAYING_TEXT_UPDATE_FREQ;
}
return null;
}
示例15: execute
import sx.blah.discord.util.MessageBuilder; //导入依赖的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;
}