Skip to content

Commit

Permalink
Update dependencies & use Optionals
Browse files Browse the repository at this point in the history
Gradle Galaxy: 1.1.3 -> 1.2.3
Shadow: 8.1.7 -> 8.3.0
Java Utilities: 12eda02e55 -> a073202b43
Logback Classic: 1.5.3 -> 1.5.6
  • Loading branch information
srnyx committed Aug 15, 2024
1 parent db06d41 commit 306d052
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import xyz.srnyx.gradlegalaxy.utility.setupPublishing

plugins {
application
id("xyz.srnyx.gradle-galaxy") version "1.1.3"
id("io.github.goooler.shadow") version "8.1.7"
id("xyz.srnyx.gradle-galaxy") version "1.2.3"
id("com.gradleup.shadow") version "8.3.0"
}

setupJava("xyz.srnyx", "3.1.0", "A simple library for JDA Discord bots", JavaVersion.VERSION_19)
Expand All @@ -20,12 +20,12 @@ addCompilerArgs("-parameters")
repository(Repository.MAVEN_CENTRAL, Repository.JITPACK)
dependencies {
compileOnly("net.dv8tion", "JDA", "5.0.2") // JDA
implementation("xyz.srnyx", "java-utilities", "12eda02e55") // General Java utility library
implementation("xyz.srnyx", "java-utilities", "a073202b43") // General Java utility library
implementation("io.github.freya022", "BotCommands", "2.10.3") // Command framework
implementation("org.spongepowered", "configurate-yaml", "4.1.2") // Config manager
implementation("org.postgresql", "postgresql", "42.7.3") // Database
implementation("com.zaxxer", "HikariCP", "5.1.0") // Database
implementation("ch.qos.logback", "logback-classic", "1.5.3") // Logging
implementation("ch.qos.logback", "logback-classic", "1.5.6") // Logging
}

setupPublishing(
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/xyz/srnyx/lazylibrary/utility/LazyMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import xyz.srnyx.javautilities.MiscUtility;

import java.util.Optional;


/**
* A utility class for converting {@link Object Objects} to other types
Expand All @@ -18,10 +20,10 @@ public class LazyMapper {
*
* @param object the {@link String} to parse
*
* @return the {@link Long snowflake} or {@code null}
* @return the {@link Long snowflake} or empty
*/
@Nullable
public static Long parseSnowflake(@NotNull Object object) {
@NotNull
public static Optional<Long> parseSnowflake(@NotNull Object object) {
return MiscUtility.handleException(() -> MiscUtil.parseSnowflake(object.toString()));
}

Expand All @@ -30,14 +32,11 @@ public static Long parseSnowflake(@NotNull Object object) {
*
* @param object the {@link Object} to convert
*
* @return the {@link UserSnowflake} or {@code null}
* @return the {@link UserSnowflake} or empty
*/
@Nullable
public static UserSnowflake toUserSnowflake(@Nullable Object object) {
if (object == null) return null;
final Long snowflake = parseSnowflake(object);
if (snowflake == null) return null;
return MiscUtility.handleException(() -> UserSnowflake.fromId(snowflake));
@NotNull
public static Optional<UserSnowflake> toUserSnowflake(@Nullable Object object) {
return object == null ? Optional.empty() : parseSnowflake(object).flatMap(snowflake -> MiscUtility.handleException(() -> UserSnowflake.fromId(snowflake)));
}

private LazyMapper() {
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/xyz/srnyx/lazylibrary/utility/LazyUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.jetbrains.annotations.NotNull;

import xyz.srnyx.javautilities.MiscUtility;
import xyz.srnyx.javautilities.manipulation.Mapper;

import xyz.srnyx.lazylibrary.LazyEmoji;
Expand Down Expand Up @@ -56,21 +55,23 @@ public static PaginatorBuilder getDefaultPaginator() {
*/
public static boolean userHasChannelPermission(@NotNull Interaction interaction, @NotNull Permission... permissions) {
final Member member = interaction.getMember();
final GuildChannel channel = MiscUtility.handleException(() -> (GuildChannel) interaction.getChannel());
if (member == null || channel == null) return false;
return member.hasPermission(channel, permissions);
return member != null && Mapper.to(interaction.getChannel(), GuildChannel.class)
.map(channel -> member.hasPermission(channel, permissions))
.orElse(false);
}

@NotNull private static final Function<BoundExtractedResult<Command.Choice>, Command.Choice> STRING_MAPPING = BoundExtractedResult::getReferent;
@NotNull private static final Function<BoundExtractedResult<Command.Choice>, Command.Choice> INTEGER_MAPPING = result -> {
final Command.Choice choice = result.getReferent();
final Long value = Mapper.toLong(choice.getAsString());
return value == null ? null : new Command.Choice(choice.getName(), value);
return Mapper.toLong(choice.getAsString())
.map(value -> new Command.Choice(choice.getName(), value))
.orElse(null);
};
@NotNull private static final Function<BoundExtractedResult<Command.Choice>, Command.Choice> NUMBER_MAPPING = result -> {
final Command.Choice choice = result.getReferent();
final Double value = Mapper.toDouble(choice.getAsString());
return value == null ? null : new Command.Choice(choice.getName(), value);
return Mapper.toDouble(choice.getAsString())
.map(value -> new Command.Choice(choice.getName(), value))
.orElse(null);
};

/**
Expand Down

0 comments on commit 306d052

Please sign in to comment.