Created
May 2, 2020 08:14
-
-
Save darichey/54670fd18835e09c946eff05a79eaf32 to your computer and use it in GitHub Desktop.
Future of Spec Strawman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public RoleCreateSpec createRole() { | |
return new RoleCreateSpec(gateway, getId().asLong()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RoleCreateSpec extends Mono<Role> { | |
private final GatewayDiscordClient gateway; | |
private final long guildId; | |
private final ImmutableRoleCreateRequest request; | |
@Nullable | |
private final String reason; | |
public RoleCreateSpec(GatewayDiscordClient gateway, long guildId) { | |
this(gateway, guildId, RoleCreateRequest.builder().build(), null); | |
} | |
private RoleCreateSpec(GatewayDiscordClient gateway, long guildId, ImmutableRoleCreateRequest request, @Nullable String reason) { | |
this.gateway = gateway; | |
this.guildId = guildId; | |
this.request = request; | |
this.reason = reason; | |
} | |
public RoleCreateSpec withName(String name) { | |
return withRequest(request.withName(name)); | |
} | |
public RoleCreateSpec withPermissions(PermissionSet permissions) { | |
return withRequest(request.withPermissions(permissions.getRawValue())); | |
} | |
public RoleCreateSpec withColor(Color color) { | |
return withRequest(request.withColor(color.getRGB() & 0xFFFFFF)); | |
} | |
public RoleCreateSpec withHoist(boolean hoist) { | |
return withRequest(request.withHoist(hoist)); | |
} | |
public RoleCreateSpec withMentionable(boolean mentionable) { | |
return withRequest(request.withMentionable(mentionable)); | |
} | |
public RoleCreateSpec withReason(String name) { | |
return new RoleCreateSpec(this.gateway, this.guildId, this.request, name); | |
} | |
private RoleCreateSpec withRequest(ImmutableRoleCreateRequest request) { | |
return new RoleCreateSpec(this.gateway, this.guildId, request, this.reason); | |
} | |
@Override | |
public void subscribe(CoreSubscriber<? super Role> actual) { | |
gateway.rest().getGuildService() | |
.createGuildRole(guildId, request, reason) | |
.map(data -> new Role(gateway, data, guildId)) | |
.subscribe(actual); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guild.createRole() | |
.withName("New Role") | |
.withHoist(true) | |
.withReason("I want to") | |
.map(Role::getName) // any Mono methods | |
.subscribe(System.out::println); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment