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

Commit dbaa826

Browse files
author
CodeDoctorDE
committed
adding limit, fix bugs
1 parent 979ffe5 commit dbaa826

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
lines changed

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) {

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
}
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+
public enum GuildPlan {
4+
COMMUNITY, PRO, PRIVATE;
5+
public int getPrefixLimit(){
6+
switch (this){
7+
case COMMUNITY:
8+
return 3;
9+
case PRO:
10+
return 10;
11+
case PRIVATE:
12+
return -1;
13+
}
14+
return -1;
15+
}
16+
}

src/main/java/com/github/codedoctorde/linwood/listener/KarmaListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void onRemove(MessageReactionRemoveEvent event){
5353
return;
5454
maybeReset();
5555
event.retrieveMember().queue(donor -> {
56-
var emote = event.getReactionEmote().isEmoji() ? event.getReactionEmote().getAsReactionCode() : event.getReactionEmote().getAsCodepoints();
56+
var emote = event.getReactionEmote().isEmoji() ? event.getReactionEmote().getAsReactionCode() : event.getReactionEmote().getEmote().getAsMention();
5757
var session = Linwood.getInstance().getDatabase().getSessionFactory().openSession();
5858
var entity = Linwood.getInstance().getDatabase().getGuildById(session, event.getGuild().getIdLong());
5959
var karma = entity.getKarmaEntity();

src/main/resources/locale/commands/settings/general/AddPrefix_de.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ Success=:white_check_mark: Erfolgreich Prefix `{0}` hinzugefügt!
22
Syntax=settings general addprefix <Prefix...>
33
Description=Füge ein Prefix zum Bot hinzu
44
Permission=Server verwalten
5-
Invalid=Dieser Prefix wurde schon hinzugefügt!
5+
Invalid=Dieser Prefix wurde schon hinzugefügt oder du hast das Limit überschritten!

src/main/resources/locale/commands/settings/general/AddPrefix_en.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ Success=:white_check_mark: Successfully add the prefix `{0}`!
22
Syntax=settings general addprefix <Prefix...>
33
Description=Add a prefix of the bot
44
Permission=Manage server
5-
Invalid=This prefix is already added!
5+
Invalid=This prefix is already added or you've exceeded the limit!

0 commit comments

Comments
 (0)