Skip to content

Commit

Permalink
Merge pull request #97 from mineral-dart/develop
Browse files Browse the repository at this point in the history
feat: Release 3.1.0
  • Loading branch information
LeadcodeDev authored Mar 29, 2023
2 parents da97ac4 + b2a1e85 commit 4c3dff6
Show file tree
Hide file tree
Showing 109 changed files with 1,806 additions and 586 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 3.1.0
- Implement Invites
- Implement invite packets (create, delete)
- Implement many select menus (dynamic, user, role, channel, mentionable)
- Migrate of Discord component to builders (wait next release to allow constructor declaration)
- Improve `main.dart` file entrypoint
- Implement new package concept
- Fix message delete issue (no message when resolving from message id)

## 3.0.0
- Implement cli & refactor
- Implement new features
Expand Down
6 changes: 5 additions & 1 deletion lib/core/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export '../src/api/interactions/context_message_interaction.dart' show ContextMe
export '../src/api/interactions/context_user_interaction.dart' show ContextUserInteraction;
export '../src/api/interactions/interaction.dart' show Interaction;
export '../src/api/interactions/modal_interaction.dart' show ModalInteraction;
export '../src/api/interactions/select_menu_interaction.dart' show SelectMenuInteraction;
export '../src/api/interactions/menus/dynamic_menu_interaction.dart' show DynamicMenuInteraction;
export '../src/api/interactions/menus/user_menu_interaction.dart' show UserMenuInteraction;
export '../src/api/managers/member_role_manager.dart' show MemberRoleManager;
export '../src/api/managers/voice_manager.dart' show VoiceManager;
export '../src/api/managers/message_manager.dart' show MessageManager, BulkDeleteBuilder;
Expand All @@ -47,5 +48,8 @@ export '../src/internal/services/intent_service.dart' show Intent;
export '../src/api/users/premium_type.dart' show PremiumType;
export '../src/api/users/user_decoration.dart' show UserDecoration;
export '../src/api/users/user_flags/user_flag_contract.dart' show UserFlagContract;
export '../src/api/client/client_scope.dart' show ClientScope;
export '../src/api/client/client_permission.dart' show ClientPermission;
export '../src/api/guilds/activities/activity_type.dart' show ActivityType;

typedef Snowflake = String;
20 changes: 16 additions & 4 deletions lib/core/builders.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/// Includes classes for designing buttons, selection menus and more
library builders;

export '../src/api/builders/button_builder.dart' show ButtonBuilder, ButtonStyle;
export '../src/api/builders/component_builder.dart' show ComponentBuilder;
export '../src/api/builders/buttons/button_builder.dart' show ButtonBuilder;
export '../src/api/builders/buttons/button_style.dart' show ButtonStyle;
export '../src/api/builders/channel_builder.dart' show ChannelBuilder;
export '../src/api/builders/code_builder.dart' show CodeBuilder;
export '../src/api/builders/embed_builder.dart' show EmbedBuilder, Footer, Image, Thumbnail, Author, Field;
Expand All @@ -11,6 +13,16 @@ export '../src/api/builders/message_builder.dart' show MessageBuilder;
export '../src/api/builders/modal_builder.dart' show ModalBuilder;
export '../src/api/builders/moderation_rules_builder.dart' show ModerationRulesBuilder;
export '../src/api/builders/row_builder.dart' show RowBuilder;
export '../src/api/builders/select_menu_builder.dart' show SelectMenuBuilder, SelectMenuOption, EmojiOption;
export '../src/api/builders/text_input_builder.dart' show TextInputBuilder, TextInputStyle;
export '../src/api/builders/attachment_builder.dart' show AttachmentBuilder;

export '../src/api/builders/menus/dynamic_select_menu_builder.dart' show DynamicSelectMenuBuilder, SelectMenuOption, EmojiOption;
export '../src/api/builders/menus/user_select_menu_builder.dart' show UserSelectMenuBuilder;
export '../src/api/builders/menus/role_select_menu_builder.dart' show RoleSelectMenuBuilder;
export '../src/api/builders/menus/channel_select_menu_builder.dart' show ChannelSelectMenuBuilder;
export '../src/api/builders/menus/mentionable_select_menu_builder.dart' show MentionableSelectMenuBuilder;

