Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement recurrence rule for Guild Scheduled Event #188

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ static ImmutableGuildScheduledEventCreateRequest.Builder builder() {
int entityType();

Possible<String> image();

@JsonProperty("recurrence_rule")
Possible<RecurrenceRuleData> recurrenceRule();
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ static ImmutableGuildScheduledEventData.Builder builder() {
Possible<Integer> userCount();

Possible<Optional<String>> image();

@JsonProperty("recurrence_rule")
Optional<RecurrenceRuleData> recurrenceRule();
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ static ImmutableGuildScheduledEventModifyRequest.Builder builder() {
Possible<Integer> status();

Possible<String> image();

@JsonProperty("recurrence_rule")
Possible<RecurrenceRuleData> recurrenceRule();
Doc94 marked this conversation as resolved.
Show resolved Hide resolved
}
44 changes: 44 additions & 0 deletions src/main/java/discord4j/discordjson/json/RecurrenceRuleData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package discord4j.discordjson.json;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutableRecurrenceRuleData.class)
@JsonDeserialize(as = ImmutableRecurrenceRuleData.class)
public interface RecurrenceRuleData {

static ImmutableRecurrenceRuleData.Builder builder() {
return ImmutableRecurrenceRuleData.builder();
}

Instant start();

Optional<Instant> end();

int frequency();

int interval();

@JsonProperty("by_weekday")
Optional<List<Integer>> byWeekday();

@JsonProperty("by_n_weekday")
Optional<List<RecurrenceRuleNWeekdayData>> byNWeekday();

@JsonProperty("by_month")
Optional<List<Integer>> byMonth();

@JsonProperty("by_month_day")
Optional<List<Integer>> byMonthDay();

@JsonProperty("by_year_day")
Optional<List<Integer>> byYearDay();

Optional<Integer> count();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package discord4j.discordjson.json;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutableRecurrenceRuleNWeekdayData.class)
@JsonDeserialize(as = ImmutableRecurrenceRuleNWeekdayData.class)
public interface RecurrenceRuleNWeekdayData {

static ImmutableRecurrenceRuleNWeekdayData.Builder builder() {
return ImmutableRecurrenceRuleNWeekdayData.builder();
}

int n();

int day();

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import discord4j.discordjson.Id;
import discord4j.discordjson.json.*;
import discord4j.discordjson.possible.PossibleFilter;
Expand All @@ -36,6 +37,7 @@ public class RestDeserializationTest {
public void setUp() {
mapper = new ObjectMapper()
.registerModule(new PossibleModule())
.registerModule(new JavaTimeModule())
.registerModule(new Jdk8Module())
.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.PUBLIC_ONLY)
Expand Down Expand Up @@ -241,4 +243,10 @@ public void readApplicationInfoData() throws IOException {
ApplicationInfoData data = read("/rest/ApplicationInfoData.json", ApplicationInfoData.class);
log.info("{}", data);
}

@Test
public void readGuildScheduledEvents() throws IOException {
GuildScheduledEventData[] data = read("/rest/GuildScheduledEventData.json", GuildScheduledEventData[].class);
log.info("{}", Arrays.asList(data));
}
}
45 changes: 23 additions & 22 deletions src/test/resources/gateway/GuildScheduledEventCreate.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
{
"t": "GUILD_SCHEDULED_EVENT_CREATE",
"s": 14,
"op": 0,
"d": {
"status": 1,
"sku_ids": [],
"scheduled_start_time": "2023-06-18T21:00:00+00:00",
"scheduled_end_time": "2023-06-18T22:00:00+00:00",
"privacy_level": 2,
"name": "___: _______",
"image": null,
"id": "1120073806816489582",
"guild_id": "935234113919660033",
"entity_type": 3,
"entity_metadata": {
"location": "TBA"
},
"entity_id": null,
"description": null,
"creator_id": "1026096354201714799",
"channel_id": null
}
"t": "GUILD_SCHEDULED_EVENT_CREATE",
"s": 14,
"op": 0,
"d": {
"status": 1,
"sku_ids": [],
"scheduled_start_time": "2023-06-18T21:00:00+00:00",
"scheduled_end_time": "2023-06-18T22:00:00+00:00",
"privacy_level": 2,
"name": "___: _______",
"image": null,
"id": "1120073806816489582",
"guild_id": "935234113919660033",
"entity_type": 3,
"entity_metadata": {
"location": "TBA"
},
"entity_id": null,
"description": null,
"creator_id": "1026096354201714799",
"channel_id": null,
"recurrence_rule": null
}
}
55 changes: 55 additions & 0 deletions src/test/resources/rest/GuildScheduledEventData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[
{
"id": "1271851224307732633",
"guild_id": "545819046294192128",
"name": "A good event",
"description": "The best party for social media",
"channel_id": "545819046294192132",
"creator_id": "216316781483130880",
"creator": {
"id": "216316781483130880",
"username": "doc",
"avatar": "b7a8560e5ece2d003b38f87a96e9b354",
"discriminator": "0",
"public_flags": 4194562,
"flags": 4194562,
"banner": "350f1d70ddc02a0082084879bb15e7ba",
"accent_color": null,
"global_name": "Doc",
"avatar_decoration_data": {
"asset": "a_65db91cee351e36150a2b506b26eba71",
"sku_id": "1252353273256480818",
"expires_at": null
},
"banner_color": null,
"clan": null
},
"image": "20521a3e71d0a45b1c025ecbdf86a3a2",
"scheduled_start_time": "2024-08-16T16:00:00+00:00",
"scheduled_end_time": null,
"status": 1,
"entity_type": 2,
"entity_id": null,
"recurrence_rule": {
"start": "2024-08-16T16:00:00+00:00",
"end": null,
"frequency": 1,
"interval": 1,
"by_weekday": null,
"by_n_weekday": [
{
"n": 3,
"day": 4
}
],
"by_month": null,
"by_month_day": null,
"by_year_day": null,
"count": null
},
"privacy_level": 2,
"sku_ids": [],
"guild_scheduled_event_exceptions": [],
"entity_metadata": {}
}
]