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

feat: Implement missing features #55

Merged
merged 15 commits into from
Aug 23, 2022
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
15 changes: 8 additions & 7 deletions lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export 'src/api/managers/member_role_manager.dart' show MemberRoleManager;
export 'src/api/managers/voice_manager.dart' show VoiceManager;

export 'src/api/guilds/guild.dart' show Guild;
export 'src/api/guilds/guild_preview.dart' show GuildPreview;
export 'src/api/moderation_rule.dart' show ModerationEventType, ModerationTriggerType, ModerationPresetType, ModerationActionType, ModerationTriggerMetadata, ModerationActionMetadata, ModerationAction, ModerationRule;

export 'src/api/guilds/guild_scheduled_event.dart' show ScheduledEventStatus, ScheduledEventEntityType, GuildScheduledEvent, ScheduledEventUser;
Expand All @@ -28,18 +29,18 @@ export 'src/api/channels/news_channel.dart' show NewsChannel;
export 'src/api/channels/permission_overwrite.dart' show PermissionOverwrite, PermissionOverwriteType;

export 'src/api/messages/message.dart' show Message;
export 'src/api/messages/message_embed.dart' show MessageEmbed, Footer, Image, Thumbnail, Author, Field;
export 'src/api/messages/embed_builder.dart' show EmbedBuilder, Footer, Image, Thumbnail, Author, Field;
export 'src/api/color.dart' show Color;

export 'src/api/emoji.dart' show EmojiBuilder, Emoji;
export 'src/api/role.dart' show Role;

export 'src/api/components/row.dart' show Row;
export 'src/api/components/select_menu.dart' show SelectMenu, SelectMenuOption, EmojiOption;
export 'src/api/components/modal.dart' show Modal;
export 'src/api/components/text_input.dart' show TextInputStyle;
export 'src/api/components/button.dart' show Button, ButtonStyle;
export 'src/api/components/link.dart' show Link;
export 'src/api/components/row_builder.dart' show RowBuilder;
export 'src/api/components/select_menu_builder.dart' show SelectMenuBuilder, SelectMenuOption, EmojiOption;
export 'src/api/components/modal_builder.dart' show ModalBuilder;
export 'src/api/components/text_input_builder.dart' show TextInputBuilder, TextInputStyle;
export 'src/api/components/button_builder.dart' show ButtonBuilder, ButtonStyle;
export 'src/api/components/link_builder.dart' show LinkBuilder;

