Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.codedoctorde</groupId>
<artifactId>linwood</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> aliases(GuildEntity entity) {
return null;
}

@Override
public @NotNull ResourceBundle getBundle(GuildEntity entity) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -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<String> aliases(GuildEntity entity) {
return null;
}

@Override
public @NotNull ResourceBundle getBundle(GuildEntity entity) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -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<String> aliases(GuildEntity entity) {
return null;
}

@Override
public @NotNull ResourceBundle getBundle(GuildEntity entity) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -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<String> aliases(GuildEntity entity) {
return null;
}

@Override
public @NotNull ResourceBundle getBundle(GuildEntity entity) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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(){
}
Expand Down Expand Up @@ -81,10 +78,7 @@ public KarmaEntity getKarmaEntity() {
}

public NotificationEntity getNotificationEntity() {
if(notificationEntity != null)
return notificationEntity;
else
return null;
}

public Long getMaintainerId() {
Expand All @@ -111,7 +105,16 @@ public Set<String> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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<TeamMemberEntity> 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<TeamMemberEntity> getGuilds() {
return guilds;
}

public Long getId() {
return id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> 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() {
Expand All @@ -32,19 +35,7 @@ public Long getId() {
return id;
}

public long getGuildId() {
return guildId;
}

public List<Long> getSyncRolesId() {
return syncRolesId;
}

public Long getGlobalChat() {
return globalChat;
}

public void setGlobalChat(Long globalChat) {
this.globalChat = globalChat;
public GuildEntity getGuild() {
return guild;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
<mapping class="com.github.codedoctorde.linwood.entity.MemberEntity"/>
<mapping class="com.github.codedoctorde.linwood.entity.KarmaEntity"/>
<mapping class="com.github.codedoctorde.linwood.entity.NotificationEntity"/>
<mapping class="com.github.codedoctorde.linwood.entity.TeamEntity"/>
<mapping class="com.github.codedoctorde.linwood.entity.TeamMemberEntity"/>
</session-factory>
</hibernate-configuration>
Loading