Skip to content

Commit

Permalink
DiSky v4.12.2-beta1 (#163)
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

* ✨ Added new media channel type

* ✨ Added supports for custom status for bots

* ⚡ Bumped to JDA 5-beta15 / DiSky v4.13.0

* 🚀 Bumped to JDA 19

* ⚡ Added debug messages for the `open private channel` effect.

* ✨ Added way to "reset" the state of a user/role's permission in a channel
  • Loading branch information
ItsTheSky committed Jan 6, 2024
1 parent d5b9f78 commit 061da19
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 14 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Expand Up @@ -8,10 +8,10 @@ group = 'info.itsthesky'
// Semantic Versioning
def major = '4'
def minor = '12'
def patch = '1'
def patch = '2'

def channel = ''
def channelVersion = ''
def channel = 'beta'
def channelVersion = '1'

version = major + '.' + minor + '.' + patch + (channel ? '-' + channel + 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.13'
implementation 'net.dv8tion:JDA:5.0.0-beta.19'

// Class manipulation
implementation 'net.bytebuddy:byte-buddy:1.11.22'
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
@@ -1 +1 @@
rootProject.name = 'disky'
rootProject.name = 'DiSky'
4 changes: 4 additions & 0 deletions src/main/java/info/itsthesky/disky/elements/Types.java
Expand Up @@ -110,6 +110,10 @@ public static class DiSkyConverters {
Channel::getName,
input -> DiSky.getManager().searchIfAnyPresent(bot -> bot.getInstance().getForumChannelById(input))
).eventExpression().register();
new DiSkyType<>(MediaChannel.class, "mediachannel",
Channel::getName,
input -> DiSky.getManager().searchIfAnyPresent(bot -> bot.getInstance().getMediaChannelById(input))
).eventExpression().register();
new DiSkyType<>(ChannelAction.class, "channelaction",
action -> action.getType().name(),
null
Expand Down
Expand Up @@ -13,6 +13,8 @@
import info.itsthesky.disky.core.Utils;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.concrete.PrivateChannel;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.CacheRestAction;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -42,12 +44,20 @@ public boolean initEffect(Expression<?>[] exprs, int i, Kleenean kleenean, Skrip
@Override
public void runEffect(@NotNull Event e, Bot bot) {
final User rawUser = parseSingle(exprUser, e, null);
DiSky.debug("Opening private channel of user " + rawUser.getId() + " ...");
if (anyNull(this, rawUser, bot)) {
restart();
return;
}

rawUser.openPrivateChannel().queue(this::restart, ex -> {
final CacheRestAction<PrivateChannel> response = rawUser.openPrivateChannel();
DiSky.debug("Request for private channel of user " + rawUser.getId() + " created. sending ...");

response.queue(entity -> {
restart(entity);
DiSky.debug("Private channel of user " + rawUser.getId() + " opened and stored in " + changedVariable.toString(e, true) + ".");
}, ex -> {
DiSky.debug("Cannot open private channel of user " + rawUser.getId() + ": " + ex.getMessage() + ".");
DiSky.getErrorHandler().exception(e, ex);
restart();
});
Expand Down
Expand Up @@ -67,8 +67,8 @@ public boolean init(Expression<?> @NotNull [] exprs, int matchedPattern, @NotNul

@Override
public Class<?> @NotNull [] acceptChange(@NotNull Changer.ChangeMode mode) {
if (mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE)
return new Class[] {Permission[].class};
if (mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE || mode == Changer.ChangeMode.REMOVE_ALL)
return new Class[] {Permission[].class, Permission.class};
return new Class[0];
}

Expand All @@ -82,20 +82,25 @@ public void change(@NotNull Event e, @NotNull Object[] delta, @NotNull Changer.C
final Permission[] perms = (Permission[]) delta;
if (EasyElement.anyNull(this, holder, perms))
return;
if (channel != null && !(channel instanceof GuildChannel))
return;

switch (mode) {
case ADD:
if (holder instanceof Role && channel == null)
((Role) holder).getManager().givePermissions(perms).queue();
if (channel != null)
((GuildChannel) channel).getPermissionContainer().upsertPermissionOverride(holder).grant(perms).queue();
channel.getPermissionContainer().upsertPermissionOverride(holder).grant(perms).queue();
break;
case REMOVE:
if (holder instanceof Role && channel == null)
((Role) holder).getManager().revokePermissions(perms).queue();
if (channel != null)
((GuildChannel) channel).getPermissionContainer().upsertPermissionOverride(holder).deny(perms).queue();
channel.getPermissionContainer().upsertPermissionOverride(holder).deny(perms).queue();
break;
case REMOVE_ALL:
if (holder instanceof Role && channel == null)
DiSky.getInstance().getLogger().warning("You cannot clear/reset permissions of a role, without a target channel!");
if (channel != null)
channel.getPermissionContainer().upsertPermissionOverride(holder).clear(perms).queue();
break;
}
}
Expand Down Expand Up @@ -128,7 +133,7 @@ public void change(@NotNull Event e, @NotNull Object[] delta, @NotNull Changer.C
return new Permission[0];
if (channel == null)
return holder.getPermissions().toArray(new Permission[0]);
return holder.getPermissions((GuildChannel) channel).toArray(new Permission[0]);
return holder.getPermissions(channel).toArray(new Permission[0]);
}

@Override
Expand Down
Expand Up @@ -20,7 +20,8 @@ public class ExprPresence extends SimpleExpression<Activity> {
"watching [to] %string%",
"playing [to] %string%",
"streaming [to] %string% with [the] url %string%",
"competing [to] %string%"
"competing [to] %string%",
"custom status [of] %string%"
);
}

Expand Down Expand Up @@ -64,6 +65,8 @@ public boolean init(Expression<?> @NotNull [] exprs, int matchedPattern, @NotNul
break;
case 4:
activity = Activity.competing(input);
case 5:
activity = Activity.customStatus(input);
}
return new Activity[] {activity};
}
Expand Down Expand Up @@ -91,6 +94,8 @@ public boolean isSingle() {
return "streaming " + exprInput.toString(e, debug) + " with url " + exprURL.toString(e, debug);
case 4:
return "competing " + exprInput.toString(e, debug);
case 5:
return "custom status " + exprInput.toString(e, debug);
}
return "";
}
Expand Down
@@ -0,0 +1,32 @@
package info.itsthesky.disky.elements.properties.channels;

import info.itsthesky.disky.api.skript.action.GuildAction;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.requests.restaction.ChannelAction;
import org.jetbrains.annotations.NotNull;

public class NewMediaChannel extends GuildAction<ChannelAction> {

static {
register(
NewMediaChannel.class,
ChannelAction.class,
"media[( |-)]channel"
);
}

@Override
protected ChannelAction create(@NotNull Guild guild) {
return guild.createMediaChannel("default channel");
}

@Override
public String getNewType() {
return "mediachannel";
}

@Override
public Class<? extends ChannelAction> getReturnType() {
return ChannelAction.class;
}
}
Expand Up @@ -10,6 +10,10 @@ public class MessageWrapper extends ReceivedMessage {

public MessageWrapper(Message message) {
super(message.getIdLong(),
message.getChannelIdLong(),
message.getGuildIdLong(),
message.getJDA(),
message.getGuild(),
message.getChannel(),
message.getType(),
message.getMessageReference(),
Expand Down

0 comments on commit 061da19

Please sign in to comment.