export 'src/api/interactions/command_interaction.dart' show CommandInteraction;
export 'src/api/interactions/button_interaction.dart' show ButtonInteraction;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/api/channels/text_based_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TextBasedChannel extends Channel {
MessageManager get messages => _messages;
ThreadManager get threads => _threads;

Future<Message?> send ({ String? content, List<MessageEmbed>? embeds, List<Row>? components, bool? tts }) async {
Future<Message?> send ({ String? content, List<EmbedBuilder>? embeds, List<RowBuilder>? components, bool? tts }) async {
MineralClient client = ioc.singleton(ioc.services.client);

Response response = await client.sendMessage(this,
Expand Down
5 changes: 4 additions & 1 deletion lib/src/api/client/mineral_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class MineralClient {
String _sessionId;
Application _application;
List<Intent> _intents;
late DateTime uptime;

MineralClient(
this._user,
Expand All @@ -96,9 +97,11 @@ class MineralClient {
Application get application => _application;
List<Intent> get intents => _intents;

/// ### Returns the time the [MineralClient] is online
Duration get uptimeDuration => DateTime.now().difference(uptime);

/// ### Defines the presence that this should adopt
///
///
/// Example :
/// ```dart
/// client.setPresence(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ enum ButtonStyle {
String toString () => value.toString();
}

class Button extends Component {
class ButtonBuilder extends Component {
String customId;
String label;
String? label;
ButtonStyle style;
EmojiBuilder? emoji;
bool disabled;

Button({ required this.customId, required this.label, required this.style, this.emoji, this.disabled = false }) : super(type: ComponentType.button);
ButtonBuilder({ required this.customId, this.label, required this.style, this.emoji, this.disabled = false }) : super(type: ComponentType.button);

@override
dynamic toJson () {
Expand All @@ -36,8 +36,8 @@ class Button extends Component {
};
}

factory Button.from({ required dynamic payload }) {
return Button(
factory ButtonBuilder.from({ required dynamic payload }) {
return ButtonBuilder(
customId: payload['custom_id'],
label: payload['label'],
style: ButtonStyle.values.firstWhere((element) => element.value == payload['style'])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:mineral/src/api/components/component.dart';

class Link extends Component {
class LinkBuilder extends Component {
String label;
String url;
int style = 5;

Link({ required this.label, required this.url }) : super(type: ComponentType.button);
LinkBuilder({ required this.label, required this.url }) : super(type: ComponentType.button);

@override
dynamic toJson () {
Expand All @@ -17,8 +17,8 @@ class Link extends Component {
};
}

factory Link.from({ required dynamic payload }) {
return Link(
factory LinkBuilder.from({ required dynamic payload }) {
return LinkBuilder(
url: payload['url'],
label: payload['label'],
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
import 'package:mineral/src/api/components/component.dart';
import 'package:mineral/src/api/components/text_input.dart';

import '../../../api.dart';

class Modal extends Component {
class ModalBuilder extends Component {
String label;
String customId;

List<Row> components = [];
List<RowBuilder>? components = [];

Modal({ required this.customId, required this.label }) : super(type: ComponentType.selectMenu);
ModalBuilder({ required this.customId, required this.label, this.components }) : super(type: ComponentType.selectMenu);

/// ### Created a input text field
///
/// Example :
/// ```dart
/// final Modal modal = Modal(customId: 'my_modal', label: 'My modal')
/// final ModalBuilder modal = ModalBuilder(customId: 'my_modal', label: 'My modal')
/// .addInput(customId: 'my_text', label: 'Premier texte');
/// ```
Modal addInput ({ required String customId, required String label, bool? required, int? minLength, int? maxLength, String? placeholder, String? value }) {
_addInput(customId: customId, label: label, style: TextInputStyle.short, required: required, minLength: minLength, maxLength: maxLength, placeholder: placeholder, value: value);
ModalBuilder addInput ({ required String customId, required String label, bool? required, int? minLength, int? maxLength, String? placeholder, String? value }) {
_addInput(customId: customId, label: label, style: TextInputStyle.input, required: required, minLength: minLength, maxLength: maxLength, placeholder: placeholder, value: value);
return this;
}

/// ### Created a input text field with multiple lines
///
/// Example :
/// ```dart
/// final Modal modal = Modal(customId: 'my_modal', label: 'My modal')
/// final ModalBuilder modal = ModalBuilder(customId: 'my_modal', label: 'My modal')
/// .addParagraph(customId: 'my_paragraph', label: 'Second texte');
/// ```
Modal addParagraph ({ required String customId, required String label, bool? required, int? minLength, int? maxLength, String? placeholder, String? value }) {
ModalBuilder addParagraph ({ required String customId, required String label, bool? required, int? minLength, int? maxLength, String? placeholder, String? value }) {
_addInput(customId: customId, label: label, style: TextInputStyle.paragraph, required: required, minLength: minLength, maxLength: maxLength, placeholder: placeholder, value: value);
return this;
}

void _addInput ({ required String customId, required String label, required TextInputStyle style, bool? required, int? minLength, int? maxLength, String? placeholder, String? value }) {
TextInput input = TextInput(
components ??= [];

final TextInputBuilder input = TextInputBuilder(
customId: customId,
label: label,
style: style,
Expand All @@ -47,15 +48,15 @@ class Modal extends Component {
value: value,
);

components.add(Row(components: [input]));
components?.add(RowBuilder.fromComponents([input]));
}

@override
Object toJson() {
return {
'title': label,
'custom_id': customId,
'components': components.map((component) => component.toJson()).toList()
'components': components?.map((component) => component.toJson()).toList()
};
}
}
19 changes: 0 additions & 19 deletions lib/src/api/components/row.dart

This file was deleted.

28 changes: 28 additions & 0 deletions lib/src/api/components/row_builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:mineral/api.dart';
import 'package:mineral/src/api/components/component.dart';

class RowBuilder extends Component {
List<Component> components = [];

RowBuilder() : super(type: ComponentType.actionRow);

@override
Object toJson () {
return {
'type': type.value,
'components': components.map((Component component) => component.toJson()).toList()
};
}

factory RowBuilder.fromComponents(List<Component> components) {
return RowBuilder.fromComponents(components);
}

factory RowBuilder.fromComponent(Component component) {
return RowBuilder.fromComponents([component]);
}

factory RowBuilder.fromTextInput(TextInputBuilder input) {
return RowBuilder.fromComponents([input]);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import 'package:mineral/api.dart';
import 'package:mineral/src/api/components/component.dart';

class SelectMenu extends Component {
class SelectMenuBuilder extends Component {
String customId;
List<SelectMenuOption> options = [];
String? placeholder;
int? minValues = 1;
int? maxValues = 25;
bool? disabled = false;

SelectMenu({ required this.customId, required this.options, this.placeholder, this.minValues, this.maxValues, this.disabled }) : super (type: ComponentType.selectMenu);
SelectMenuBuilder({ required this.customId, required this.options, this.placeholder, this.minValues, this.maxValues, this.disabled }) : super (type: ComponentType.selectMenu);

RowBuilder toRow () => RowBuilder.fromComponents([this]);

@override
Object toJson () {
Expand Down Expand Up @@ -43,7 +45,7 @@ class SelectMenuOption<T> {
String label;
String description;
T value;
EmojiOption? emoji;
EmojiBuilder? emoji;

SelectMenuOption({ required this.label, required this.description, required this.value, this.emoji });

Expand All @@ -52,7 +54,7 @@ class SelectMenuOption<T> {
'label': label,
'description': description,
'value': value,
'emoji': emoji?.toJson(),
'emoji': emoji?.emoji.toJson(),
};
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:mineral/src/api/components/component.dart';

enum TextInputStyle {
short(1),
input(1),
paragraph(2);

final int value;
Expand All @@ -11,23 +11,23 @@ enum TextInputStyle {
String toString () => value.toString();
}

class TextInput extends Component {
class TextInputBuilder extends Component {
String customId;
String label;
TextInputStyle style;
int? minLength;
int? maxLength;
bool required;
bool required = false;
String? placeholder;
String? value;

TextInput({
TextInputBuilder({
required this.customId,
required this.label,
required this.style,
this.minLength,
this.maxLength,
required this.required,
this.required = false,
this.placeholder,
this.value,
}) : super(type: ComponentType.textInput);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/api/emoji.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Emoji extends PartialEmoji {
@override
String toString () => isAnimated
? '<a:$label:$id>'
: '<$label:$id>';
: '<:$label:$id>';

factory Emoji.from({ required MemberManager memberManager, required EmojiManager emojiManager, required dynamic payload }) {
return Emoji(
Expand Down
17 changes: 12 additions & 5 deletions lib/src/api/guilds/guild.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:http/http.dart';
import 'package:mineral/api.dart';
import 'package:mineral/console.dart';
Expand All @@ -13,7 +15,6 @@ import 'package:mineral/src/api/managers/moderation_rule_manager.dart';
import 'package:mineral/src/api/managers/sticker_manager.dart';
import 'package:mineral/src/api/managers/webhook_manager.dart';
import 'package:mineral/src/api/managers/guild_scheduled_event_manager.dart';
import 'package:mineral/src/api/sticker.dart';
import 'package:mineral/src/api/welcome_screen.dart';

import 'package:collection/collection.dart';
Expand Down Expand Up @@ -544,6 +545,16 @@ class Guild {
}
}

Future<GuildPreview> preview () async {
Http http = ioc.singleton(ioc.services.http);
Response response = await http.get(url: '/guilds/$id/preview');

return GuildPreview.from(
guild: this,
payload: jsonDecode(response.body)
);
}

factory Guild.from({
required EmojiManager emojiManager,
required MemberManager memberManager,
Expand All @@ -555,10 +566,6 @@ class Guild {
required dynamic payload
}) {
StickerManager stickerManager = StickerManager();
for (dynamic element in payload['stickers']) {
Sticker sticker = Sticker.from(element);
stickerManager.cache.putIfAbsent(sticker.id, () => sticker);
}

List<GuildFeature> features = [];
for (String element in payload['features']) {
Expand Down
1 change: 0 additions & 1 deletion lib/src/api/guilds/guild_member_reaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class GuildMemberReaction {
? '${_partialEmoji.label}:${_partialEmoji.id}'
: _partialEmoji.label;

print('/channels/${_message.channel.id}/messages/${_message.id}/reactions/$_emoji/${user.id}');
Response response = await http.destroy(url: '/channels/${_message.channel.id}/messages/${_message.id}/reactions/$_emoji/${user.id}');
if (response.statusCode == 200) {
_manager.reactions.remove(_emoji);
Expand Down
Loading