diff --git a/pom.xml b/pom.xml index 7d0dc6b6..215f9662 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.codedoctorde linwood - 1.0.1 + 1.0.2 11 UTF-8 diff --git a/src/main/java/com/github/codedoctorde/linwood/commands/WriteCommand.java b/src/main/java/com/github/codedoctorde/linwood/commands/WriteCommand.java new file mode 100644 index 00000000..c406ec4e --- /dev/null +++ b/src/main/java/com/github/codedoctorde/linwood/commands/WriteCommand.java @@ -0,0 +1,34 @@ +package com.github.codedoctorde.linwood.commands; + +import com.github.codedoctorde.linwood.entity.GuildEntity; +import net.dv8tion.jda.api.entities.Message; +import org.hibernate.Session; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.ResourceBundle; +import java.util.Set; + +/** + * @author CodeDoctorDE + */ +public class WriteCommand implements Command { + @Override + public boolean onCommand(Session session, Message message, GuildEntity entity, String label, String[] args) { + return false; + } + + @Override + public @NotNull Set aliases(GuildEntity entity) { + return new HashSet<>(Arrays.asList( + "write", + "w" + )); + } + + @Override + public @NotNull ResourceBundle getBundle(GuildEntity entity) { + return ResourceBundle.getBundle("locale.commands.Write", entity.getLocalization()); + } +} diff --git a/src/main/java/com/github/codedoctorde/linwood/commands/settings/general/AddPrefixCommand.java b/src/main/java/com/github/codedoctorde/linwood/commands/settings/general/AddPrefixCommand.java index 44d0e8a2..431d1797 100644 --- a/src/main/java/com/github/codedoctorde/linwood/commands/settings/general/AddPrefixCommand.java +++ b/src/main/java/com/github/codedoctorde/linwood/commands/settings/general/AddPrefixCommand.java @@ -25,7 +25,10 @@ public boolean onCommand(Session session, Message message, GuildEntity entity, S return false; else try { var prefix = String.join(" ", args); - entity.getPrefixes().add(prefix); + if(!entity.addPrefix(prefix)){ + message.getChannel().sendMessage(bundle.getString("Invalid")).queue(); + return true; + } entity.save(session); message.getChannel().sendMessage(MessageFormat.format(bundle.getString("Success"), prefix)).queue(); } catch (NullPointerException e) { diff --git a/src/main/java/com/github/codedoctorde/linwood/commands/settings/template/CreateTemplateCommand.java b/src/main/java/com/github/codedoctorde/linwood/commands/settings/template/CreateTemplateCommand.java new file mode 100644 index 00000000..cbb36212 --- /dev/null +++ b/src/main/java/com/github/codedoctorde/linwood/commands/settings/template/CreateTemplateCommand.java @@ -0,0 +1,30 @@ +package com.github.codedoctorde.linwood.commands.settings.template; + +import com.github.codedoctorde.linwood.commands.Command; +import com.github.codedoctorde.linwood.entity.GuildEntity; +import net.dv8tion.jda.api.entities.Message; +import org.hibernate.Session; +import org.jetbrains.annotations.NotNull; + +import java.util.ResourceBundle; +import java.util.Set; + +/** + * @author CodeDoctorDE + */ +public class CreateTemplateCommand implements Command { + @Override + public boolean onCommand(Session session, Message message, GuildEntity entity, String label, String[] args) { + return false; + } + + @Override + public @NotNull Set aliases(GuildEntity entity) { + return null; + } + + @Override + public @NotNull ResourceBundle getBundle(GuildEntity entity) { + return null; + } +} diff --git a/src/main/java/com/github/codedoctorde/linwood/commands/settings/template/ListTemplateCommand.java b/src/main/java/com/github/codedoctorde/linwood/commands/settings/template/ListTemplateCommand.java new file mode 100644 index 00000000..436a237c --- /dev/null +++ b/src/main/java/com/github/codedoctorde/linwood/commands/settings/template/ListTemplateCommand.java @@ -0,0 +1,30 @@ +package com.github.codedoctorde.linwood.commands.settings.template; + +import com.github.codedoctorde.linwood.commands.Command; +import com.github.codedoctorde.linwood.entity.GuildEntity; +import net.dv8tion.jda.api.entities.Message; +import org.hibernate.Session; +import org.jetbrains.annotations.NotNull; + +import java.util.ResourceBundle; +import java.util.Set; + +/** + * @author CodeDoctorDE + */ +public class ListTemplateCommand implements Command { + @Override + public boolean onCommand(Session session, Message message, GuildEntity entity, String label, String[] args) { + return false; + } + + @Override + public @NotNull Set aliases(GuildEntity entity) { + return null; + } + + @Override + public @NotNull ResourceBundle getBundle(GuildEntity entity) { + return null; + } +} diff --git a/src/main/java/com/github/codedoctorde/linwood/commands/settings/template/RemoveTemplateCommand.java b/src/main/java/com/github/codedoctorde/linwood/commands/settings/template/RemoveTemplateCommand.java new file mode 100644 index 00000000..4f11f17b --- /dev/null +++ b/src/main/java/com/github/codedoctorde/linwood/commands/settings/template/RemoveTemplateCommand.java @@ -0,0 +1,30 @@ +package com.github.codedoctorde.linwood.commands.settings.template; + +import com.github.codedoctorde.linwood.commands.Command; +import com.github.codedoctorde.linwood.entity.GuildEntity; +import net.dv8tion.jda.api.entities.Message; +import org.hibernate.Session; +import org.jetbrains.annotations.NotNull; + +import java.util.ResourceBundle; +import java.util.Set; + +/** + * @author CodeDoctorDE + */ +public class RemoveTemplateCommand implements Command { + @Override + public boolean onCommand(Session session, Message message, GuildEntity entity, String label, String[] args) { + return false; + } + + @Override + public @NotNull Set aliases(GuildEntity entity) { + return null; + } + + @Override + public @NotNull ResourceBundle getBundle(GuildEntity entity) { + return null; + } +} diff --git a/src/main/java/com/github/codedoctorde/linwood/commands/settings/template/TemplateCommand.java b/src/main/java/com/github/codedoctorde/linwood/commands/settings/template/TemplateCommand.java new file mode 100644 index 00000000..261454f7 --- /dev/null +++ b/src/main/java/com/github/codedoctorde/linwood/commands/settings/template/TemplateCommand.java @@ -0,0 +1,33 @@ +package com.github.codedoctorde.linwood.commands.settings.template; + +import com.github.codedoctorde.linwood.commands.Command; +import com.github.codedoctorde.linwood.commands.CommandManager; +import com.github.codedoctorde.linwood.entity.GuildEntity; +import org.jetbrains.annotations.NotNull; + +import java.util.ResourceBundle; +import java.util.Set; + +/** + * @author CodeDoctorDE + */ +public class TemplateCommand extends CommandManager { + @Override + public @NotNull Command[] commands() { + return new Command[]{ + new CreateTemplateCommand(), + new ListTemplateCommand(), + new RemoveTemplateCommand() + }; + } + + @Override + public @NotNull Set aliases(GuildEntity entity) { + return null; + } + + @Override + public @NotNull ResourceBundle getBundle(GuildEntity entity) { + return null; + } +} diff --git a/src/main/java/com/github/codedoctorde/linwood/entity/DeleteChannelEntity.java b/src/main/java/com/github/codedoctorde/linwood/entity/DeleteChannelEntity.java new file mode 100644 index 00000000..c99c6e1f --- /dev/null +++ b/src/main/java/com/github/codedoctorde/linwood/entity/DeleteChannelEntity.java @@ -0,0 +1,16 @@ +package com.github.codedoctorde.linwood.entity; + +import javax.persistence.*; + +/** + * @author CodeDoctorDE + */ +@Entity +@Table +public class DeleteChannelEntity { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private Long id; + private long channelId; +} diff --git a/src/main/java/com/github/codedoctorde/linwood/entity/GlobalEntity.java b/src/main/java/com/github/codedoctorde/linwood/entity/GlobalEntity.java deleted file mode 100644 index 9a4a92cc..00000000 --- a/src/main/java/com/github/codedoctorde/linwood/entity/GlobalEntity.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.codedoctorde.linwood.entity; - -import javax.persistence.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -@Entity -public class GlobalEntity { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id") - private Long id; - @OneToMany - private final List guilds = new ArrayList<>(); - - public GlobalEntity(){} - public GlobalEntity(Long ownerGuildId, Long... memberGuildIds){ - guilds.add(new GlobalGuildEntity(ownerGuildId, PermissionLevel.OWNER)); - Arrays.stream(memberGuildIds).forEach(guildId -> guilds.add(new GlobalGuildEntity(guildId, PermissionLevel.MEMBER))); - } - - public List getGuilds() { - return guilds; - } - - public Long getId() { - return id; - } -} \ No newline at end of file diff --git a/src/main/java/com/github/codedoctorde/linwood/entity/GuildEntity.java b/src/main/java/com/github/codedoctorde/linwood/entity/GuildEntity.java index a971f94d..754c8c9f 100644 --- a/src/main/java/com/github/codedoctorde/linwood/entity/GuildEntity.java +++ b/src/main/java/com/github/codedoctorde/linwood/entity/GuildEntity.java @@ -35,10 +35,7 @@ public class GuildEntity { @JoinColumn(name = "notification_id", referencedColumnName = "id") private final NotificationEntity notificationEntity = new NotificationEntity(); private Long maintainerId = null; - public enum Plan { - DEFAULT, PRIVATE - } - private Plan plan = Plan.DEFAULT; + private GuildPlan plan = GuildPlan.COMMUNITY; public GuildEntity(){ } @@ -81,10 +78,7 @@ public KarmaEntity getKarmaEntity() { } public NotificationEntity getNotificationEntity() { - if(notificationEntity != null) return notificationEntity; - else - return null; } public Long getMaintainerId() { @@ -111,7 +105,16 @@ public Set getPrefixes() { return prefixes; } - public Plan getPlan() { + public GuildPlan getPlan() { return plan; } + + public void setPlan(GuildPlan plan) { + this.plan = plan; + } + public boolean addPrefix(String prefix){ + if(plan.getPrefixLimit() == -1 || plan.getPrefixLimit() <= getPrefixes().size() + 1) + return getPrefixes().add(prefix); + return false; + } } diff --git a/src/main/java/com/github/codedoctorde/linwood/entity/GuildPlan.java b/src/main/java/com/github/codedoctorde/linwood/entity/GuildPlan.java new file mode 100644 index 00000000..1c7eec36 --- /dev/null +++ b/src/main/java/com/github/codedoctorde/linwood/entity/GuildPlan.java @@ -0,0 +1,16 @@ +package com.github.codedoctorde.linwood.entity; + +public enum GuildPlan { + COMMUNITY, PRO, PRIVATE; + public int getPrefixLimit(){ + switch (this){ + case COMMUNITY: + return 3; + case PRO: + return 10; + case PRIVATE: + return -1; + } + return -1; + } +} diff --git a/src/main/java/com/github/codedoctorde/linwood/entity/NotificationEntity.java b/src/main/java/com/github/codedoctorde/linwood/entity/NotificationEntity.java index 4db78082..fc106f24 100644 --- a/src/main/java/com/github/codedoctorde/linwood/entity/NotificationEntity.java +++ b/src/main/java/com/github/codedoctorde/linwood/entity/NotificationEntity.java @@ -7,6 +7,8 @@ import net.dv8tion.jda.api.entities.TextChannel; import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; @Entity @Table(name = "notification") diff --git a/src/main/java/com/github/codedoctorde/linwood/entity/TeamEntity.java b/src/main/java/com/github/codedoctorde/linwood/entity/TeamEntity.java new file mode 100644 index 00000000..5ab6ee5a --- /dev/null +++ b/src/main/java/com/github/codedoctorde/linwood/entity/TeamEntity.java @@ -0,0 +1,30 @@ +package com.github.codedoctorde.linwood.entity; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@Entity +public class TeamEntity { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private Long id; + @OneToMany + private final List guilds = new ArrayList<>(); + + public TeamEntity(){} + public TeamEntity(GuildEntity ownerGuild, GuildEntity... memberGuilds){ + guilds.add(new TeamMemberEntity(ownerGuild, PermissionLevel.OWNER)); + Arrays.stream(memberGuilds).forEach(guild -> guilds.add(new TeamMemberEntity(guild, PermissionLevel.MEMBER))); + } + + public List getGuilds() { + return guilds; + } + + public Long getId() { + return id; + } +} \ No newline at end of file diff --git a/src/main/java/com/github/codedoctorde/linwood/entity/GlobalGuildEntity.java b/src/main/java/com/github/codedoctorde/linwood/entity/TeamMemberEntity.java similarity index 53% rename from src/main/java/com/github/codedoctorde/linwood/entity/GlobalGuildEntity.java rename to src/main/java/com/github/codedoctorde/linwood/entity/TeamMemberEntity.java index bd990385..b9b6479a 100644 --- a/src/main/java/com/github/codedoctorde/linwood/entity/GlobalGuildEntity.java +++ b/src/main/java/com/github/codedoctorde/linwood/entity/TeamMemberEntity.java @@ -5,19 +5,22 @@ import java.util.List; @Entity -public class GlobalGuildEntity { +public class TeamMemberEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private Long id; - private final long guildId; + @OneToOne + private GuildEntity guild; private PermissionLevel permissionLevel; - private Long globalChat; - private final List syncRolesId = new ArrayList<>(); - public GlobalGuildEntity(Long guildId, PermissionLevel level){ + public TeamMemberEntity(GuildEntity guild, PermissionLevel level){ permissionLevel = level; - this.guildId = guildId; + this.guild = guild; + } + + public TeamMemberEntity() { + } public PermissionLevel getPermissionLevel() { @@ -32,19 +35,7 @@ public Long getId() { return id; } - public long getGuildId() { - return guildId; - } - - public List getSyncRolesId() { - return syncRolesId; - } - - public Long getGlobalChat() { - return globalChat; - } - - public void setGlobalChat(Long globalChat) { - this.globalChat = globalChat; + public GuildEntity getGuild() { + return guild; } } diff --git a/src/main/java/com/github/codedoctorde/linwood/listener/KarmaListener.java b/src/main/java/com/github/codedoctorde/linwood/listener/KarmaListener.java index 56db20b2..13228c12 100644 --- a/src/main/java/com/github/codedoctorde/linwood/listener/KarmaListener.java +++ b/src/main/java/com/github/codedoctorde/linwood/listener/KarmaListener.java @@ -53,7 +53,7 @@ public void onRemove(MessageReactionRemoveEvent event){ return; maybeReset(); event.retrieveMember().queue(donor -> { - var emote = event.getReactionEmote().isEmoji() ? event.getReactionEmote().getAsReactionCode() : event.getReactionEmote().getAsCodepoints(); + var emote = event.getReactionEmote().isEmoji() ? event.getReactionEmote().getAsReactionCode() : event.getReactionEmote().getEmote().getAsMention(); var session = Linwood.getInstance().getDatabase().getSessionFactory().openSession(); var entity = Linwood.getInstance().getDatabase().getGuildById(session, event.getGuild().getIdLong()); var karma = entity.getKarmaEntity(); diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml index 765be286..125eb7f9 100644 --- a/src/main/resources/hibernate.cfg.xml +++ b/src/main/resources/hibernate.cfg.xml @@ -17,5 +17,7 @@ + + \ No newline at end of file diff --git a/src/main/resources/locale/commands/settings/general/AddPrefix_de.properties b/src/main/resources/locale/commands/settings/general/AddPrefix_de.properties index be3dbfa3..2d96884b 100644 --- a/src/main/resources/locale/commands/settings/general/AddPrefix_de.properties +++ b/src/main/resources/locale/commands/settings/general/AddPrefix_de.properties @@ -2,4 +2,4 @@ Success=:white_check_mark: Erfolgreich Prefix `{0}` hinzugefügt! Syntax=settings general addprefix Description=Füge ein Prefix zum Bot hinzu Permission=Server verwalten -Invalid=Dieser Prefix wurde schon hinzugefügt! \ No newline at end of file +Invalid=Dieser Prefix wurde schon hinzugefügt oder du hast das Limit überschritten! \ No newline at end of file diff --git a/src/main/resources/locale/commands/settings/general/AddPrefix_en.properties b/src/main/resources/locale/commands/settings/general/AddPrefix_en.properties index 4e7a138d..e8c17f08 100644 --- a/src/main/resources/locale/commands/settings/general/AddPrefix_en.properties +++ b/src/main/resources/locale/commands/settings/general/AddPrefix_en.properties @@ -2,4 +2,4 @@ Success=:white_check_mark: Successfully add the prefix `{0}`! Syntax=settings general addprefix Description=Add a prefix of the bot Permission=Manage server -Invalid=This prefix is already added! \ No newline at end of file +Invalid=This prefix is already added or you've exceeded the limit! \ No newline at end of file