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 guild scheduled events #1134

Merged
merged 21 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a17b91c
Start work for guild scheduled events
NovaFox161 Nov 15, 2021
1edc0d6
Continued work on implementing scheduled events
NovaFox161 Nov 16, 2021
7d08a3e
Add events requests to guild service, need to finish up rest stuff
NovaFox161 Nov 16, 2021
8c31acb
Finish rest implementation
NovaFox161 Nov 17, 2021
6f43ea5
Update methods where object models changed due to api changes
NovaFox161 Nov 18, 2021
fe58602
[WIP] Adding stores actions for scheduled events
NovaFox161 Dec 2, 2021
a0e3a66
feat(scheduled events): implement core and store methods for schedule…
Gregory-Widmer Apr 10, 2023
fb284fb
fix(timestamp serializing): add jackson jsr310 implementation and con…
Gregory-Widmer Apr 11, 2023
49ddcfb
doc(guild event): add example bot for guild scheduled events
Gregory-Widmer Apr 11, 2023
4431d4a
fix(serialization): use Set<Long> instead of Set<Id> for guild event …
Gregory-Widmer Apr 17, 2023
84484c3
refactor(data accessor): use default methods for new members to ease …
Gregory-Widmer Apr 17, 2023
0911562
doc(license): add missing license header in some files
Gregory-Widmer Apr 17, 2023
6ba6843
fix(type inference): fix type inference oddities in LegacyStoreLayout
Gregory-Widmer Apr 17, 2023
7179a02
doc(invalid tag): fix invalid tag usage in ScheduledEvent
Gregory-Widmer Apr 17, 2023
28bd5f5
Use discord-json snapshots
quanticc May 8, 2023
649a7ae
Remove all-args Guild#createScheduledEvent method
quanticc May 8, 2023
0a61eed
Update generators to include enum type as parameter
quanticc May 8, 2023
bb4fef4
Rename interested to subscribed
quanticc May 8, 2023
df7d6c3
Add guild scheduled event payload event names for deserialization
quanticc May 8, 2023
a322eb5
Add remaining core events for scheduled events
quanticc Jun 5, 2023
6f1b9f2
Fix javadoc
quanticc Jun 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ext {
// Dependencies
reactor_bom_version = '2020.0.30'
jackson_databind_version = '2.12.7.1'
jackson_datatype_jsr310_version = '2.14.2'
jackson_datatype_jdk8_version = '2.12.7'
caffeine_version = '2.8.8'
immutables_group = 'org.immutables'
Expand Down Expand Up @@ -58,6 +59,7 @@ allprojects {

dependencies {
api platform("io.projectreactor:reactor-bom:$reactor_bom_version")
api "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_datatype_jsr310_version"
api "com.discord4j:discord-json:$discordJsonVersion"
}

Expand Down
4 changes: 4 additions & 0 deletions common/src/main/java/discord4j/common/JacksonResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import discord4j.common.jackson.UnknownPropertyHandler;
import discord4j.discordjson.possible.PossibleFilter;
import discord4j.discordjson.possible.PossibleModule;
Expand All @@ -39,6 +41,8 @@ public class JacksonResources {
*/
public static final Function<ObjectMapper, ObjectMapper> INITIALIZER = mapper -> mapper
.registerModule(new PossibleModule())
.registerModule(new JavaTimeModule())
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.registerModule(new Jdk8Module())
.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.PUBLIC_ONLY)
Expand Down
12 changes: 12 additions & 0 deletions common/src/main/java/discord4j/common/store/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ private static ActionMapper dataAccessorToMapper(DataAccessor dataAccessor) {
.getVoiceStatesInGuild(action.getGuildId()))
.map(GetVoiceStateByIdAction.class, action -> dataAccessor
.getVoiceStateById(action.getGuildId(), action.getUserId()))
.map(GetGuildScheduledEventsInGuildAction.class, action -> dataAccessor
.getScheduledEventsInGuild(action.getGuildId()))
.map(GetGuildScheduledEventByIdAction.class, action -> dataAccessor
.getScheduledEventById(action.getGuildId(), action.getEventId()))
.map(GetGuildScheduledEventUsersInEventAction.class, action -> dataAccessor
.getScheduledEventUsersInEvent(action.getGuildId(), action.getEventId()))
.build();
}

Expand Down Expand Up @@ -208,6 +214,12 @@ private static ActionMapper gatewayDataUpdaterToMapper(GatewayDataUpdater gatewa
.onGuildRoleDelete(action.getShardIndex(), action.getGuildRoleDelete()))
.map(GuildRoleUpdateAction.class, action -> gatewayDataUpdater
.onGuildRoleUpdate(action.getShardIndex(), action.getGuildRoleUpdate()))
.map(GuildScheduledEventCreateAction.class, action -> gatewayDataUpdater
.onGuildScheduledEventCreate(action.getShardIndex(), action.getGuildScheduledEventCreate()))
.map(GuildScheduledEventUpdateAction.class, action -> gatewayDataUpdater
.onGuildScheduledEventUpdate(action.getShardIndex(), action.getGuildScheduledEventUpdate()))
.map(GuildScheduledEventDeleteAction.class, action -> gatewayDataUpdater
.onGuildScheduledEventDelete(action.getShardIndex(), action.getGuildScheduledEventDelete()))
.map(GuildUpdateAction.class, action -> gatewayDataUpdater
.onGuildUpdate(action.getShardIndex(), action.getGuildUpdate()))
.map(InvalidateShardAction.class, action -> gatewayDataUpdater
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,64 @@ public static GuildRoleUpdateAction guildRoleUpdate(int shardIndex, GuildRoleUpd
return new GuildRoleUpdateAction(shardIndex, dispatch);
}

/**
* Creates an action to execute when a {@link GuildScheduledEventCreate} is received from the gateway.
*
* @param shardIndex the index of the shard where the dispatch comes from
* @param dispatch the dispatch data coming from Discord gateway
* @return a new {@link GuildScheduledEventCreate}
*/
public static GuildScheduledEventCreateAction guildScheduledEventCreate(int shardIndex, GuildScheduledEventCreate dispatch) {
return new GuildScheduledEventCreateAction(shardIndex, dispatch);
}

/**
* Creates an action to execute when a {@link GuildScheduledEventUpdate} is received from the gateway.
*
* @param shardIndex the index of the shard where the dispatch comes from
* @param dispatch the dispatch data coming from Discord gateway
* @return a new {@link GuildScheduledEventUpdate}
*/
public static GuildScheduledEventUpdateAction guildScheduledEventUpdate(int shardIndex, GuildScheduledEventUpdate dispatch) {
return new GuildScheduledEventUpdateAction(shardIndex, dispatch);
}

/**
* Creates an action to execute when a {@link GuildScheduledEventDelete} is received from the gateway.
*
* @param shardIndex the index of the shard where the dispatch comes from
* @param dispatch the dispatch data coming from Discord gateway
* @return a new {@link GuildScheduledEventDelete}
*/
public static GuildScheduledEventDeleteAction guildScheduledEventDelete(int shardIndex, GuildScheduledEventDelete dispatch) {
return new GuildScheduledEventDeleteAction(shardIndex, dispatch);
}


/**
* Creates an action to execute when a {@link GuildScheduledEventUserAdd} is received from the gateway.
*
* @param shardIndex the index of the shard where the dispatch comes from
* @param dispatch the dispatch data coming from Discord gateway
* @return a new {@link GuildScheduledEventUserAddAction}
*/
public static GuildScheduledEventUserAddAction guildScheduledEventUserAdd(int shardIndex,
GuildScheduledEventUserAdd dispatch) {
return new GuildScheduledEventUserAddAction(shardIndex, dispatch);
}

/**
* Creates an action to execute when a {@link GuildScheduledEventUserRemove} is received from the gateway.
*
* @param shardIndex the index of the shard where the dispatch comes from
* @param dispatch the dispatch data coming from Discord gateway
* @return a new {@link GuildScheduledEventUserRemoveAction}
*/
public static GuildScheduledEventUserRemoveAction guildScheduledEventUserRemove(int shardIndex,
GuildScheduledEventUserRemove dispatch) {
return new GuildScheduledEventUserRemoveAction(shardIndex, dispatch);
}

/**
* Creates an action to execute when a {@link GuildUpdate} is received from the gateway.
*
Expand Down Expand Up @@ -350,4 +408,5 @@ public static VoiceStateUpdateDispatchAction voiceStateUpdateDispatch(int shardI
public static CompleteGuildMembersAction completeGuildMembers(long guildId) {
return new CompleteGuildMembersAction(guildId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package discord4j.common.store.action.gateway;
Gregory-Widmer marked this conversation as resolved.
Show resolved Hide resolved

import discord4j.discordjson.json.gateway.GuildScheduledEventCreate;

public class GuildScheduledEventCreateAction extends ShardAwareAction<Void> {

private final GuildScheduledEventCreate guildScheduledEventCreate;

GuildScheduledEventCreateAction(int shardIndex, GuildScheduledEventCreate guildScheduledEventCreate) {
super(shardIndex);
this.guildScheduledEventCreate = guildScheduledEventCreate;
}

public GuildScheduledEventCreate getGuildScheduledEventCreate() {
return guildScheduledEventCreate;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package discord4j.common.store.action.gateway;

import discord4j.discordjson.json.GuildScheduledEventData;
import discord4j.discordjson.json.gateway.GuildScheduledEventDelete;

public class GuildScheduledEventDeleteAction extends ShardAwareAction<GuildScheduledEventData> {

private final GuildScheduledEventDelete guildScheduledEventDelete;

GuildScheduledEventDeleteAction(int shardIndex, GuildScheduledEventDelete guildScheduledEventDelete) {
super(shardIndex);
this.guildScheduledEventDelete = guildScheduledEventDelete;
}

public GuildScheduledEventDelete getGuildScheduledEventDelete() {
return guildScheduledEventDelete;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package discord4j.common.store.action.gateway;

import discord4j.discordjson.json.GuildScheduledEventData;
import discord4j.discordjson.json.gateway.GuildScheduledEventUpdate;

public class GuildScheduledEventUpdateAction extends ShardAwareAction<GuildScheduledEventData> {

private final GuildScheduledEventUpdate guildScheduledEventUpdate;

GuildScheduledEventUpdateAction(int shardIndex, GuildScheduledEventUpdate guildScheduledEventUpdate) {
super(shardIndex);
this.guildScheduledEventUpdate = guildScheduledEventUpdate;
}

public GuildScheduledEventUpdate getGuildScheduledEventUpdate() {
return guildScheduledEventUpdate;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* This file is part of Discord4J.
*
* Discord4J is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Discord4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Discord4J. If not, see <http://www.gnu.org/licenses/>.
*/

package discord4j.common.store.action.gateway;

import discord4j.discordjson.json.gateway.GuildScheduledEventUserAdd;

public class GuildScheduledEventUserAddAction extends ShardAwareAction<Void> {

private final GuildScheduledEventUserAdd userAdd;

public GuildScheduledEventUserAddAction(int shardIndex, GuildScheduledEventUserAdd userAdd) {
super(shardIndex);
this.userAdd = userAdd;
}

public GuildScheduledEventUserAdd getUserAdd() {
return userAdd;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* This file is part of Discord4J.
*
* Discord4J is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Discord4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Discord4J. If not, see <http://www.gnu.org/licenses/>.
*/

package discord4j.common.store.action.gateway;

import discord4j.discordjson.json.gateway.GuildScheduledEventUserRemove;

public class GuildScheduledEventUserRemoveAction extends ShardAwareAction<Void>{

private final GuildScheduledEventUserRemove userRemove;

public GuildScheduledEventUserRemoveAction(int shardIndex, GuildScheduledEventUserRemove userRemove) {
super(shardIndex);
this.userRemove = userRemove;
}

public GuildScheduledEventUserRemove getUserRemove() {
return userRemove;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of Discord4J.
*
* Discord4J is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Discord4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Discord4J. If not, see <http://www.gnu.org/licenses/>.
*/

package discord4j.common.store.action.read;

import discord4j.common.store.api.StoreAction;
import discord4j.discordjson.json.GuildScheduledEventData;

public class GetGuildScheduledEventByIdAction implements StoreAction<GuildScheduledEventData> {

private final long guildId;

private final long eventId;

GetGuildScheduledEventByIdAction(long guildId, long eventId) {
this.guildId = guildId;
this.eventId = eventId;
}

public long getGuildId() {
return guildId;
}

public long getEventId() {
return eventId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This file is part of Discord4J.
*
* Discord4J is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Discord4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Discord4J. If not, see <http://www.gnu.org/licenses/>.
*/

package discord4j.common.store.action.read;

import discord4j.common.store.api.StoreAction;
import discord4j.discordjson.json.GuildScheduledEventUserData;

public class GetGuildScheduledEventUsersAction implements StoreAction<GuildScheduledEventUserData> {

GetGuildScheduledEventUsersAction() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of Discord4J.
*
* Discord4J is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Discord4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Discord4J. If not, see <http://www.gnu.org/licenses/>.
*/

package discord4j.common.store.action.read;

import discord4j.common.store.api.StoreAction;
import discord4j.discordjson.Id;
import discord4j.discordjson.json.GuildScheduledEventUserData;

public class GetGuildScheduledEventUsersInEventAction implements StoreAction<Id> {

private final long guildId;
private final long eventId;

public GetGuildScheduledEventUsersInEventAction(long guildId, long eventId) {
this.guildId = guildId;
this.eventId = eventId;
}

public long getGuildId() {
return guildId;
}

public long getEventId() {
return eventId;
}
}