Skip to content

Commit a36d3c4

Browse files
committed
Utility functions for MaybeThreadChannels implementations
Not too sure of those methods names though
1 parent 122c43d commit a36d3c4

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

core/api/core.api

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10341,6 +10341,8 @@ public final class dev/kord/core/entity/channel/WelcomeScreenChannel : dev/kord/
1034110341
public final class dev/kord/core/entity/channel/thread/DeletedThreadChannel : dev/kord/core/entity/channel/thread/MaybeThreadChannel {
1034210342
public fun <init> (Ldev/kord/core/cache/data/ChannelData;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;)V
1034310343
public synthetic fun <init> (Ldev/kord/core/cache/data/ChannelData;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
10344+
public fun doIfStillExist (Lkotlin/jvm/functions/Function0;)V
10345+
public fun flatMap-gIAlu-s (Ldev/kord/core/entity/channel/thread/MaybeThreadChannel;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
1034410346
public fun getData ()Ldev/kord/core/cache/data/ChannelData;
1034510347
public fun getGuild ()Ldev/kord/core/behavior/GuildBehavior;
1034610348
public fun getGuild (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
@@ -10359,6 +10361,8 @@ public final class dev/kord/core/entity/channel/thread/DeletedThreadChannel : de
1035910361
}
1036010362

1036110363
public abstract interface class dev/kord/core/entity/channel/thread/MaybeThreadChannel : dev/kord/core/entity/Strategizable {
10364+
public abstract fun doIfStillExist (Lkotlin/jvm/functions/Function0;)V
10365+
public abstract fun flatMap-gIAlu-s (Ldev/kord/core/entity/channel/thread/MaybeThreadChannel;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
1036210366
public abstract fun getData ()Ldev/kord/core/cache/data/ChannelData;
1036310367
public fun getGuild ()Ldev/kord/core/behavior/GuildBehavior;
1036410368
public fun getGuild (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
@@ -10400,8 +10404,10 @@ public final class dev/kord/core/entity/channel/thread/NewsChannelThread : dev/k
1040010404
public fun createMessage (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1040110405
public fun delete (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1040210406
public fun deleteMessage (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
10407+
public fun doIfStillExist (Lkotlin/jvm/functions/Function0;)V
1040310408
public fun fetchChannel (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1040410409
public fun fetchChannelOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
10410+
public fun flatMap-gIAlu-s (Ldev/kord/core/entity/channel/thread/MaybeThreadChannel;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
1040510411
public fun getAppliedTags ()Ljava/util/List;
1040610412
public fun getArchiveTimestamp ()Lkotlin/time/Instant;
1040710413
public fun getAutoArchiveDuration ()Ldev/kord/common/entity/ArchiveDuration;
@@ -10478,8 +10484,10 @@ public final class dev/kord/core/entity/channel/thread/TextChannelThread : dev/k
1047810484
public fun createMessage (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1047910485
public fun delete (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1048010486
public fun deleteMessage (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
10487+
public fun doIfStillExist (Lkotlin/jvm/functions/Function0;)V
1048110488
public fun fetchChannel (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1048210489
public fun fetchChannelOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
10490+
public fun flatMap-gIAlu-s (Ldev/kord/core/entity/channel/thread/MaybeThreadChannel;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
1048310491
public fun getAppliedTags ()Ljava/util/List;
1048410492
public fun getArchiveTimestamp ()Lkotlin/time/Instant;
1048510493
public fun getAutoArchiveDuration ()Ldev/kord/common/entity/ArchiveDuration;
@@ -10547,6 +10555,8 @@ public final class dev/kord/core/entity/channel/thread/TextChannelThread : dev/k
1054710555
}
1054810556

1054910557
public abstract interface class dev/kord/core/entity/channel/thread/ThreadChannel : dev/kord/core/behavior/channel/threads/ThreadChannelBehavior, dev/kord/core/entity/channel/GuildMessageChannel, dev/kord/core/entity/channel/thread/MaybeThreadChannel {
10558+
public fun doIfStillExist (Lkotlin/jvm/functions/Function0;)V
10559+
public fun flatMap-gIAlu-s (Ldev/kord/core/entity/channel/thread/MaybeThreadChannel;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
1055010560
public fun getAppliedTags ()Ljava/util/List;
1055110561
public fun getArchiveTimestamp ()Lkotlin/time/Instant;
1055210562
public fun getAutoArchiveDuration ()Ldev/kord/common/entity/ArchiveDuration;
@@ -10595,8 +10605,10 @@ public final class dev/kord/core/entity/channel/thread/ThreadChannel$DefaultImpl
1059510605
public static fun createMessage (Ldev/kord/core/entity/channel/thread/ThreadChannel;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1059610606
public static fun delete (Ldev/kord/core/entity/channel/thread/ThreadChannel;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1059710607
public static fun deleteMessage (Ldev/kord/core/entity/channel/thread/ThreadChannel;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
10608+
public static fun doIfStillExist (Ldev/kord/core/entity/channel/thread/ThreadChannel;Lkotlin/jvm/functions/Function0;)V
1059810609
public static fun fetchChannel (Ldev/kord/core/entity/channel/thread/ThreadChannel;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1059910610
public static fun fetchChannelOrNull (Ldev/kord/core/entity/channel/thread/ThreadChannel;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
10611+
public static fun flatMap-gIAlu-s (Ldev/kord/core/entity/channel/thread/ThreadChannel;Ldev/kord/core/entity/channel/thread/MaybeThreadChannel;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
1060010612
public static fun getAppliedTags (Ldev/kord/core/entity/channel/thread/ThreadChannel;)Ljava/util/List;
1060110613
public static fun getArchiveTimestamp (Ldev/kord/core/entity/channel/thread/ThreadChannel;)Lkotlin/time/Instant;
1060210614
public static fun getAutoArchiveDuration (Ldev/kord/core/entity/channel/thread/ThreadChannel;)Ldev/kord/common/entity/ArchiveDuration;

core/api/core.klib.api

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,8 @@ abstract interface dev.kord.core.entity.channel.thread/ThreadChannel : dev.kord.
832832
open val type // dev.kord.core.entity.channel.thread/ThreadChannel.type|{}type[0]
833833
open fun <get-type>(): dev.kord.common.entity/ChannelType // dev.kord.core.entity.channel.thread/ThreadChannel.type.<get-type>|<get-type>(){}[0]
834834

835+
open fun <#A1: kotlin/Any?> (dev.kord.core.entity.channel.thread/MaybeThreadChannel).flatMap(kotlin/Function0<#A1>): kotlin/Result<#A1> // dev.kord.core.entity.channel.thread/ThreadChannel.flatMap|flatMap@dev.kord.core.entity.channel.thread.MaybeThreadChannel(kotlin.Function0<0:0>){0§<kotlin.Any?>}[0]
836+
open fun <#A1: kotlin/Any?> doIfStillExist(kotlin/Function0<#A1>) // dev.kord.core.entity.channel.thread/ThreadChannel.doIfStillExist|doIfStillExist(kotlin.Function0<0:0>){0§<kotlin.Any?>}[0]
835837
open fun withStrategy(dev.kord.core.supplier/EntitySupplyStrategy<*>): dev.kord.core.entity.channel.thread/ThreadChannel // dev.kord.core.entity.channel.thread/ThreadChannel.withStrategy|withStrategy(dev.kord.core.supplier.EntitySupplyStrategy<*>){}[0]
836838
open suspend fun getGuild(): dev.kord.core.entity/Guild // dev.kord.core.entity.channel.thread/ThreadChannel.getGuild|getGuild(){}[0]
837839
open suspend fun getGuildOrNull(): dev.kord.core.entity/Guild? // dev.kord.core.entity.channel.thread/ThreadChannel.getGuildOrNull|getGuildOrNull(){}[0]
@@ -1296,6 +1298,8 @@ sealed interface dev.kord.core.entity.channel.thread/MaybeThreadChannel : dev.ko
12961298
open val type // dev.kord.core.entity.channel.thread/MaybeThreadChannel.type|{}type[0]
12971299
open fun <get-type>(): dev.kord.common.entity/ChannelType // dev.kord.core.entity.channel.thread/MaybeThreadChannel.type.<get-type>|<get-type>(){}[0]
12981300

1301+
abstract fun <#A1: kotlin/Any?> (dev.kord.core.entity.channel.thread/MaybeThreadChannel).flatMap(kotlin/Function0<#A1>): kotlin/Result<#A1> // dev.kord.core.entity.channel.thread/MaybeThreadChannel.flatMap|flatMap@dev.kord.core.entity.channel.thread.MaybeThreadChannel(kotlin.Function0<0:0>){0§<kotlin.Any?>}[0]
1302+
abstract fun <#A1: kotlin/Any?> doIfStillExist(kotlin/Function0<#A1>) // dev.kord.core.entity.channel.thread/MaybeThreadChannel.doIfStillExist|doIfStillExist(kotlin.Function0<0:0>){0§<kotlin.Any?>}[0]
12991303
open suspend fun getGuild(): dev.kord.core.entity/Guild // dev.kord.core.entity.channel.thread/MaybeThreadChannel.getGuild|getGuild(){}[0]
13001304
open suspend fun getGuildOrNull(): dev.kord.core.entity/Guild? // dev.kord.core.entity.channel.thread/MaybeThreadChannel.getGuildOrNull|getGuildOrNull(){}[0]
13011305
open suspend fun getParent(): dev.kord.core.entity.channel/ThreadParentChannel // dev.kord.core.entity.channel.thread/MaybeThreadChannel.getParent|getParent(){}[0]
@@ -7250,6 +7254,8 @@ final class dev.kord.core.entity.channel.thread/DeletedThreadChannel : dev.kord.
72507254
final val supplier // dev.kord.core.entity.channel.thread/DeletedThreadChannel.supplier|{}supplier[0]
72517255
final fun <get-supplier>(): dev.kord.core.supplier/EntitySupplier // dev.kord.core.entity.channel.thread/DeletedThreadChannel.supplier.<get-supplier>|<get-supplier>(){}[0]
72527256

7257+
final fun <#A1: kotlin/Any?> (dev.kord.core.entity.channel.thread/MaybeThreadChannel).flatMap(kotlin/Function0<#A1>): kotlin/Result<#A1> // dev.kord.core.entity.channel.thread/DeletedThreadChannel.flatMap|flatMap@dev.kord.core.entity.channel.thread.MaybeThreadChannel(kotlin.Function0<0:0>){0§<kotlin.Any?>}[0]
7258+
final fun <#A1: kotlin/Any?> doIfStillExist(kotlin/Function0<#A1>) // dev.kord.core.entity.channel.thread/DeletedThreadChannel.doIfStillExist|doIfStillExist(kotlin.Function0<0:0>){0§<kotlin.Any?>}[0]
72537259
final fun withStrategy(dev.kord.core.supplier/EntitySupplyStrategy<*>): dev.kord.core.entity.channel.thread/DeletedThreadChannel // dev.kord.core.entity.channel.thread/DeletedThreadChannel.withStrategy|withStrategy(dev.kord.core.supplier.EntitySupplyStrategy<*>){}[0]
72547260
}
72557261

core/src/commonMain/kotlin/entity/channel/thread/DeletedThreadChannel.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ public class DeletedThreadChannel(
1010
public override val kord: Kord,
1111
override val supplier: EntitySupplier = kord.defaultSupplier
1212
) : MaybeThreadChannel {
13+
override fun <T> MaybeThreadChannel.flatMap(func: () -> T): Result<T> {
14+
return Result.failure(Exception("The thread does not exists anymore."))
15+
}
16+
17+
override fun <T> doIfStillExist(func: () -> T) {
18+
return;
19+
}
20+
1321
override fun withStrategy(strategy: EntitySupplyStrategy<*>): DeletedThreadChannel {
1422
return DeletedThreadChannel(data, kord, strategy.supply(kord))
1523
}

core/src/commonMain/kotlin/entity/channel/thread/MaybeThreadChannel.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,16 @@ public sealed interface MaybeThreadChannel : Strategizable {
5858
* @throws [RequestException] if something went wrong during the request.
5959
*/
6060
public suspend fun getParentOrNull(): ThreadParentChannel? = supplier.getChannelOfOrNull(parentId)
61+
62+
/**
63+
* Return the value of the function in parameter if the thread is not deleted.
64+
*
65+
* MIGHT FAIL!
66+
*/
67+
public fun <T> MaybeThreadChannel.flatMap(func: () -> T): Result<T>
68+
69+
/**
70+
* Execute the function in parameter if the thread is not deleted.
71+
*/
72+
public fun <T> doIfStillExist(func: () -> T): Unit
6173
}

core/src/commonMain/kotlin/entity/channel/thread/ThreadChannel.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ public interface ThreadChannel : GuildMessageChannel, ThreadChannelBehavior, May
131131
*/
132132
public val appliedTags: List<Snowflake> get() = data.appliedTags.value ?: emptyList()
133133

134+
override fun <T> MaybeThreadChannel.flatMap(func: () -> T): Result<T> = Result.success(func())
135+
136+
override fun <T> doIfStillExist(func: () -> T) {
137+
func()
138+
}
139+
134140
override fun withStrategy(strategy: EntitySupplyStrategy<*>): ThreadChannel {
135141
return ThreadChannel(data, kord, strategy.supply(kord))
136142
}

0 commit comments

Comments
 (0)