use of de.nikos410.discordbot.framework.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.
the class ModStuff method command_setMuteRole.
@CommandSubscriber(command = "setMuteRole", help = "Mute Rolle einstellen", pmAllowed = false, passContext = false, permissionLevel = PermissionLevel.ADMIN)
public void command_setMuteRole(final IMessage message, final String roleParameter) {
final IRole muteRole = GuildUtils.getRoleFromMessage(message, roleParameter);
if (muteRole == null) {
// No valid role specified
DiscordIO.sendMessage(message.getChannel(), "Keine gültige Rolle angegeben!");
return;
}
final IGuild guild = message.getGuild();
final JSONObject guildJSON;
if (modstuffJSON.has(guild.getStringID())) {
guildJSON = modstuffJSON.getJSONObject(guild.getStringID());
} else {
guildJSON = new JSONObject();
modstuffJSON.put(guild.getStringID(), guildJSON);
}
guildJSON.put("muteRole", muteRole.getLongID());
saveJSON();
// :white_check_mark:
message.addReaction(ReactionEmoji.of("✅"));
}
use of de.nikos410.discordbot.framework.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.
the class Roll method command_roll.
@CommandSubscriber(command = "roll", help = "Würfeln. Syntax: `roll AnzahlWuerfel;[AugenJeWuerfel=6]`")
public void command_roll(final IMessage commandMessage, final String diceArgsInput) {
final IChannel channel = commandMessage.getChannel();
final EmbedBuilder outputBuilder = new EmbedBuilder();
if (diceArgsInput.matches("^[0-9]+;?[0-9]*")) {
try {
final String[] args = diceArgsInput.split(";");
final int diceCount = Integer.parseInt(args[0]);
final int dotCount = args.length > 1 ? Integer.parseInt(args[1]) : DEFAULT_DOT_COUNT;
if (diceCount < 1 || dotCount < 1) {
throw new NumberFormatException("Würfelanzahl und maximale Augenzahl muss größer als 0 sein!");
}
final StringBuilder resultBuilder = new StringBuilder();
final int sum = IntStream.generate(() -> (rng.nextInt(dotCount) + 1)).limit(diceCount).reduce(0, (int acc, int number) -> {
resultBuilder.append(number);
resultBuilder.append("\n");
return acc + number;
});
resultBuilder.append(MessageFormat.format("Sum: {0}", sum));
outputBuilder.appendField(MessageFormat.format("Würfelt {0} Würfel mit einer maximalen Augenzahl von {1}!", diceCount, dotCount), resultBuilder.toString(), false);
EmbedObject rollObject = outputBuilder.build();
DiscordIO.sendEmbed(channel, rollObject);
} catch (NumberFormatException ex) {
DiscordIO.sendMessage(channel, MessageFormat.format("Konnte Eingabe '{0}' nicht verarbeiten." + "Bitte sicherstellen, dass sowohl die Würfelanzahl als auch die maximale Augenzahl Integer-Zahlen > 0 sind!", diceArgsInput));
}
} else {
DiscordIO.sendMessage(channel, "Syntax: `roll AnzahlWürfel;[AugenJeWürfel=6]`");
}
}
use of de.nikos410.discordbot.framework.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.
the class GeneralCommands method command_uptime.
@CommandSubscriber(command = "uptime", help = "Zeigt seit wann der Bot online ist")
public void command_uptime(final IMessage message) {
final DateTimeFormatter timeStampFormatter = DateTimeFormatter.ofPattern("dd.MM. | HH:mm");
DiscordIO.sendMessage(message.getChannel(), String.format("Online seit: %s", startupTimestamp.format(timeStampFormatter)));
}
use of de.nikos410.discordbot.framework.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.
the class GeneralCommands method command_quote.
@CommandSubscriber(command = "quote", help = "Zitiert die Nachricht mit der angegebenen ID.", pmAllowed = false, passContext = false)
public void command_quote(final IMessage commandMessage, final String id) {
if (id.isEmpty()) {
DiscordIO.sendMessage(commandMessage.getChannel(), "Keine ID angegeben!");
return;
}
final IUser commandAuthor = commandMessage.getAuthor();
final IGuild guild = commandMessage.getGuild();
if (!id.matches("^[0-9]{18}$")) {
DiscordIO.sendMessage(commandMessage.getChannel(), "Keine gültige ID eingegeben!");
return;
}
final long quoteMessageID = Long.parseLong(id);
final Optional<IMessage> optQuoteMessage = guild.getChannels().parallelStream().map(c -> c.fetchMessage(quoteMessageID)).filter(Objects::nonNull).findFirst();
if (!optQuoteMessage.isPresent()) {
DiscordIO.sendMessage(commandMessage.getChannel(), String.format("Nachricht mit der ID `%s` nicht gefunden!", quoteMessageID));
return;
}
final IMessage quoteMessage = optQuoteMessage.get();
commandMessage.delete();
final IUser quoteAuthor = quoteMessage.getAuthor();
final IRole quoteAuthorTopRole = UserUtils.getTopRole(quoteAuthor, quoteMessage.getGuild());
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.withAuthorIcon(quoteAuthor.getAvatarURL());
embedBuilder.withAuthorName(UserUtils.makeUserString(quoteAuthor, guild));
embedBuilder.withDesc(quoteMessage.getContent());
embedBuilder.withColor(quoteAuthorTopRole.getColor());
final DateTimeFormatter timestampFormatter = DateTimeFormatter.ofPattern("dd.MM.YYYY, HH:mm");
final LocalDateTime timestamp = LocalDateTime.ofInstant(quoteMessage.getTimestamp(), ZoneOffset.UTC);
final String timestampString = timestamp.format(timestampFormatter);
embedBuilder.withFooterText(String.format("%s | Zitiert von: %s", timestampString, UserUtils.makeUserString(commandAuthor, guild)));
DiscordIO.sendEmbed(commandMessage.getChannel(), embedBuilder.build());
}
use of de.nikos410.discordbot.framework.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.
the class DiscordBot method discoverCommands.
private List<CommandWrapper> discoverCommands(final ModuleWrapper moduleWrapper) {
LOG.debug("Registering command(s) for module '{}'.", moduleWrapper.getName());
final List<CommandWrapper> commands = new LinkedList<>();
final Method[] allMethods = moduleWrapper.getModuleClass().getMethods();
final List<Method> commandMethods = Arrays.stream(allMethods).filter(module -> module.isAnnotationPresent(CommandSubscriber.class)).collect(Collectors.toList());
for (final Method method : commandMethods) {
// Register methods with the @CommandSubscriber as commands
// All annotations of type CommandSubscriber declared for that Method. Should be exactly 1
final CommandSubscriber annotation = method.getDeclaredAnnotationsByType(CommandSubscriber.class)[0];
// Get command properties from annotation
final String commandName = annotation.command();
final String commandHelp = annotation.help();
final boolean pmAllowed = annotation.pmAllowed();
final PermissionLevel permissionLevel = annotation.permissionLevel();
final boolean passContext = annotation.passContext();
final boolean ignoreParameterCount = annotation.ignoreParameterCount();
final int parameterCount = method.getParameterCount() - 1;
if ((parameterCount >= 0 && parameterCount <= 5) || ignoreParameterCount) {
final CommandWrapper commandWrapper = new CommandWrapper(commandName, commandHelp, moduleWrapper, method, pmAllowed, permissionLevel, parameterCount, passContext, ignoreParameterCount);
commands.add(commandWrapper);
LOG.debug("Saved command '{}'.", commandName);
} else {
LOG.warn("Method '{}' has an invalid number of arguments. Skipping", commandName);
}
}
return commands;
}
Aggregations