Skip to content

Commit

Permalink
Implement guild scheduled events (#1134)
Browse files Browse the repository at this point in the history
* Start work for guild scheduled events

* Continued work on implementing scheduled events

* Add events requests to guild service, need to finish up rest stuff

* Finish rest implementation

* Update methods where object models changed due to api changes

* [WIP] Adding stores actions for scheduled events

* feat(scheduled events): implement core and store methods for scheduled events

* fix(timestamp serializing): add jackson jsr310 implementation and configure instant serialization

* doc(guild event): add example bot for guild scheduled events

* fix(serialization): use Set<Long> instead of Set<Id> for guild event users storing in LegacyStoreLayout

* refactor(data accessor): use default methods for new members to ease migraiton

* doc(license): add missing license header in some files

* fix(type inference): fix type inference oddities in LegacyStoreLayout

This refactoring uses an explicit cast to avoid a build error regarding type inference on the Long class in involved method.

* doc(invalid tag): fix invalid tag usage in ScheduledEvent

* Use discord-json snapshots

* Remove all-args Guild#createScheduledEvent method

* Update generators to include enum type as parameter

* Rename interested to subscribed

* Add guild scheduled event payload event names for deserialization

* Add remaining core events for scheduled events

* Fix javadoc

---------

Co-authored-by: NovaFox161 <novamaday@gmail.com>
Co-authored-by: quanticc <abarcab.ivan@gmail.com>
  • Loading branch information
3 people committed Jun 5, 2023
1 parent d703d8d commit 4106965
Show file tree
Hide file tree
Showing 51 changed files with 2,708 additions and 27 deletions.
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,35 @@
/*
* 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.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,36 @@
/*
* 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.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,36 @@
/*
* 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.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() {
}
}

0 comments on commit 4106965

Please sign in to comment.