use of java.time.temporal.ChronoUnit in project de-DiscordBot by DACH-Discord.
the class ModStuff method command_channelMute.
@CommandSubscriber(command = "channelMute", help = "Nutzer in einem Channel für eine bestimmte Zeit stummschalten", pmAllowed = false, permissionLevel = PermissionLevel.MODERATOR)
public void command_channelMute(final IMessage message, final String userInput, final String channelInput, final String muteDurationInput) {
// Parse user
final IUser muteUser = UserUtils.getUserFromMessage(message, userInput);
if (muteUser == null) {
DiscordIO.sendMessage(message.getChannel(), ":x: Fehler: Kein gültiger Nutzer angegeben!");
return;
}
// Parse channel
final IChannel muteChannel = ChannelUtils.getChannelFromMessage(message, channelInput);
if (muteChannel == null) {
DiscordIO.sendMessage(message.getChannel(), ":x: Fehler: Kein gültiger Kanal angegeben!");
return;
}
// Parse mute duration and message
final CommandUtils.DurationParameters durationParameters = CommandUtils.parseDurationParameters(muteDurationInput);
if (durationParameters == null) {
DiscordIO.sendMessage(message.getChannel(), "Ungültige Dauer angegeben. Mögliche Einheiten sind: s, m, h, d");
return;
}
final int muteDuration = durationParameters.getDuration();
final ChronoUnit muteDurationUnit = durationParameters.getDurationUnit();
String customMessage = durationParameters.getMessage();
if (customMessage == null || customMessage.isEmpty()) {
customMessage = "kein";
}
// Mute user and schedule unmute
final String output = muteUserForChannel(muteUser, muteChannel, muteDuration, muteDurationUnit);
if (output.isEmpty()) {
// :mute:
message.addReaction(ReactionEmoji.of("\uD83D\uDD07"));
} else {
DiscordIO.sendMessage(message.getChannel(), output);
return;
}
final IGuild guild = message.getGuild();
// Do not notify a bot user
if (!muteUser.isBot()) {
final List<String> muteMessage = new ArrayList<>();
muteMessage.add(String.format("**Du wurdest für %s %s für den Kanal %s auf dem Server %s gemuted!**", muteDuration, muteDurationUnit.name(), muteChannel.getName(), guild.getName()));
muteMessage.add(String.format("Hinweis: _%s_", customMessage));
DiscordIO.sendMessage(muteUser.getOrCreatePMChannel(), muteMessage);
}
// Modlog
LOG.info("Guild '{}': User {} was muted for {} {} for the channel {}. Message: {}", guild.getName(), UserUtils.makeUserString(muteUser, guild), muteDuration, muteDurationUnit.name(), muteChannel.getName(), customMessage);
final IChannel modLogChannel = getModlogChannelForGuild(guild);
if (modLogChannel != null) {
final List<String> modLogMessage = new ArrayList<>();
modLogMessage.add(String.format("Nutzer **%s** wurde im Kanal %s für %s %s für den Kanal %s **gemuted**.", UserUtils.makeUserString(muteUser, message.getGuild()), message.getChannel().mention(), muteDuration, muteDurationUnit.name(), muteChannel.mention()));
modLogMessage.add(String.format("Hinweis: _%s _", customMessage));
DiscordIO.sendMessage(modLogChannel, modLogMessage);
}
}
use of java.time.temporal.ChronoUnit 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 = PermissionLevel.MODERATOR, ignoreParameterCount = true)
public void command_mute(final IMessage message, final String userString, final String muteDurationInput) {
// Find the user to mute
final IUser muteUser = UserUtils.getUserFromMessage(message, userString);
if (muteUser == null) {
DiscordIO.sendMessage(message.getChannel(), ":x: Fehler: Nutzer nicht gefunden!");
return;
}
// Check if mute duration was specified
if (muteDurationInput == null) {
DiscordIO.sendMessage(message.getChannel(), "Fehler! Es muss eine Mute-Dauer angegeben werden.");
return;
}
// Parse mute duration
final CommandUtils.DurationParameters durationParameters = CommandUtils.parseDurationParameters(muteDurationInput);
if (durationParameters == null) {
DiscordIO.sendMessage(message.getChannel(), "Ungültige Dauer angegeben. Mögliche Einheiten sind: s, m, h, d");
return;
}
final int muteDuration = durationParameters.getDuration();
final ChronoUnit muteDurationUnit = durationParameters.getDurationUnit();
String customMessage = durationParameters.getMessage();
if (customMessage == null || customMessage.isEmpty()) {
customMessage = "kein";
}
final IGuild guild = message.getGuild();
// Mute the user and schedule unmute
muteUserForGuild(muteUser, guild, muteDuration, muteDurationUnit, message.getChannel());
// :mute:
message.addReaction(ReactionEmoji.of("\uD83D\uDD07"));
// Do not notify a bot user
if (!muteUser.isBot()) {
final List<String> muteMessage = Arrays.asList(String.format("**Du wurdest auf dem Server %s für %s %s gemuted!**", guild.getName(), muteDuration, muteDurationUnit.name()), String.format("Hinweis: _%s_", customMessage));
DiscordIO.sendMessage(muteUser.getOrCreatePMChannel(), muteMessage);
}
// Modlog
LOG.info("Guild '{}': User {} was muted for {} {}. Message: {}", guild.getName(), UserUtils.makeUserString(muteUser, message.getGuild()), muteDuration, muteDurationUnit.name(), customMessage);
final IChannel modLogChannel = getModlogChannelForGuild(guild);
if (modLogChannel != null) {
final List<String> modLogMessage = new ArrayList<>();
modLogMessage.add(String.format("Nutzer **%s** wurde im Kanal %s für %s %s **gemuted**.", UserUtils.makeUserString(muteUser, guild), message.getChannel().mention(), muteDuration, muteDurationUnit.name()));
modLogMessage.add(String.format("Hinweis: _%s_", customMessage));
DiscordIO.sendMessage(modLogChannel, modLogMessage);
}
saveUserMutes();
}
Aggregations