Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper constructors to some builders #531

Merged
merged 1 commit into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/src/builders/channel/thread.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class ThreadBuilder extends CreateBuilder<Thread> {

ThreadBuilder({required this.name, this.autoArchiveDuration, required this.type, this.invitable, this.rateLimitPerUser});

ThreadBuilder.publicThread({required this.name, this.autoArchiveDuration, this.rateLimitPerUser}) : type = ChannelType.publicThread;

ThreadBuilder.privateThread({required this.name, this.autoArchiveDuration, this.invitable, this.rateLimitPerUser}) : type = ChannelType.privateThread;

@override
Map<String, Object?> build() => {
'name': name,
Expand Down
84 changes: 83 additions & 1 deletion lib/src/builders/message/component.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:nyxx/nyxx.dart';
import 'package:nyxx/src/builders/builder.dart';
import 'package:nyxx/src/models/channel/channel.dart';
import 'package:nyxx/src/models/emoji.dart';
import 'package:nyxx/src/models/message/component.dart';
import 'package:nyxx/src/models/snowflake.dart';

abstract class MessageComponentBuilder extends CreateBuilder<MessageComponent> {
MessageComponentType type;
Expand Down Expand Up @@ -47,6 +47,46 @@ class ButtonBuilder extends MessageComponentBuilder {
this.isDisabled,
}) : super(type: MessageComponentType.button);

ButtonBuilder.primary({
this.label,
this.emoji,
required String customId,
this.isDisabled,
}) : style = ButtonStyle.primary,
super(type: MessageComponentType.button);

ButtonBuilder.secondary({
this.label,
this.emoji,
required String customId,
this.isDisabled,
}) : style = ButtonStyle.secondary,
super(type: MessageComponentType.button);

ButtonBuilder.success({
this.label,
this.emoji,
required String customId,
this.isDisabled,
}) : style = ButtonStyle.success,
super(type: MessageComponentType.button);

ButtonBuilder.danger({
this.label,
this.emoji,
required String customId,
this.isDisabled,
}) : style = ButtonStyle.danger,
super(type: MessageComponentType.button);

ButtonBuilder.link({
this.label,
this.emoji,
required Uri this.url,
this.isDisabled,
}) : style = ButtonStyle.link,
super(type: MessageComponentType.button);

@override
Map<String, Object?> build() => {
...super.build(),
Expand Down Expand Up @@ -90,6 +130,48 @@ class SelectMenuBuilder extends MessageComponentBuilder {
this.isDisabled,
});

SelectMenuBuilder.stringSelect({
required this.customId,
required List<SelectMenuOptionBuilder> this.options,
this.placeholder,
this.minValues,
this.maxValues,
this.isDisabled,
}) : super(type: MessageComponentType.stringSelect);

SelectMenuBuilder.userSelect({
required this.customId,
this.placeholder,
this.minValues,
this.maxValues,
this.isDisabled,
}) : super(type: MessageComponentType.userSelect);

SelectMenuBuilder.roleSelect({
required this.customId,
this.placeholder,
this.minValues,
this.maxValues,
this.isDisabled,
}) : super(type: MessageComponentType.roleSelect);

SelectMenuBuilder.mentionableSelect({
required this.customId,
this.channelTypes,
this.placeholder,
this.minValues,
this.maxValues,
this.isDisabled,
}) : super(type: MessageComponentType.mentionableSelect);

SelectMenuBuilder.channelSelect({
required this.customId,
this.placeholder,
this.minValues,
this.maxValues,
this.isDisabled,
}) : super(type: MessageComponentType.channelSelect);

@override
Map<String, Object?> build() => {
...super.build(),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/builders/sticker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class StickerUpdateBuilder implements UpdateBuilder<GuildSticker> {
String? name;

/// Description of the sticker (empty or 2-100 characters)
String description;
String? description;

/// Autocomplete/suggestion tags for the sticker (max 200 characters)
String? tags;
Expand All @@ -40,7 +40,7 @@ class StickerUpdateBuilder implements UpdateBuilder<GuildSticker> {

@override
Map<String, Object?> build() => {
if (!identical(description, sentinelString)) "description": description,
if (!identical(description, sentinelString)) "description": description ?? '',
if (name != null) "name": name,
if (tags != null) "tags": tags,
};
Expand Down
Loading