Skip to content

Commit

Permalink
Add VoiceChannelEffectSendEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
freya022 committed Oct 16, 2024
1 parent ef28ed6 commit bf699f4
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.ISnowflake;
import net.dv8tion.jda.api.entities.SoundboardSound;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.attribute.IAgeRestrictedChannel;
import net.dv8tion.jda.api.entities.channel.attribute.ISlowmodeChannel;
import net.dv8tion.jda.api.entities.channel.attribute.IVoiceStatusChannel;
Expand All @@ -25,11 +28,13 @@
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildChannel;
import net.dv8tion.jda.api.entities.emoji.EmojiUnion;
import net.dv8tion.jda.api.managers.channel.concrete.VoiceChannelManager;
import net.dv8tion.jda.api.requests.restaction.ChannelAction;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Represents a Discord Voice GuildChannel.
Expand Down Expand Up @@ -73,4 +78,107 @@ default ChannelAction<VoiceChannel> createCopy()
@Override
@CheckReturnValue
VoiceChannelManager getManager();

class Effect
{
private final VoiceChannel channel;
private final User user;
private final EmojiUnion emoji;
private final Animation animation;
private final SoundboardSound soundboardSound;

public Effect(VoiceChannel channel, User user, EmojiUnion emoji, Animation animation, SoundboardSound soundboardSound)
{
this.channel = channel;
this.user = user;
this.emoji = emoji;
this.animation = animation;
this.soundboardSound = soundboardSound;
}

@Nonnull
public VoiceChannel getChannel()
{
return channel;
}

@Nonnull
public User getUser()
{
return user;
}

@Nullable
public EmojiUnion getEmoji()
{
return emoji;
}

@Nullable
public Animation getAnimation()
{
return animation;
}

@Nullable
public SoundboardSound getSoundboardSound()
{
return soundboardSound;
}

public static class Animation implements ISnowflake
{
public Animation(long id, Type type)
{
this.id = id;
this.type = type;
}

private final long id;
private final Type type;

@Override
public long getIdLong()
{
return id;
}

@Nonnull
public Type getType()
{
return type;
}

public enum Type
{
UNKNOWN(-1),
PREMIUM(0),
BASIC(1);

private final int value;

Type(int value)
{
this.value = value;
}

public int getValue()
{
return value;
}

@Nonnull
public static Type fromValue(int value)
{
for (Type type : values())
{
if (type.value == value)
return type;
}

return UNKNOWN;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.api.events.channel;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;

import javax.annotation.Nonnull;

/**
* Indicates that a {@link VoiceChannel.Effect voice channel effect} was sent in a {@link VoiceChannel}.
*/
public class VoiceChannelEffectSendEvent extends GenericChannelEvent
{
private final VoiceChannel.Effect effect;

public VoiceChannelEffectSendEvent(@Nonnull JDA api, long responseNumber, Channel channel, VoiceChannel.Effect effect)
{
super(api, responseNumber, channel);
this.effect = effect;
}

@Nonnull
public VoiceChannel getVoiceChannel()
{
return getChannel().asVoiceChannel();
}

@Nonnull
public VoiceChannel.Effect getEffect()
{
return effect;
}
}
4 changes: 4 additions & 0 deletions src/main/java/net/dv8tion/jda/api/hooks/ListenerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.dv8tion.jda.api.events.channel.ChannelCreateEvent;
import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent;
import net.dv8tion.jda.api.events.channel.GenericChannelEvent;
import net.dv8tion.jda.api.events.channel.VoiceChannelEffectSendEvent;
import net.dv8tion.jda.api.events.channel.forum.ForumTagAddEvent;
import net.dv8tion.jda.api.events.channel.forum.ForumTagRemoveEvent;
import net.dv8tion.jda.api.events.channel.forum.GenericForumTagEvent;
Expand Down Expand Up @@ -385,6 +386,9 @@ public void onSoundboardSoundUpdateName(@Nonnull SoundboardSoundUpdateNameEvent
public void onSoundboardSoundUpdateVolume(@Nonnull SoundboardSoundUpdateVolumeEvent event) {}
public void onSoundboardSoundUpdateEmoji(@Nonnull SoundboardSoundUpdateEmojiEvent event) {}

// Voice channel effect events
public void onVoiceChannelEffectSend(@Nonnull VoiceChannelEffectSendEvent event) {}

// Entitlement events
public void onEntitlementCreate(@Nonnull EntitlementCreateEvent event) {}
public void onEntitlementUpdate(@Nonnull EntitlementUpdateEvent event) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.internal.handle;

import net.dv8tion.jda.api.entities.SoundboardSound;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel.Effect;
import net.dv8tion.jda.api.entities.emoji.EmojiUnion;
import net.dv8tion.jda.api.events.channel.VoiceChannelEffectSendEvent;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.JDAImpl;
import net.dv8tion.jda.internal.entities.EntityBuilder;
import net.dv8tion.jda.internal.entities.GuildImpl;

public class VoiceChannelEffectSendHandler extends SocketHandler
{
public VoiceChannelEffectSendHandler(JDAImpl api)
{
super(api);
}

@Override
protected Long handleInternally(DataObject content)
{
final long guildId = content.getLong("guild_id");
if (getJDA().getGuildSetupController().isLocked(guildId))
return guildId;

GuildImpl guild = (GuildImpl) getJDA().getGuildById(guildId);
if (guild == null)
{
getJDA().getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle);
return null;
}

final long channelId = content.getLong("channel_id");
VoiceChannel channel = guild.getVoiceChannelById(channelId);
if (channel == null)
{
getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
return null;
}

User user = api.getUserById(content.getString("user_id"));
EmojiUnion emoji = content.optObject("emoji").map(EntityBuilder::createEmoji).orElse(null);
Effect.Animation animation = content.opt("animation_type")
.map(rawAnimationType ->
{
long animationId = content.getLong("animation_id");
Effect.Animation.Type type = Effect.Animation.Type.fromValue(Integer.parseInt(rawAnimationType.toString()));
return new Effect.Animation(animationId, type);
})
.orElse(null);
SoundboardSound soundboardSound = content.opt("sound_id")
.map(soundId -> guild.getSoundboardSoundById(soundId.toString()))
.orElse(null);

Effect effect = new Effect(channel, user, emoji, animation, soundboardSound);

api.handleEvent(new VoiceChannelEffectSendEvent(api, responseNumber, channel, effect));

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,7 @@ protected void setupHandlers()
handlers.put("GUILD_SOUNDBOARD_SOUND_UPDATE", new GuildSoundboardSoundUpdateHandler(api));
handlers.put("GUILD_SOUNDBOARD_SOUNDS_UPDATE", new GuildSoundboardSoundsUpdateHandler(api));
handlers.put("GUILD_SOUNDBOARD_SOUND_DELETE", new GuildSoundboardSoundDeleteHandler(api));
handlers.put("VOICE_CHANNEL_EFFECT_SEND", new VoiceChannelEffectSendHandler(api));
handlers.put("GUILD_UPDATE", new GuildUpdateHandler(api));
handlers.put("INTERACTION_CREATE", new InteractionCreateHandler(api));
handlers.put("INVITE_CREATE", new InviteCreateHandler(api));
Expand Down

0 comments on commit bf699f4

Please sign in to comment.