export '../src/api/builders/modal/text_builder.dart' show TextBuilder;
export '../src/api/builders/modal/paragraph_builder.dart' show ParagraphBuilder;

export '../src/api/builders/attachment_builder.dart' show AttachmentBuilder;
export '../src/api/builders/markdown/markdown.dart' show Md;
export '../src/api/builders/markdown/timestamp_style.dart' show TimestampStyle;
11 changes: 9 additions & 2 deletions lib/core/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export '../src/internal/websockets/events/guild_scheduled_event_update_event.dar
export '../src/internal/websockets/events/guild_scheduled_event_user_add_event.dart';
export '../src/internal/websockets/events/guild_scheduled_event_user_remove_event.dart';
export '../src/internal/websockets/events/guild_update_event.dart';
export '../src/internal/websockets/events/guild_delete_event.dart';
export '../src/internal/websockets/events/member_deaf_event.dart';
export '../src/internal/websockets/events/member_join_event.dart';
export '../src/internal/websockets/events/member_leave_event.dart';
Expand All @@ -35,9 +36,15 @@ export '../src/internal/websockets/events/moderation_rules_delete_event.dart';
export '../src/internal/websockets/events/moderation_rules_update_event.dart';
export '../src/internal/websockets/events/presence_update_event.dart';
export '../src/internal/websockets/events/ready_event.dart';
export '../src/internal/websockets/events/select_menu_create_event.dart';
export '../src/internal/websockets/events/dynamic_menu_create_event.dart';
export '../src/internal/websockets/events/user_menu_create_event.dart';
export '../src/internal/websockets/events/channel_menu_create_event.dart';
export '../src/internal/websockets/events/role_menu_create_event.dart';
export '../src/internal/websockets/events/mentionable_menu_create_event.dart';
export '../src/internal/websockets/events/voice_join_event.dart';
export '../src/internal/websockets/events/voice_leave_event.dart';
export '../src/internal/websockets/events/voice_move_event.dart';
export '../src/internal/websockets/events/voice_state_update_event.dart';
export '../src/internal/websockets/events/webhook_update_event.dart';
export '../src/internal/websockets/events/webhook_update_event.dart';
export '../src/internal/websockets/events/invite_create_event.dart';
export '../src/internal/websockets/events/invite_delete_event.dart';
8 changes: 8 additions & 0 deletions lib/core/services.dart
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;
1 change: 0 additions & 1 deletion lib/framework.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ library framework;
export '../src/internal/entities/command.dart' show MineralCommand, CommandBuilder, Option, OptionType, OptionChoice, SubCommandBuilder, CommandGroupBuilder, Scope;
export '../src/internal/entities/context_menu.dart' show MineralContextMenu;
export '../src/internal/entities/event.dart' show MineralEvent, Event;
export '../src/internal/entities/module.dart' show MineralModule;
export '../src/internal/entities/state.dart' show MineralState;
export '../src/internal/mixins/console.dart';
export 'src/internal/mixins/collection.dart';
Expand Down
48 changes: 0 additions & 48 deletions lib/src/api/builders/button_builder.dart

This file was deleted.

55 changes: 55 additions & 0 deletions lib/src/api/builders/buttons/button_builder.dart
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,
};
}
13 changes: 13 additions & 0 deletions lib/src/api/builders/buttons/button_style.dart
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();
}
7 changes: 7 additions & 0 deletions lib/src/api/builders/buttons/clickable_button.dart
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);

}
3 changes: 3 additions & 0 deletions lib/src/api/builders/buttons/contracts/button_contract.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
abstract class ButtonContract {

}
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);
}
14 changes: 14 additions & 0 deletions lib/src/api/builders/buttons/contracts/link_contract.dart
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);
}
6 changes: 6 additions & 0 deletions lib/src/api/builders/buttons/link_button.dart
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);
}
79 changes: 24 additions & 55 deletions lib/src/api/builders/component_builder.dart
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 ();
}
}
Loading

0 comments on commit 4c3dff6

Please sign in to comment.