diff --git a/src/main/java/com/github/codedoctorde/linwood/commands/BaseCommand.java b/src/main/java/com/github/codedoctorde/linwood/commands/BaseCommand.java index b89ff498..c9ca12a1 100644 --- a/src/main/java/com/github/codedoctorde/linwood/commands/BaseCommand.java +++ b/src/main/java/com/github/codedoctorde/linwood/commands/BaseCommand.java @@ -27,6 +27,7 @@ public Command[] commands() { new FunCommand(), new GameCommand(), new SettingsCommand(), + new ClearCommand(), infoCommand }; } diff --git a/src/main/java/com/github/codedoctorde/linwood/commands/ClearCommand.java b/src/main/java/com/github/codedoctorde/linwood/commands/ClearCommand.java index a684fd2b..a73aa7d9 100644 --- a/src/main/java/com/github/codedoctorde/linwood/commands/ClearCommand.java +++ b/src/main/java/com/github/codedoctorde/linwood/commands/ClearCommand.java @@ -1,6 +1,8 @@ package com.github.codedoctorde.linwood.commands; import com.github.codedoctorde.linwood.entity.GuildEntity; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Message; import org.hibernate.Session; import org.jetbrains.annotations.NotNull; @@ -27,10 +29,20 @@ public boolean onCommand(Session session, Message message, GuildEntity entity, S message.getChannel().sendMessage(bundle.getString("Invalid")).queue(); return true; } - message.getChannel().getHistory().retrievePast(count).queue(messages -> message.getChannel().sendMessage(MessageFormat.format(bundle.getString("Success"), messages.size())).queue()); + if(count <= 0 || count > 100) + message.getChannel().sendMessage(bundle.getString("Between")).queue(); + message.getChannel().getHistory().retrievePast(count).queue(messages -> { + messages.forEach(deleteMessage -> deleteMessage.delete().queue()); + message.getChannel().sendMessage(MessageFormat.format(bundle.getString("Success"), messages.size())).queue(); + }); return true; } + @Override + public boolean hasPermission(Member member, GuildEntity entity, Session session) { + return member.hasPermission(Permission.MANAGE_CHANNEL); + } + @Override public @NotNull Set aliases(GuildEntity entity) { return new HashSet<>(Arrays.asList( diff --git a/src/main/resources/locale/commands/Base_de.properties b/src/main/resources/locale/commands/Base_de.properties index 69ec41b0..a4eb1034 100644 --- a/src/main/resources/locale/commands/Base_de.properties +++ b/src/main/resources/locale/commands/Base_de.properties @@ -1,2 +1,2 @@ -Syntax=*Bekomme die Hilfe mit `help `*\n**Verfügbare Hilfeseiten:** \n\n`help fun` \n*Spaßbefehlhilfe* \n\n`help settings` \n*Einstellungshilfe* \n\n`help games` \n*(Mini)gameshilfe* \n\n~~ ~~ \n\n**Verfügbare Befehle:** \n\n`info` \n*Bekomme generelle Informationen über den Bot* +Syntax=*Bekomme die Hilfe mit `help `*\n**Verfügbare Hilfeseiten:** \n\n`help fun` \n*Spaßbefehlhilfe* \n\n`help settings` \n*Einstellungshilfe* \n\n`help games` \n*(Mini)gameshilfe* \n\n~~ ~~ \n\n**Verfügbare Befehle:** \n\n`info` \n*Bekomme generelle Informationen über den Bot* \n\n`clear ` \nLeere den Chat \n__Benötigte Rechte: Kanal verwalten__ Description=Generelle Hilfe Befehl \ No newline at end of file diff --git a/src/main/resources/locale/commands/Base_en.properties b/src/main/resources/locale/commands/Base_en.properties index ad37db2e..16cbb3fc 100644 --- a/src/main/resources/locale/commands/Base_en.properties +++ b/src/main/resources/locale/commands/Base_en.properties @@ -1,2 +1,2 @@ -Syntax=*Get the help with `help `*\n**Available help pages:** \n\n`help fun` \n*Fun Commands Help* \n\n`help settings` \n*Settings help* \n\n`help games` \n*(Mini)games help* \n\n~~ ~~ \n\n**Available commands:** \n\n`info` \n*Get the general information of the bot* +Syntax=*Get the help with `help `*\n**Available help pages:** \n\n`help fun` \n*Fun Commands Help* \n\n`help settings` \n*Settings help* \n\n`help games` \n*(Mini)games help* \n\n~~ ~~ \n\n**Available commands:** \n\n`info` \n*Get the general information of the bot* \n\n`clear ` \nClear the chat \n__Required permissions: Manage channel__ Description=General help command \ No newline at end of file diff --git a/src/main/resources/locale/commands/Clear_de.properties b/src/main/resources/locale/commands/Clear_de.properties new file mode 100644 index 00000000..6961c6f2 --- /dev/null +++ b/src/main/resources/locale/commands/Clear_de.properties @@ -0,0 +1,5 @@ +Syntax=clear +Description=Leere den derzeitigen Chat +Success=Erfolgreich {0} Nachrichten geleert! +Invalid=Das Argument muss eine Zahl sein! +Between=Das Argument muss zwischen 1 und 100 sein! \ No newline at end of file diff --git a/src/main/resources/locale/commands/Clear_en.properties b/src/main/resources/locale/commands/Clear_en.properties new file mode 100644 index 00000000..e50eed1e --- /dev/null +++ b/src/main/resources/locale/commands/Clear_en.properties @@ -0,0 +1,5 @@ +Syntax=clear +Description=Clear the current chat +Success=Successfully {0} messages cleared! +Invalid=The argument should be a number! +Between=The argument should be between 1 and 100! \ No newline at end of file