Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit bf88848

Browse files
authored
Merge pull request #18 from CodeDoctorDE/features/clear
Features/clear
2 parents 6365794 + 87c09f5 commit bf88848

File tree

6 files changed

+26
-3
lines changed

6 files changed

+26
-3
lines changed

src/main/java/com/github/codedoctorde/linwood/commands/BaseCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public Command[] commands() {
2727
new FunCommand(),
2828
new GameCommand(),
2929
new SettingsCommand(),
30+
new ClearCommand(),
3031
infoCommand
3132
};
3233
}

src/main/java/com/github/codedoctorde/linwood/commands/ClearCommand.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.github.codedoctorde.linwood.commands;
22

33
import com.github.codedoctorde.linwood.entity.GuildEntity;
4+
import net.dv8tion.jda.api.Permission;
5+
import net.dv8tion.jda.api.entities.Member;
46
import net.dv8tion.jda.api.entities.Message;
57
import org.hibernate.Session;
68
import org.jetbrains.annotations.NotNull;
@@ -27,10 +29,20 @@ public boolean onCommand(Session session, Message message, GuildEntity entity, S
2729
message.getChannel().sendMessage(bundle.getString("Invalid")).queue();
2830
return true;
2931
}
30-
message.getChannel().getHistory().retrievePast(count).queue(messages -> message.getChannel().sendMessage(MessageFormat.format(bundle.getString("Success"), messages.size())).queue());
32+
if(count <= 0 || count > 100)
33+
message.getChannel().sendMessage(bundle.getString("Between")).queue();
34+
message.getChannel().getHistory().retrievePast(count).queue(messages -> {
35+
messages.forEach(deleteMessage -> deleteMessage.delete().queue());
36+
message.getChannel().sendMessage(MessageFormat.format(bundle.getString("Success"), messages.size())).queue();
37+
});
3138
return true;
3239
}
3340

41+
@Override
42+
public boolean hasPermission(Member member, GuildEntity entity, Session session) {
43+
return member.hasPermission(Permission.MANAGE_CHANNEL);
44+
}
45+
3446
@Override
3547
public @NotNull Set<String> aliases(GuildEntity entity) {
3648
return new HashSet<>(Arrays.asList(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Syntax=*Bekomme die Hilfe mit `help <Command...>`*\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*
1+
Syntax=*Bekomme die Hilfe mit `help <Command...>`*\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 <Nachrichten 1-100>` \nLeere den Chat \n__Benötigte Rechte: Kanal verwalten__
22
Description=Generelle Hilfe Befehl
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Syntax=*Get the help with `help <Command...>`*\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*
1+
Syntax=*Get the help with `help <Command...>`*\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 <Messages 1-100>` \nClear the chat \n__Required permissions: Manage channel__
22
Description=General help command
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Syntax=clear <Nachrichten 1-100>
2+
Description=Leere den derzeitigen Chat
3+
Success=Erfolgreich {0} Nachrichten geleert!
4+
Invalid=Das Argument muss eine Zahl sein!
5+
Between=Das Argument muss zwischen 1 und 100 sein!
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Syntax=clear <Messages 1-100>
2+
Description=Clear the current chat
3+
Success=Successfully {0} messages cleared!
4+
Invalid=The argument should be a number!
5+
Between=The argument should be between 1 and 100!

0 commit comments

Comments
 (0)