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

Commit 68e47e9

Browse files
CodeDoctorDECodeDoctorDE
andauthored
1.0.2 (#16)
* fix prefix command, change command handle (#15) Co-authored-by: CodeDoctorDE <[email protected]> * adding template and rename global to team * adding limit, fix bugs * bump version Co-authored-by: CodeDoctorDE <[email protected]>
1 parent b94ad42 commit 68e47e9

File tree

18 files changed

+253
-63
lines changed

18 files changed

+253
-63
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.codedoctorde</groupId>
88
<artifactId>linwood</artifactId>
9-
<version>1.0.1</version>
9+
<version>1.0.2</version>
1010
<properties>
1111
<java.version>11</java.version>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.github.codedoctorde.linwood.commands;
2+
3+
import com.github.codedoctorde.linwood.entity.GuildEntity;
4+
import net.dv8tion.jda.api.entities.Message;
5+
import org.hibernate.Session;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import java.util.Arrays;
9+
import java.util.HashSet;
10+
import java.util.ResourceBundle;
11+
import java.util.Set;
12+
13+
/**
14+
* @author CodeDoctorDE
15+
*/
16+
public class WriteCommand implements Command {
17+
@Override
18+
public boolean onCommand(Session session, Message message, GuildEntity entity, String label, String[] args) {
19+
return false;
20+
}
21+
22+
@Override
23+
public @NotNull Set<String> aliases(GuildEntity entity) {
24+
return new HashSet<>(Arrays.asList(
25+
"write",
26+
"w"
27+
));
28+
}
29+
30+
@Override
31+
public @NotNull ResourceBundle getBundle(GuildEntity entity) {
32+
return ResourceBundle.getBundle("locale.commands.Write", entity.getLocalization());
33+
}
34+
}

src/main/java/com/github/codedoctorde/linwood/commands/settings/general/AddPrefixCommand.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public boolean onCommand(Session session, Message message, GuildEntity entity, S
2525
return false;
2626
else try {
2727
var prefix = String.join(" ", args);
28-
entity.getPrefixes().add(prefix);
28+
if(!entity.addPrefix(prefix)){
29+
message.getChannel().sendMessage(bundle.getString("Invalid")).queue();
30+
return true;
31+
}
2932
entity.save(session);
3033
message.getChannel().sendMessage(MessageFormat.format(bundle.getString("Success"), prefix)).queue();
3134
} catch (NullPointerException e) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.github.codedoctorde.linwood.commands.settings.template;
2+
3+
import com.github.codedoctorde.linwood.commands.Command;
4+
import com.github.codedoctorde.linwood.entity.GuildEntity;
5+
import net.dv8tion.jda.api.entities.Message;
6+
import org.hibernate.Session;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.util.ResourceBundle;
10+
import java.util.Set;
11+
12+
/**
13+
* @author CodeDoctorDE
14+
*/
15+
public class CreateTemplateCommand implements Command {
16+
@Override
17+
public boolean onCommand(Session session, Message message, GuildEntity entity, String label, String[] args) {
18+
return false;
19+
}
20+
21+
@Override
22+
public @NotNull Set<String> aliases(GuildEntity entity) {
23+
return null;
24+
}
25+
26+
@Override
27+
public @NotNull ResourceBundle getBundle(GuildEntity entity) {
28+
return null;
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.github.codedoctorde.linwood.commands.settings.template;
2+
3+
import com.github.codedoctorde.linwood.commands.Command;
4+
import com.github.codedoctorde.linwood.entity.GuildEntity;
5+
import net.dv8tion.jda.api.entities.Message;
6+
import org.hibernate.Session;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.util.ResourceBundle;
10+
import java.util.Set;
11+
12+
/**
13+
* @author CodeDoctorDE
14+
*/
15+
public class ListTemplateCommand implements Command {
16+
@Override
17+
public boolean onCommand(Session session, Message message, GuildEntity entity, String label, String[] args) {
18+
return false;
19+
}
20+
21+
@Override
22+
public @NotNull Set<String> aliases(GuildEntity entity) {
23+
return null;
24+
}
25+
26+
@Override
27+
public @NotNull ResourceBundle getBundle(GuildEntity entity) {
28+
return null;
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.github.codedoctorde.linwood.commands.settings.template;
2+
3+
import com.github.codedoctorde.linwood.commands.Command;
4+
import com.github.codedoctorde.linwood.entity.GuildEntity;
5+
import net.dv8tion.jda.api.entities.Message;
6+
import org.hibernate.Session;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.util.ResourceBundle;
10+
import java.util.Set;
11+
12+
/**
13+
* @author CodeDoctorDE
14+
*/
15+
public class RemoveTemplateCommand implements Command {
16+
@Override
17+
public boolean onCommand(Session session, Message message, GuildEntity entity, String label, String[] args) {
18+
return false;
19+
}
20+
21+
@Override
22+
public @NotNull Set<String> aliases(GuildEntity entity) {
23+
return null;
24+
}
25+
26+
@Override
27+
public @NotNull ResourceBundle getBundle(GuildEntity entity) {
28+
return null;
29+
}
30+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.github.codedoctorde.linwood.commands.settings.template;
2+
3+
import com.github.codedoctorde.linwood.commands.Command;
4+
import com.github.codedoctorde.linwood.commands.CommandManager;
5+
import com.github.codedoctorde.linwood.entity.GuildEntity;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import java.util.ResourceBundle;
9+
import java.util.Set;
10+
11+
/**
12+
* @author CodeDoctorDE
13+
*/
14+
public class TemplateCommand extends CommandManager {
15+
@Override
16+
public @NotNull Command[] commands() {
17+
return new Command[]{
18+
new CreateTemplateCommand(),
19+
new ListTemplateCommand(),
20+
new RemoveTemplateCommand()
21+
};
22+
}
23+
24+
@Override
25+
public @NotNull Set<String> aliases(GuildEntity entity) {
26+
return null;
27+
}
28+
29+
@Override
30+
public @NotNull ResourceBundle getBundle(GuildEntity entity) {
31+
return null;
32+
}
33+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.codedoctorde.linwood.entity;
2+
3+
import javax.persistence.*;
4+
5+
/**
6+
* @author CodeDoctorDE
7+
*/
8+
@Entity
9+
@Table
10+
public class DeleteChannelEntity {
11+
@Id
12+
@GeneratedValue(strategy = GenerationType.AUTO)
13+
@Column(name = "id")
14+
private Long id;
15+
private long channelId;
16+
}

src/main/java/com/github/codedoctorde/linwood/entity/GlobalEntity.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/main/java/com/github/codedoctorde/linwood/entity/GuildEntity.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ public class GuildEntity {
3535
@JoinColumn(name = "notification_id", referencedColumnName = "id")
3636
private final NotificationEntity notificationEntity = new NotificationEntity();
3737
private Long maintainerId = null;
38-
public enum Plan {
39-
DEFAULT, PRIVATE
40-
}
41-
private Plan plan = Plan.DEFAULT;
38+
private GuildPlan plan = GuildPlan.COMMUNITY;
4239

4340
public GuildEntity(){
4441
}
@@ -81,10 +78,7 @@ public KarmaEntity getKarmaEntity() {
8178
}
8279

8380
public NotificationEntity getNotificationEntity() {
84-
if(notificationEntity != null)
8581
return notificationEntity;
86-
else
87-
return null;
8882
}
8983

9084
public Long getMaintainerId() {
@@ -111,7 +105,16 @@ public Set<String> getPrefixes() {
111105
return prefixes;
112106
}
113107

114-
public Plan getPlan() {
108+
public GuildPlan getPlan() {
115109
return plan;
116110
}
111+
112+
public void setPlan(GuildPlan plan) {
113+
this.plan = plan;
114+
}
115+
public boolean addPrefix(String prefix){
116+
if(plan.getPrefixLimit() == -1 || plan.getPrefixLimit() <= getPrefixes().size() + 1)
117+
return getPrefixes().add(prefix);
118+
return false;
119+
}
117120
}

0 commit comments

Comments
 (0)