-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from mineral-dart/develop
feat: Release 3.1.0
- Loading branch information
Showing
109 changed files
with
1,806 additions
and
586 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// Contain all Mineral public services | ||
library services; | ||
|
||
export 'package:mineral/src/internal/services/event_service.dart' show EventService; | ||
export 'package:mineral/src/internal/services/command_service.dart' show CommandService; | ||
export 'package:mineral/src/internal/services/intent_service.dart' show IntentService; | ||
export 'package:mineral/src/internal/services/package_service.dart' show PackageService; | ||
export 'package:mineral/src/internal/services/shared_state_service.dart' show SharedStateService; |
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import 'package:mineral/core/builders.dart'; | ||
import 'package:mineral/src/api/builders/buttons/clickable_button.dart'; | ||
import 'package:mineral/src/api/builders/buttons/contracts/button_contract.dart'; | ||
import 'package:mineral/src/api/builders/buttons/contracts/clickable_button_contract.dart'; | ||
import 'package:mineral/src/api/builders/buttons/link_button.dart'; | ||
import 'package:mineral/src/api/builders/component_wrapper.dart'; | ||
|
||
import 'contracts/link_contract.dart'; | ||
|
||
class ButtonBuilder extends ComponentWrapper implements ButtonContract { | ||
static ClickableButtonContract button (String customId) => ClickableButton(customId, null, ButtonStyle.primary); | ||
static LinkContract link (String url) => LinkButton(null, url, ButtonStyle.link); | ||
|
||
final String? _customId; | ||
String? _label; | ||
ButtonStyle _style; | ||
EmojiBuilder? _emoji; | ||
bool _disabled = false; | ||
String? _url; | ||
|
||
ButtonBuilder(this._customId, this._url, this._style): super(type: ComponentType.button); | ||
|
||
String get customId => _customId!; | ||
|
||
String? get label => _label; | ||
|
||
ButtonStyle get style => _style; | ||
|
||
EmojiBuilder? get emoji => _emoji; | ||
|
||
bool get disabled => _disabled; | ||
|
||
String get url => _url!; | ||
|
||
void setLabel (String value) => _label = value; | ||
|
||
void setDisabled (bool value) => _disabled = value; | ||
|
||
void setEmoji (EmojiBuilder? value) => _emoji = value; | ||
|
||
void setStyle (ButtonStyle value) => _style = value; | ||
|
||
void setUrl (String value) => _url = value; | ||
|
||
@override | ||
Map<String, dynamic> toJson() => { | ||
'type': type?.value, | ||
'custom_id': _customId, | ||
'label': _label, | ||
'style': _style.value, | ||
'emoji': _emoji?.emoji.toJson(), | ||
'disabled': _disabled, | ||
'url': _url, | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
enum ButtonStyle { | ||
primary(1), | ||
secondary(2), | ||
success(3), | ||
danger(4), | ||
link(5); | ||
|
||
final int value; | ||
const ButtonStyle(this.value); | ||
|
||
@override | ||
String toString () => value.toString(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import 'package:mineral/core/builders.dart'; | ||
import 'package:mineral/src/api/builders/buttons/contracts/clickable_button_contract.dart'; | ||
|
||
class ClickableButton extends ButtonBuilder implements ClickableButtonContract { | ||
ClickableButton(super.customId, super.url, super.style); | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
abstract class ButtonContract { | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
lib/src/api/builders/buttons/contracts/clickable_button_contract.dart
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:mineral/core/builders.dart'; | ||
import 'package:mineral/src/api/builders/buttons/contracts/button_contract.dart'; | ||
|
||
abstract class ClickableButtonContract extends ButtonContract { | ||
String get customId; | ||
String? get label; | ||
EmojiBuilder? get emoji; | ||
bool get disabled; | ||
ButtonStyle get style; | ||
|
||
void setStyle (ButtonStyle value); | ||
void setLabel (String value); | ||
void setDisabled (bool value); | ||
void setEmoji (EmojiBuilder value); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:mineral/core/builders.dart'; | ||
import 'package:mineral/src/api/builders/buttons/contracts/button_contract.dart'; | ||
|
||
abstract class LinkContract extends ButtonContract { | ||
String? get label; | ||
EmojiBuilder? get emoji; | ||
bool get disabled; | ||
String get url; | ||
|
||
void setUrl (String value); | ||
void setLabel (String value); | ||
void setDisabled (bool value); | ||
void setEmoji (EmojiBuilder value); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import 'package:mineral/core/builders.dart'; | ||
import 'package:mineral/src/api/builders/buttons/contracts/link_contract.dart'; | ||
|
||
class LinkButton extends ButtonBuilder implements LinkContract { | ||
LinkButton(super.customId, super.url, super.style); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,36 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:mineral/core/api.dart'; | ||
import 'package:mineral/core/builders.dart'; | ||
import 'package:mineral/framework.dart'; | ||
import 'package:mineral_ioc/ioc.dart'; | ||
import 'package:mineral/src/api/builders/component_wrapper.dart'; | ||
import 'package:mineral/src/api/builders/menus/select_menu_builder.dart'; | ||
import 'package:mineral/src/exceptions/too_many_exception.dart'; | ||
|
||
enum ComponentType { | ||
actionRow(1), | ||
button(2), | ||
selectMenu(3), | ||
textInput(4); | ||
import 'buttons/contracts/button_contract.dart'; | ||
|
||
final int value; | ||
const ComponentType(this.value); | ||
class ComponentBuilder { | ||
final List<RowBuilder> rows = []; | ||
|
||
@override | ||
String toString () => value.toString(); | ||
} | ||
ComponentBuilder(); | ||
|
||
abstract class ComponentBuilder { | ||
ComponentType type; | ||
void withSelectMenu<T extends SelectMenuBuilder> (T menu) { | ||
rows.add(RowBuilder([menu])); | ||
} | ||
|
||
ComponentBuilder({ required this.type }); | ||
ButtonWrapper get withButton => ButtonWrapper(this); | ||
} | ||
|
||
static wrap (dynamic payload, Snowflake? guildId) { | ||
final Guild? guild = ioc.use<MineralClient>().guilds.cache.get(guildId); | ||
final componentType = ComponentType.values.firstWhereOrNull((element) => element.value == payload['type']); | ||
class ButtonWrapper { | ||
final ComponentBuilder _builder; | ||
|
||
if (componentType == null) { | ||
return; | ||
} | ||
ButtonWrapper(this._builder); | ||
|
||
switch (componentType) { | ||
case ComponentType.button: | ||
final ButtonStyle style = ButtonStyle.values.firstWhere((element) => element.value == payload['style']); | ||
final EmojiBuilder? emojiBuilder = guild != null && payload['id'] != null | ||
? EmojiBuilder.fromEmoji(guild.emojis.cache.getOrFail(payload['id'])) | ||
: EmojiBuilder.fromUnicode(payload['emoji']?['name']); | ||
void only<T extends ButtonContract> (T builder) { | ||
_builder.rows.add(RowBuilder([builder as ComponentWrapper])); | ||
} | ||
|
||
return ButtonBuilder(payload['custom_id'], payload['label'], style, emojiBuilder, payload['disabled'], payload['url']); | ||
case ComponentType.actionRow: | ||
return RowBuilder(); | ||
case ComponentType.selectMenu: | ||
return SelectMenuBuilder( | ||
customId: payload['custom_id'], | ||
options: [], | ||
placeholder: payload['placeholder'], | ||
disabled: payload['disabled'], | ||
minValues: payload['min_values'], | ||
maxValues: payload['max_values'], | ||
); | ||
case ComponentType.textInput: | ||
return TextInputBuilder( | ||
customId: payload['custom_id'], | ||
label: payload['label'], | ||
style: TextInputStyle.values.firstWhere((element) => element.value == payload['style']), | ||
placeholder: payload['placeholder'], | ||
required: payload['required'], | ||
maxLength: payload['max_length'], | ||
minLength: payload['min_length'], | ||
value: payload['value'], | ||
); | ||
void many<T extends ButtonContract> (List<T> builders) { | ||
if (builders.length > 5) { | ||
throw TooManyException("You can't define more than 5 embeds in the same action-row"); | ||
} | ||
|
||
_builder.rows.add(RowBuilder(builders)); | ||
} | ||
|
||
dynamic toJson (); | ||
} | ||
} |
Oops, something went wrong.