Skip to content

Commit

Permalink
DiSky v4.12.1 (#146)
Browse files Browse the repository at this point in the history
* ⚡ Added a better null check for emojis in react section

* ⚡ Added a null check for 'has role' condition

* ✨ Added way to reply to deferred & waited interactions

* ⚡ DiSky v4.12.0

* 🐛 Fixed event-channel (see #138)

* ⚡ Enhanced bot login error system

* ⚡ Added way to use options in entries

* ⚡ Moved scopes/structs loading after Skript verifications

* ⚡ Removed debug message from BaseScope.java

* ⚡ Added a better error try/catch system for the nickname effect

* ✨ Added JSON serialization for embeds

* 🔥 Discriminator are no longer defaulted in toString methods

* ⚡ Bumped to JDA v5-beta13
🚀 DiSky v4.12.1
  • Loading branch information
ItsTheSky authored Aug 26, 2023
1 parent 27508b6 commit 50eeb58
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 7 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ group = 'info.itsthesky'
// Semantic Versioning
def major = '4'
def minor = '12'
def patch = '0'
def patch = '1'

def channel = ''
def channelVersion = ''
Expand All @@ -33,7 +33,7 @@ dependencies {

// Commits: com.github.dv8fromtheworld:jda
// Stable: net.dv8tion:JDA
implementation 'net.dv8tion:JDA:5.0.0-beta.10'
implementation 'net.dv8tion:JDA:5.0.0-beta.13'

// Class manipulation
implementation 'net.bytebuddy:byte-buddy:1.11.22'
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/info/itsthesky/disky/core/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void shutdown(boolean force) {
}

public String getDiscordName() {
return getInstance().getSelfUser().getName() + "#" + getInstance().getSelfUser().getDiscriminator();
return getInstance().getSelfUser().getEffectiveName();
}

public BotOptions getOptions() {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/info/itsthesky/disky/core/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import ch.njol.util.NonNullPair;
import com.google.common.collect.Lists;
import info.itsthesky.disky.DiSky;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.utils.data.DataObject;
import org.bukkit.ChatColor;
import org.bukkit.event.Event;

Expand All @@ -12,6 +15,7 @@
import java.awt.image.DataBufferByte;
import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Consumer;

Expand Down Expand Up @@ -108,4 +112,16 @@ public static List<NonNullPair<InputStream, String>> parseFiles(Object[] raws) t
}
return streams;
}

public static EmbedBuilder convertJSONToEmbed(String json) {
return EmbedBuilder.fromData(DataObject.fromJson(json));
}

public static String convertEmbedToJSON(EmbedBuilder builder) {
if (builder.isEmpty())
return "{}"; // TODO: 26/08/2023 Maybe handle that a bit better?

final MessageEmbed embed = builder.build();
return new String(embed.toData().toJson(), StandardCharsets.UTF_8);
}
}
6 changes: 3 additions & 3 deletions src/main/java/info/itsthesky/disky/elements/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public static class DiSkyConverters {

DiSkyType.fromEnum(Permission.class, "permission", "permission").register();
new DiSkyType<>(User.class, "user",
user -> user.getName() + "#" + user.getDiscriminator(),
user -> user.getEffectiveName(),
input -> DiSky.getManager().searchIfAnyPresent(bot -> bot.getInstance().getUserById(input))
).eventExpression().register();
new DiSkyType<>(User.Profile.class, "userprofile",
Expand Down Expand Up @@ -258,7 +258,7 @@ public static class DiSkyConverters {
input -> DiSky.getManager().searchIfAnyPresent(bot -> bot.getInstance().getGuildById(input))
).eventExpression().register();
new DiSkyType<>(Member.class, "member",
member -> member.getUser().getName() + "#" + member.getUser().getDiscriminator(),
member -> member.getUser().getEffectiveName(),
id -> {
final CommandEvent event = CommandEvent.lastEvent;
if (event == null)
Expand All @@ -268,7 +268,7 @@ public static class DiSkyConverters {
return null;
}).eventExpression().register();
new DiSkyType<>(Bot.class, "bot",
member -> member.getInstance().getSelfUser().getName() + "#" + member.getInstance().getSelfUser().getDiscriminator(),
member -> member.getInstance().getSelfUser().getEffectiveName(),
input -> DiSky.getManager().fromName(input))
.eventExpression()
.register();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package info.itsthesky.disky.elements.properties.embeds;

import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import info.itsthesky.disky.api.skript.EasyElement;
import info.itsthesky.disky.core.Utils;
import net.dv8tion.jda.api.EmbedBuilder;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class EmbedFromJSON extends SimpleExpression<EmbedBuilder> {

static {
Skript.registerExpression(
EmbedFromJSON.class,
EmbedBuilder.class,
ExpressionType.COMBINED,
"[the] embed (from|of) [json] %string%"
);
}

private Expression<String> exprJSON;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.@NotNull ParseResult parseResult) {
exprJSON = (Expression<String>) exprs[0];
return true;
}

@Override
protected EmbedBuilder @NotNull [] get(@NotNull Event e) {
final String json = EasyElement.parseSingle(exprJSON, e);
if (json == null)
return new EmbedBuilder[0];

return new EmbedBuilder[] {Utils.convertJSONToEmbed(json)};
}

@Override
public boolean isSingle() {
return true;
}

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

@Override
public @NotNull String toString(@Nullable Event e, boolean debug) {
return "embed from json " + exprJSON.toString(e, debug);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package info.itsthesky.disky.elements.properties.embeds;

import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import info.itsthesky.disky.api.skript.EasyElement;
import info.itsthesky.disky.core.Utils;
import net.dv8tion.jda.api.EmbedBuilder;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class EmbedToJSON extends SimpleExpression<String> {

static {
Skript.registerExpression(
EmbedToJSON.class,
String.class,
ExpressionType.COMBINED,
"[the] embed %embedbuilder% (to|as) json"
);
}

private Expression<EmbedBuilder> exprJSON;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.@NotNull ParseResult parseResult) {
exprJSON = (Expression<EmbedBuilder>) exprs[0];
return true;
}

@Override
protected String @NotNull [] get(@NotNull Event e) {
final EmbedBuilder embedBuilder = EasyElement.parseSingle(exprJSON, e);
if (embedBuilder == null)
return new String[0];

return new String[] {Utils.convertEmbedToJSON(embedBuilder)};
}

@Override
public boolean isSingle() {
return true;
}

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

@Override
public @NotNull String toString(@Nullable Event e, boolean debug) {
return "embed from json " + exprJSON.toString(e, debug);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import info.itsthesky.disky.DiSky;
import info.itsthesky.disky.api.skript.EasyElement;
import info.itsthesky.disky.core.Utils;
import net.dv8tion.jda.api.entities.Member;
Expand Down Expand Up @@ -51,7 +52,14 @@ public void change(@NotNull Event e, @NotNull Object[] delta, @NotNull Changer.C
final String name = (String) delta[0];
if (EasyElement.anyNull(this, member, name))
return;
Utils.catchAction(member.modifyNickname(name), e);

if (!member.getGuild().getSelfMember().canInteract(member)) {
DiSky.getInstance().getLogger()
.warning("The bot '"+member.getGuild().getSelfMember().getUser().getEffectiveName()+"' cannot interact with the member '"+member.getUser().getEffectiveName()+"' to change his nickname! For more information about that, please check DiSky's FAQ: https://disky.me/wiki/getting-started/faq/");
return;
}

member.modifyNickname(name).queue(null, ex -> DiSky.getErrorHandler().exception(e, ex));
}

}

0 comments on commit 50eeb58

Please sign in to comment.