use of sx.blah.discord.util.MessageBuilder in project Discord4J by Discord4J.
the class ParrotBot method handle.
/**
* Called when the client receives a message.
*/
@Override
public void handle(MessageReceivedEvent event) {
// Gets the message from the event object NOTE: This is not the content of the message, but the object itself
IMessage message = event.getMessage();
// Gets the channel in which this message was sent.
IChannel channel = message.getChannel();
try {
// Builds (sends) and new message in the channel that the original message was sent with the content of the original message.
new MessageBuilder(this.client).withChannel(channel).withContent(message.getContent()).build();
} catch (RateLimitException e) {
// RateLimitException thrown. The bot is sending messages too quickly!
System.err.print("Sending messages too quickly!");
e.printStackTrace();
} catch (DiscordException e) {
// DiscordException thrown. Many possibilities. Use getErrorMessage() to see what went wrong.
// Print the error message sent by Discord
System.err.print(e.getErrorMessage());
e.printStackTrace();
} catch (MissingPermissionsException e) {
// MissingPermissionsException thrown. The bot doesn't have permission to send the message!
System.err.print("Missing permissions for channel!");
e.printStackTrace();
}
}
use of sx.blah.discord.util.MessageBuilder in project Shadbot by Shadorc.
the class BotUtils method sendMessage.
public static RequestFuture<IMessage> sendMessage(EmbedObject embed, IChannel channel) {
if (!BotUtils.hasPermissions(channel, Permissions.SEND_MESSAGES, Permissions.EMBED_LINKS)) {
BotUtils.sendMessage(TextUtils.missingPerm(Permissions.EMBED_LINKS), channel);
LogUtils.infof("{Guild ID: %d} Shadbot wasn't allowed to send embed link.", channel.getGuild().getLongID());
return null;
}
VariousStatsManager.log(VariousEnum.EMBEDS_SENT);
return BotUtils.sendMessage(new MessageBuilder(channel.getClient()).withChannel(channel).withEmbed(embed));
}
use of sx.blah.discord.util.MessageBuilder in project Shadbot by Shadorc.
the class CommandManager method execute.
public static void execute(Context context) {
AbstractCommand cmd = COMMANDS_MAP.get(context.getCommandName());
if (cmd == null) {
return;
}
if (!BotUtils.isCommandAllowed(context.getGuild(), cmd)) {
return;
}
CommandPermission authorPermission = context.getAuthorPermission();
if (cmd.getPermission().isSuperior(authorPermission)) {
BotUtils.sendMessage(Emoji.ACCESS_DENIED + " You do not have the permission to execute this command.", context.getChannel());
return;
}
if (cmd.getRateLimiter() != null && cmd.getRateLimiter().isLimited(context.getChannel(), context.getAuthor())) {
CommandStatsManager.log(CommandEnum.COMMAND_LIMITED, cmd);
return;
}
try {
cmd.execute(context);
CommandStatsManager.log(CommandEnum.COMMAND_USED, cmd);
VariousStatsManager.log(VariousEnum.COMMANDS_EXECUTED);
} catch (IllegalCmdArgumentException err) {
BotUtils.sendMessage(Emoji.GREY_EXCLAMATION + err.getMessage(), context.getChannel());
CommandStatsManager.log(CommandEnum.COMMAND_ILLEGAL_ARG, cmd);
} catch (MissingArgumentException err) {
BotUtils.sendMessage(new MessageBuilder(context.getClient()).withChannel(context.getChannel()).withContent(TextUtils.MISSING_ARG).withEmbed(cmd.getHelp(context.getPrefix())));
CommandStatsManager.log(CommandEnum.COMMAND_MISSING_ARG, cmd);
}
}
use of sx.blah.discord.util.MessageBuilder in project Shadbot by Shadorc.
the class SettingsCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
List<String> splitArgs = StringUtils.split(context.getArg(), 2);
if (splitArgs.isEmpty()) {
throw new MissingArgumentException();
}
SettingEnum settingEnum = Utils.getValueOrNull(SettingEnum.class, splitArgs.get(0));
if (settingEnum == null || !SETTINGS_MAP.containsKey(settingEnum)) {
throw new IllegalCmdArgumentException(String.format("Setting `%s` does not exist. Use `%shelp %s` to see all available settings.", splitArgs.get(0), context.getPrefix(), this.getName()));
}
AbstractSetting setting = SETTINGS_MAP.get(settingEnum);
String arg = splitArgs.size() == 2 ? splitArgs.get(1) : null;
if ("help".equals(arg)) {
BotUtils.sendMessage(this.getHelp(context.getPrefix(), setting), context.getChannel());
return;
}
try {
setting.execute(context, arg);
} catch (MissingArgumentException e) {
BotUtils.sendMessage(new MessageBuilder(context.getClient()).withChannel(context.getChannel()).withContent(TextUtils.MISSING_ARG).withEmbed(this.getHelp(context.getPrefix(), setting)));
}
}
Aggregations