44import lombok .experimental .NonFinal ;
55import net .dv8tion .jda .api .JDA ;
66import net .dv8tion .jda .api .entities .ISnowflake ;
7+ import net .dv8tion .jda .api .entities .channel .concrete .Category ;
8+ import net .dv8tion .jda .api .entities .channel .concrete .ForumChannel ;
79import net .dv8tion .jda .api .entities .channel .concrete .NewsChannel ;
10+ import net .dv8tion .jda .api .entities .channel .concrete .TextChannel ;
811import org .comroid .api .config .adapter .TypeAdapter ;
912import org .comroid .api .data .seri .type .StandardValueType ;
1013import org .comroid .api .func .ext .Context ;
1821@ Value
1922@ NonFinal
2023public abstract class JdaTypeAdapter <T extends ISnowflake > extends TypeAdapter <T , @ NotNull Long > {
21- public static final JdaTypeAdapter <NewsChannel > NEWS_CHANNEL = new JdaTypeAdapter <>(NewsChannel .class ) {
24+ public static final JdaTypeAdapter <TextChannel > TEXT_CHANNEL = new JdaTypeAdapter <>(TextChannel .class ) {
25+ @ Override
26+ protected Stream <TextChannel > findAll (JDA jda ) {
27+ return jda .getTextChannels ().stream ();
28+ }
29+
30+ @ Override
31+ public Optional <TextChannel > deserialize (Context context , @ NotNull Long id ) {
32+ return context .getFromContext (JDA .class , false ).wrap ().map (jda -> jda .getTextChannelById (id ));
33+ }
34+ };
35+ public static final JdaTypeAdapter <ForumChannel > FORUM_CHANNEL = new JdaTypeAdapter <>(ForumChannel .class ) {
36+ @ Override
37+ protected Stream <ForumChannel > findAll (JDA jda ) {
38+ return jda .getForumChannels ().stream ();
39+ }
40+
41+ @ Override
42+ public Optional <ForumChannel > deserialize (Context context , @ NotNull Long id ) {
43+ return context .getFromContext (JDA .class , false ).wrap ().map (jda -> jda .getForumChannelById (id ));
44+ }
45+ };
46+ public static final JdaTypeAdapter <NewsChannel > NEWS_CHANNEL = new JdaTypeAdapter <>(NewsChannel .class ) {
2247 @ Override
2348 protected Stream <NewsChannel > findAll (JDA jda ) {
2449 return jda .getNewsChannels ().stream ();
@@ -29,6 +54,17 @@ public Optional<NewsChannel> deserialize(Context context, @NotNull Long id) {
2954 return context .getFromContext (JDA .class , false ).wrap ().map (jda -> jda .getNewsChannelById (id ));
3055 }
3156 };
57+ public static final JdaTypeAdapter <Category > CHANNEL_CATEGORY = new JdaTypeAdapter <>(Category .class ) {
58+ @ Override
59+ protected Stream <Category > findAll (JDA jda ) {
60+ return jda .getCategories ().stream ();
61+ }
62+
63+ @ Override
64+ public Optional <Category > deserialize (Context context , @ NotNull Long id ) {
65+ return context .getFromContext (JDA .class , false ).wrap ().map (jda -> jda .getCategoryById (id ));
66+ }
67+ };
3268
3369 public JdaTypeAdapter (Class <T > type ) {
3470 super (type , StandardValueType .LONG , "id" );
0 commit comments