-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(events): implemented more gateway events
- Loading branch information
Showing
10 changed files
with
433 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/seailz/discordjar/events/model/channel/ChannelEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.seailz.discordjar.events.model.channel; | ||
|
||
import com.seailz.discordjar.DiscordJar; | ||
import com.seailz.discordjar.events.model.Event; | ||
import com.seailz.discordjar.model.channel.Channel; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.json.JSONObject; | ||
|
||
public class ChannelEvent extends Event { | ||
public ChannelEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { | ||
super(bot, sequence, data); | ||
} | ||
|
||
public Channel getChannel() { | ||
return Channel.decompile(getJson(), getBot()); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/com/seailz/discordjar/events/model/channel/ChannelPinsUpdateEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.seailz.discordjar.events.model.channel; | ||
|
||
import com.seailz.discordjar.DiscordJar; | ||
import com.seailz.discordjar.events.model.Event; | ||
import com.seailz.discordjar.model.channel.Channel; | ||
import com.seailz.discordjar.model.channel.MessagingChannel; | ||
import com.seailz.discordjar.model.guild.Guild; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.json.JSONObject; | ||
|
||
import java.util.Date; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
/** | ||
* Dispatched when the pins for a channel are updated. This could be because: | ||
* <ul> | ||
* <li>A message was pinned</li> | ||
* <li>A message was unpinned</li> | ||
* </ul> | ||
* <p>It is not dispatched when a pinned message is deleted.</p> | ||
*/ | ||
public class ChannelPinsUpdateEvent extends Event { | ||
|
||
private String guildId; | ||
private Guild guild; | ||
private String channelId; | ||
private Channel channel; | ||
private LocalDateTime lastPinTimestamp; | ||
|
||
|
||
public ChannelPinsUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { | ||
super(bot, sequence, data); | ||
|
||
guildId = data.has("guild_id") ? data.getString("guild_id") : null; | ||
channelId = data.getString("channel_id"); | ||
// last_pin_timestamp is a iso8601 timestamp, so we need to get a Date object from it | ||
if (data.has("last_pin_timestamp")) { | ||
String timestampString = data.getString("last_pin_timestamp"); | ||
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; | ||
lastPinTimestamp = LocalDateTime.parse(timestampString, formatter); | ||
} | ||
} | ||
|
||
@Nullable | ||
public String getGuildId() { | ||
return guildId; | ||
} | ||
|
||
@Nullable | ||
public Guild getGuild() { | ||
if (guild == null && guildId != null) | ||
guild = getBot().getGuildById(guildId); | ||
return guild; | ||
} | ||
|
||
@NotNull | ||
public String getChannelId() { | ||
return channelId; | ||
} | ||
|
||
@Nullable | ||
public Channel getChannel() { | ||
if (channel == null) | ||
channel = getBot().getChannelById(channelId); | ||
return channel; | ||
} | ||
|
||
/** | ||
* The time at which the most recent pinned msg was pinned. | ||
*/ | ||
@Nullable | ||
public LocalDateTime getLastPinTimestamp() { | ||
return lastPinTimestamp; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelCreateEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.seailz.discordjar.events.model.channel.edit; | ||
|
||
import com.seailz.discordjar.DiscordJar; | ||
import com.seailz.discordjar.events.model.Event; | ||
import com.seailz.discordjar.events.model.channel.ChannelEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.json.JSONObject; | ||
|
||
public class ChannelCreateEvent extends ChannelEvent { | ||
public ChannelCreateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { | ||
super(bot, sequence, data); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelDeleteEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.seailz.discordjar.events.model.channel.edit; | ||
|
||
import com.seailz.discordjar.DiscordJar; | ||
import com.seailz.discordjar.events.model.channel.ChannelEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.json.JSONObject; | ||
|
||
public class ChannelDeleteEvent extends ChannelEvent { | ||
public ChannelDeleteEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { | ||
super(bot, sequence, data); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelUpdateEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.seailz.discordjar.events.model.channel.edit; | ||
|
||
import com.seailz.discordjar.DiscordJar; | ||
import com.seailz.discordjar.events.model.channel.ChannelEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.json.JSONObject; | ||
|
||
public class ChannelUpdateEvent extends ChannelEvent { | ||
public ChannelUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { | ||
super(bot, sequence, data); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/seailz/discordjar/events/model/guild/GuildDeleteEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.seailz.discordjar.events.model.guild; | ||
|
||
import com.seailz.discordjar.DiscordJar; | ||
import com.seailz.discordjar.events.model.Event; | ||
import com.seailz.discordjar.model.guild.UnavailableGuild; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* Sent when the guild becomes or was already unavailable due to an outage, or when the user leaves or is removed from a guild. | ||
*/ | ||
public class GuildDeleteEvent extends Event { | ||
|
||
private UnavailableGuild guild; | ||
|
||
public GuildDeleteEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { | ||
super(bot, sequence, data); | ||
guild = UnavailableGuild.decompile(getJson().getJSONObject("d"), getBot()); | ||
} | ||
|
||
/** | ||
* Returns the {@link UnavailableGuild} that was deleted. | ||
* @return {@link UnavailableGuild} object. | ||
*/ | ||
public UnavailableGuild getGuild() { | ||
return guild; | ||
} | ||
|
||
/** | ||
* Returns true if the current user was removed from the guild. | ||
*/ | ||
public boolean wasRemoved() { | ||
return !getJson().getJSONObject("d").has("unavailable") || !getJson().getJSONObject("d").getBoolean("unavailable"); | ||
} | ||
|
||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/seailz/discordjar/events/model/guild/GuildUpdateEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.seailz.discordjar.events.model.guild; | ||
|
||
import com.seailz.discordjar.DiscordJar; | ||
import com.seailz.discordjar.events.model.Event; | ||
import com.seailz.discordjar.model.guild.Guild; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.json.JSONObject; | ||
|
||
public class GuildUpdateEvent extends Event { | ||
public GuildUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { | ||
super(bot, sequence, data); | ||
} | ||
|
||
@NotNull | ||
public Guild getGuild() { | ||
return Guild.decompile(getJson().getJSONObject("d"), getBot()); | ||
} | ||
} |
Oops, something went wrong.