use of de.nikos410.discordBot.util.modular.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.
the class DiscordBot method command_help.
private void command_help(final IMessage message) {
final EmbedBuilder embedBuilder = new EmbedBuilder();
for (final String key : this.loadedModules.keySet()) {
Object module = this.loadedModules.get(key);
String moduleHelp = "";
for (Method method : module.getClass().getMethods()) {
if (method.isAnnotationPresent(CommandSubscriber.class)) {
final CommandSubscriber annotation = method.getDeclaredAnnotationsByType(CommandSubscriber.class)[0];
if (this.getUserPermissionLevel(message.getAuthor(), message.getGuild()) >= annotation.permissionLevel()) {
final String command = annotation.command();
final String help = annotation.help();
moduleHelp = moduleHelp + "`" + command + "` " + help + '\n';
}
}
}
final CommandModule[] annotations = module.getClass().getDeclaredAnnotationsByType(CommandModule.class);
final String moduleName = annotations[0].moduleName();
if (!moduleHelp.isEmpty()) {
embedBuilder.appendField(moduleName, moduleHelp, false);
}
}
final EmbedObject embedObject = embedBuilder.build();
Util.sendEmbed(message.getAuthor().getOrCreatePMChannel(), embedObject);
if (!message.getChannel().isPrivate()) {
Util.sendMessage(message.getChannel(), ":mailbox_with_mail:");
}
}
use of de.nikos410.discordBot.util.modular.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.
the class UserGroups method command_groups.
@CommandSubscriber(command = "groups", help = "Alle Rollen auflisten")
public void command_groups(final IMessage message) {
final StringBuilder stringBuilder = new StringBuilder();
final List<String> keyList = new LinkedList<>();
keyList.addAll(usergroupsJSON.keySet());
Collections.sort(keyList);
for (String key : keyList) {
if (stringBuilder.length() != 0) {
stringBuilder.append('\n');
}
stringBuilder.append(key);
}
if (stringBuilder.length() == 0) {
stringBuilder.append("_Keine_");
}
final EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.appendField("Verfügbare Gruppen:", stringBuilder.toString(), false);
embedBuilder.withFooterText("Weise dir mit '" + bot.configJSON.getString("prefix") + "group <Gruppe>' selbst eine dieser Gruppen zu");
Util.sendEmbed(message.getChannel(), embedBuilder.build());
}
use of de.nikos410.discordBot.util.modular.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.
the class UserLog method command_Userlog_Test.
@CommandSubscriber(command = "userlog_test", help = "Userlog-Ausgabe testen", permissionLevel = CommandPermissions.ADMIN)
public void command_Userlog_Test(final IMessage message) {
final IUser user = message.getAuthor();
userJoinNotify(user);
userLeaveNotify(user);
userBanNotify(user);
}
use of de.nikos410.discordBot.util.modular.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.
the class ModStuff method command_Mute.
@CommandSubscriber(command = "mute", help = "Einen Nutzer für eine bestimmte Zeit muten", pmAllowed = false, permissionLevel = CommandPermissions.MODERATOR)
public void command_Mute(final IMessage message, final String muteUserString, final String muteDurationInput) {
final List<IUser> mentions = message.getMentions();
if (mentions.size() < 1) {
Util.sendMessage(message.getChannel(), ":x: Fehler: Kein Nutzer angegeben!");
return;
} else if (mentions.size() > 1) {
Util.sendMessage(message.getChannel(), ":x: Fehler: mehrere Nutzer erwähnt");
return;
}
final IUser muteUser = mentions.get(0);
if (muteUser == null) {
Util.sendMessage(message.getChannel(), ":x: Fehler: Nutzer nicht gefunden!");
return;
}
Pattern pattern = Pattern.compile("(\\d+)\\s?([smhd])\\s?(.*)");
Matcher matcher = pattern.matcher(muteDurationInput);
if (!matcher.matches()) {
Util.sendMessage(message.getChannel(), "Ungültige Eingabe! Mögliche Zeitformate sind s, m, h und d.");
return;
}
IRole muteRole = message.getGuild().getRoleByID(muteRoleID);
// Wird ausgeführt, um Nutzer wieder zu entmuten
Runnable unmuteTask = () -> {
mutedUsers.remove(muteUser.getStringID());
muteUser.removeRole(muteRole);
System.out.println("Unmuted user " + Util.makeUserString(muteUser, message.getGuild()) + ".");
};
final int muteDuration = Integer.parseInt(matcher.group(1));
final String muteDurationUnitString = matcher.group(2);
ChronoUnit muteDurationUnit = parseChronoUnit(muteDurationUnitString);
if (mutedUsers.containsKey(muteUser.getStringID())) {
// Überprüfen, ob angegebener Zeitpunkt nach dem bisherigen Zeitpunkt liegt
ScheduledFuture oldFuture = mutedUsers.get(muteUser.getStringID());
LocalDateTime oldDateTime = LocalDateTime.now().plusSeconds(oldFuture.getDelay(TimeUnit.SECONDS));
LocalDateTime newDateTime = LocalDateTime.now().plus(muteDuration, muteDurationUnit);
if (newDateTime.isBefore(oldDateTime)) {
// neuer Zeitpunkt ist vor altem -> nichts tun (längerer Mute bleibt bestehen)
Util.sendMessage(message.getChannel(), "Nutzer ist bereits für einen längeren Zeitraum gemuted!");
return;
} else {
// neuer Zeitpunkt ist nach altem -> neu schedulen
mutedUsers.remove(muteUser.getStringID(), oldFuture);
oldFuture.cancel(false);
}
} else {
muteUser.addRole(muteRole);
System.out.println("Muted user " + Util.makeUserString(muteUser, message.getGuild()) + ".");
}
ScheduledFuture newFuture = scheduler.schedule(unmuteTask, muteDuration, chronoUnitToTimeUnit(muteDurationUnit));
mutedUsers.put(muteUser.getStringID(), newFuture);
// :mute:
message.addReaction(ReactionEmoji.of("\uD83D\uDD07"));
String customMessage = matcher.group(3);
if (customMessage.isEmpty()) {
customMessage = "kein";
}
final String muteMessage = "**Du wurdest für " + muteDuration + ' ' + muteDurationUnitString + " gemuted!** \nHinweis: _" + customMessage + " _";
if (!muteUser.isBot()) {
Util.sendPM(muteUser, muteMessage);
}
// Modlog
IChannel modLogChannel = message.getGuild().getChannelByID(this.modlogChannelID);
final String modLogMessage = String.format("**%s** hat Nutzer **%s** für %s %s **gemuted**. \nHinweis: _%s _", Util.makeUserString(message.getAuthor(), message.getGuild()), Util.makeUserString(muteUser, message.getGuild()), muteDuration, muteDurationUnitString, customMessage);
Util.sendMessage(modLogChannel, modLogMessage);
}
use of de.nikos410.discordBot.util.modular.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.
the class ModStuff method command_Selfmute.
@CommandSubscriber(command = "selfmute", help = "Schalte dich selber für die angegebene Zeit stumm", pmAllowed = false)
public void command_Selfmute(final IMessage message, final String muteDurationInput) {
IUser muteUser = message.getAuthor();
Pattern pattern = Pattern.compile("(\\d+)\\s?([smhd])\\s?(.*)");
Matcher matcher = pattern.matcher(muteDurationInput);
if (!matcher.matches()) {
Util.sendMessage(message.getChannel(), "Ungültige Eingabe! Mögliche Zeitformate sind s, m, h und d.");
return;
}
IRole muteRole = message.getGuild().getRoleByID(muteRoleID);
// Wird ausgeführt, um Nutzer wieder zu entmuten
Runnable unmuteTask = () -> {
mutedUsers.remove(muteUser.getStringID());
muteUser.removeRole(muteRole);
System.out.println("Unmuted user " + Util.makeUserString(muteUser, message.getGuild()) + ". (was selfmuted)");
};
final int muteDuration = Integer.parseInt(matcher.group(1));
final String muteDurationUnitString = matcher.group(2);
ChronoUnit muteDurationUnit = parseChronoUnit(muteDurationUnitString);
if (mutedUsers.containsKey(muteUser.getStringID())) {
// Überprüfen, ob angegebener Zeitpunkt nach dem bisherigen Zeitpunkt liegt
ScheduledFuture oldFuture = mutedUsers.get(muteUser.getStringID());
LocalDateTime oldDateTime = LocalDateTime.now().plusSeconds(oldFuture.getDelay(TimeUnit.SECONDS));
LocalDateTime newDateTime = LocalDateTime.now().plus(muteDuration, muteDurationUnit);
if (newDateTime.isBefore(oldDateTime)) {
// neuer Zeitpunkt ist vor altem -> nichts tun (längerer Mute bleibt bestehen)
Util.sendMessage(message.getChannel(), "Nutzer ist bereits für einen längeren Zeitraum gemuted!");
return;
} else {
// neuer Zeitpunkt ist nach altem -> neu schedulen
mutedUsers.remove(muteUser.getStringID(), oldFuture);
oldFuture.cancel(false);
}
} else {
muteUser.addRole(muteRole);
System.out.println("User " + Util.makeUserString(muteUser, message.getGuild()) + " selfmuted.");
}
ScheduledFuture newFuture = scheduler.schedule(unmuteTask, muteDuration, chronoUnitToTimeUnit(muteDurationUnit));
mutedUsers.put(muteUser.getStringID(), newFuture);
// :mute:
message.addReaction(ReactionEmoji.of("\uD83D\uDD07"));
}
Aggregations