Skip to content

Commit

Permalink
Removed spam_count from member data
Browse files Browse the repository at this point in the history
...and updated data classes according to new comment on #31
  • Loading branch information
Gregor7008 committed Nov 30, 2022
1 parent 6c15813 commit 4795230
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/main/java/assets/data/MemberData.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ public class MemberData implements DataContainer {

private final Guild guild;
private Category custom_category;
private int experience, last_penalty_index, level, levelcard_background, spam_count = 0;
private int experience, last_penalty_index, level, levelcard_background = 0;
private Language language = Language.ENGLISH;
private OffsetDateTime last_experience, last_modmail, last_suggestion, temporarily_banned_until = OffsetDateTime.now().minusDays(1L);
private ConcurrentHashMap<Integer, ModMailData> modmails = new ConcurrentHashMap<>();
private boolean permanently_muted = false;
private List<WarningData> warnings = new LinkedList<>();

// Temporary runtime data
private int spam_count = 0;

public MemberData(Guild guild, JSONObject data) {
this.guild = guild;
Expand All @@ -46,7 +49,6 @@ public DataContainer instanciateFromJSON(JSONObject data) {
this.last_penalty_index = data.getInt(Key.LAST_PENALTY_INDEX);
this.level = data.getInt(Key.LEVEL);
this.levelcard_background = data.getInt(Key.LEVELCARD_BACKGROUND);
this.spam_count = data.getInt(Key.SPAM_COUNT);

this.language = Language.valueOf(data.getString(Key.LANGUAGE));

Expand Down Expand Up @@ -87,7 +89,6 @@ public JSONObject compileToJSON() {
compiledData.put(Key.LAST_PENALTY_INDEX, last_penalty_index);
compiledData.put(Key.LEVEL, level);
compiledData.put(Key.LEVELCARD_BACKGROUND, levelcard_background);
compiledData.put(Key.SPAM_COUNT, spam_count);

compiledData.put(Key.LANGUAGE, language.toString());

Expand Down Expand Up @@ -363,7 +364,6 @@ private static abstract class Key {
public static final String LEVELCARD_BACKGROUND = "levelcard_background";
public static final String MODMAILS = "modmails";
public static final String PERMANENTLY_MUTED = "permanently_muted";
public static final String SPAM_COUNT = "spam_count";
public static final String TEMPORARILY_BANNED_UNTIL = "temporarily_banned_until";
public static final String WARNINGS = "warnings";
}
Expand Down
62 changes: 58 additions & 4 deletions src/main/java/assets/data/single/GiveawayData.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,84 @@
package assets.data.single;

import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import assets.data.DataContainer;
import base.Bot;
import engines.base.CentralTimer;
import engines.data.ConfigManager;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;

public class GiveawayData implements DataContainer {

private final Guild guild;
private final TextChannel text_channel;
private final Message message;
private final User user;
private Message message;
private String title, description = "N/A";
private boolean anonymous = false;
private OffsetDateTime time_limit = OffsetDateTime.now().plusWeeks(1);
private List<String> prizes = new LinkedList<>();
private List<Member> sign_ups = new LinkedList<>();
private List<Role> allowed_roles = new LinkedList<>();

// Temporary runtime data
private long timer_operation_id = 0L;

public GiveawayData(Message message, JSONObject data) {
this.guild = message.getGuild();
this.text_channel = message.getChannel().asTextChannel();
this.message = message;
this.user = Bot.INSTANCE.jda.retrieveUserById(data.getLong(Key.USER_ID)).complete();
this.instanciateFromJSON(data);
}

public GiveawayData(Message message, User user) {
this.text_channel = message.getChannel().asTextChannel();
this.message = message;
public GiveawayData(Guild guild, TextChannel channel, User user) {
this.guild = guild;
this.text_channel = channel;
this.user = user;
}

@Override
public DataContainer instanciateFromJSON(JSONObject data) {
this.title = data.getString(Key.TITLE);
this.description = this.message.getEmbeds().get(0).getDescription();

this.anonymous = data.getBoolean(Key.ANONYMOUS);

this.time_limit = OffsetDateTime.parse(data.getString(Key.TIME_LIMIT), ConfigManager.DATA_TIME_SAVE_FORMAT);
this.timer_operation_id = CentralTimer.get().schedule(() -> message.editMessageEmbeds(buildEndEmbed()).setComponents().queue(), this.time_limit);

JSONArray prizes_array = data.getJSONArray(Key.PRIZES);
for (int i = 0; i < prizes_array.length(); i++) {
this.prizes.add(prizes_array.getString(i));
}

JSONArray sign_ups_array = data.getJSONArray(Key.SIGN_UPS);
List<Long> memberIds = new ArrayList<>();
for (int i = 0; i < sign_ups_array.length(); i++) {
memberIds.add(sign_ups_array.getLong(i));
}
this.sign_ups.addAll(guild.retrieveMembersByIds(memberIds).get());
this.sign_ups.removeAll(Collections.singleton(null));

JSONArray allowed_roles_array = data.getJSONArray(Key.ALLOWED_ROLES);
for (int i = 0; i < allowed_roles_array.length(); i++) {
this.allowed_roles.add(guild.getRoleById(allowed_roles_array.getLong(i)));
this.allowed_roles.removeAll(Collections.singleton(null));
}
return this;
}

Expand All @@ -50,6 +99,11 @@ public Message getMessage() {
public User getUser() {
return this.user;
}

private MessageEmbed buildEndEmbed() {
// TODO Implement 'buildEndEmbed()' method
return null;
}

private static abstract class Key {
public static final String USER_ID = "user_id";
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/assets/data/single/Join2CreateChannelData.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ public Join2CreateChannelData setConfigurable(boolean configurable) {
return this;
}

/* TODO Transfer & Adapt tool methods from 'EventProcessor.class' to here
* This includes....
* 1. Creation of a new J2C-Channel incl. Formatting
* 2. Deletion of an old J2C-Channel including the...
* 3. Processing of remaining J2C-Channels
*/

private static abstract class Key {
public static final String NAME_FORMAT = "name_format";
public static final String LIMIT_PRESET = "limit_preset";
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/assets/data/single/ReactionRoleData.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

public class ReactionRoleData implements DataContainer {

// TODO Implement completely

public ReactionRoleData(JSONObject data) {
this.instanciateFromJSON(data);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/assets/data/single/WarningData.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

public class WarningData implements DataContainer {

// TODO Implement completely incl. ModController notification

public WarningData(JSONObject data) {
this.instanciateFromJSON(data);
}
Expand Down

0 comments on commit 4795230

Please sign in to comment.