Skip to content

Commit

Permalink
✨ Added utilities expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed Jun 18, 2022
1 parent 52b9221 commit dab8aa8
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/info/itsthesky/disky/elements/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static class DiSkyConverters {
Channel::getName,
input -> DiSky.getManager().searchIfAnyPresent(bot -> bot.getInstance().getVoiceChannelById(input))
).register();
new DiSkyType<>(AudioChannel.class, "messagechannel", Channel::getName, null).register();
new DiSkyType<>(ThreadChannel.class, "threadchannel",
Channel::getName,
input -> DiSky.getManager().searchIfAnyPresent(bot -> bot.getInstance().getThreadChannelById(input))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package info.itsthesky.disky.elements.getters;

import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Since;
import info.itsthesky.disky.core.Bot;
import jdk.jfr.Name;
import net.dv8tion.jda.api.entities.AudioChannel;
import org.jetbrains.annotations.NotNull;

@Name("Get Audio Channel")
@Description({"This is an utility expression.",
"It will returns an Audio Channel out of the provided ID.",
"It will returns either the voice or stage channel corresponding to the provided ID.",
"This expression cannot be changed."})
@Examples("audio channel with id \"000\"")
@Since("4.0.0")
public class GetAudioChannel extends BaseGetterExpression<AudioChannel> {

static {
register(
GetAudioChannel.class,
AudioChannel.class,
"audio channel"
);
}

@Override
protected AudioChannel get(String id, Bot bot) {
final AudioChannel voice = bot.getInstance().getVoiceChannelById(id);
return voice == null ? bot.getInstance().getStageChannelById(id) : voice;
}

@Override
public String getCodeName() {
return "audio channel";
}

@Override
public @NotNull Class<? extends AudioChannel> getReturnType() {
return AudioChannel.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package info.itsthesky.disky.elements.getters;

import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Since;
import info.itsthesky.disky.core.Bot;
import jdk.jfr.Name;
import net.dv8tion.jda.api.entities.AudioChannel;
import net.dv8tion.jda.api.entities.BaseGuildMessageChannel;
import net.dv8tion.jda.api.entities.GuildMessageChannel;
import org.jetbrains.annotations.NotNull;

@Name("Get Message Channel")
@Description({"This is an utility expression.",
"It will returns a Message Channel (text, news or thread) out of the provided ID.",
"This expression cannot be changed."})
@Examples("message channel with id \"000\"")
@Since("4.0.0")
public class GetMessageChannel extends BaseGetterExpression<GuildMessageChannel> {

static {
register(
GetMessageChannel.class,
GuildMessageChannel.class,
"message channel"
);
}

@Override
protected GuildMessageChannel get(String id, Bot bot) {
final GuildMessageChannel text = bot.getInstance().getTextChannelById(id);
if (text != null)
return text;

final GuildMessageChannel news = bot.getInstance().getNewsChannelById(id);
if (news != null)
return news;

final GuildMessageChannel thread = bot.getInstance().getThreadChannelById(id);
if (thread != null)
return thread;

return null;
}

@Override
public String getCodeName() {
return "message channel";
}

@Override
public @NotNull Class<? extends GuildMessageChannel> getReturnType() {
return GuildMessageChannel.class;
}
}

0 comments on commit dab8aa8

Please # to comment.