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/doc #111

Merged
merged 2 commits into from
May 18, 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
20 changes: 12 additions & 8 deletions lib/src/api/channels/category_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class CategoryChannel extends GuildChannel {
/// Get children of this
Map<Snowflake, GuildChannel> get children => guild.channels.cache.where((element) => element.parent?.id == id);

/// Create a Category channel
/// ```dart
/// final CategoryChannel category = await guild.channels.create(ChannelBuilder.fromCategoryChannel(label: "Lorem", position: 0, permissions: []));
/// ```
Future<T?> create<T extends GuildChannel> (ChannelBuilder channel) async {
return super.guild.channels.create(channel);
}
Expand All @@ -21,14 +25,14 @@ class CategoryChannel extends GuildChannel {
}

return CategoryChannel(
payload['guild_id'],
payload['parent_id'],
payload['name'],
payload['type'],
payload['position'],
payload['flags'],
permissionOverwriteManager,
payload['id']
payload['guild_id'],
payload['parent_id'],
payload['name'],
payload['type'],
payload['position'],
payload['flags'],
permissionOverwriteManager,
payload['id']
);
}
}
1 change: 1 addition & 0 deletions lib/src/api/channels/text_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class TextChannel extends TextBasedChannel {
await update(ChannelBuilder({ 'rate_limit': limit }));
}

/// Get parent [CategoryChannel] of this
@override
CategoryChannel? get parent => super.parent as CategoryChannel?;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/api/channels/thread_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ThreadChannel extends PartialTextChannel {
/// Get birthday of this
DateTime get createdAt => DateTime.parse(_createdAt);

/// Get parent of this
/// Get parent [CategoryChannel] of this
@override
TextChannel get parent => super.parent as TextChannel;

Expand Down
7 changes: 4 additions & 3 deletions lib/src/api/channels/voice_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class VoiceChannel extends TextBasedChannel {
/// Get current online members
Map<Snowflake, GuildMember> get members => guild.members.cache.where((member) => member.voice.channel?.id == id);

/// Get parent [CategoryChannel] of this
@override
CategoryChannel? get parent => super.parent as CategoryChannel?;

/// Define the bitrate of this
Future<void> setBitrate (int bitrate) async {
await update(ChannelBuilder({ 'bitrate': bitrate }));
Expand All @@ -64,9 +68,6 @@ class VoiceChannel extends TextBasedChannel {
await update(ChannelBuilder({ 'video_quality_mode': mode.value }));
}

@override
CategoryChannel? get parent => super.parent as CategoryChannel?;

factory VoiceChannel.fromPayload(dynamic payload) {
final permissionOverwriteManager = PermissionOverwriteManager();
for (dynamic element in payload['permission_overwrites']) {
Expand Down
9 changes: 9 additions & 0 deletions lib/src/api/client/client_presence.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,23 @@ class ClientPresence {
this._flags,
);

/// Get label of this
String? get label => _label;
/// Get type of this
GamePresence get type => GamePresence.values.firstWhere((type) => type.value == _type);
/// Get url of this
String? get url => _url;
/// Get created time of this
DateTime get createdAt => DateTime.parse(_createdAt);
/// Get timestamps of this
Timestamp? get timestamps => _timestamps != null ? Timestamp.from(payload: _timestamps) : null;
/// Get application id of this
Snowflake? get applicationId => _applicationId;
/// Get details of this
String? get details => _details;
/// Get state of this
String? get state => _state;
/// Get flags of this
int? get flags => _flags;

factory ClientPresence.from({ required dynamic payload }) {
Expand Down
1 change: 0 additions & 1 deletion lib/src/api/client/permission_bit_field.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:mineral/core/api.dart';
import 'package:mineral/src/helper.dart';
import 'package:mineral_ioc/ioc.dart';

class PermissionBitField {
final List<int> _permissions;
Expand Down
16 changes: 8 additions & 8 deletions lib/src/api/guilds/guild.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class Guild {

/// Defines the explicit content level of this
/// ```dart
/// await guild.setExplicitContentFilter(2);
/// await guild.setExplicitContentFilter(ExplicitContentLevel.allMembers);
/// ```
Future<void> setExplicitContentFilter (ExplicitContentLevel level) async {
Response response = await ioc.use<DiscordApiHttpService>().patch(url: "/guilds/$id")
Expand All @@ -346,7 +346,7 @@ class Guild {
///
/// ```dart
/// final voiceChannel = guild.channels.cache.getOrFail('240561194958716924');
/// await guild.setAfkChannel(2);
/// await guild.setAfkChannel(voiceChannel);
/// ```
Future<void> setAfkChannel (VoiceChannel channel) async {
Response response = await ioc.use<DiscordApiHttpService>().patch(url: "/guilds/$id")
Expand Down Expand Up @@ -544,7 +544,7 @@ class Guild {
/// Update system channel of this
///
/// ```dart
/// final channel = guild.channels.cache.getOrFail('240561194958716924');
/// final TextChannel channel = guild.channels.cache.getOrFail('240561194958716924');
/// await guild.setSystemChannel(channel);
/// ```
Future<void> setSystemChannel (TextChannel channel) async {
Expand All @@ -561,7 +561,7 @@ class Guild {
/// Update rules channel of this
///
/// ```dart
/// final channel = guild.channels.cache.getOrFail('240561194958716924');
/// final TextChannel channel = guild.channels.cache.getOrFail('240561194958716924');
/// await guild.setRulesChannel(channel);
/// ```
Future<void> setRulesChannel (TextChannel channel) async {
Expand All @@ -578,7 +578,7 @@ class Guild {
/// Update public updates channel of this
///
/// ```dart
/// final channel = guild.channels.cache.getOrFail('240561194958716924');
/// final TextChannel channel = guild.channels.cache.getOrFail('240561194958716924');
/// await guild.setPublicUpdateChannel(channel);
/// ```
Future<void> setPublicUpdateChannel (TextChannel channel) async {
Expand Down Expand Up @@ -633,12 +633,12 @@ class Guild {
);
}

/// Unbanned this from the [Guild] and deleted its messages for a given period
/// Unbanned member from this.
///
/// ```dart
/// await member.unban();
/// await member.unban("670642326661496866", reason: "Lorem ipsum dolor sit amet");
/// ```
Future<bool> ban (Snowflake memberId, { String? reason }) async {
Future<bool> unban (Snowflake memberId, { String? reason }) async {
Response response = await ioc.use<DiscordApiHttpService>().destroy(url: '/guilds/$id/bans/$memberId')
.auditLog(reason)
.build();
Expand Down
7 changes: 7 additions & 0 deletions lib/src/api/guilds/guild_scheduled_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import 'package:mineral_ioc/ioc.dart';

/// Represents a [GuildScheduledEvent] status of a [User].
enum ScheduledEventStatus {
/// The event is scheduled.
scheduled(1),
/// The event is active.
active(2),
/// The event is completed.
completed(3),
/// The event is canceled.
canceled(4);

final int value;
Expand All @@ -17,8 +21,11 @@ enum ScheduledEventStatus {

/// Represents a [GuildScheduledEvent] of a [Guild].
enum ScheduledEventEntityType {
/// The event is a stage instance.
stageInstance(1),
/// The event is a voice channel.
voice(2),
/// The event is a external stream.
external(3);

final int value;
Expand Down
4 changes: 4 additions & 0 deletions lib/src/api/interactions/button_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ class ButtonInteraction extends Interaction {
this._channelId,
);

/// Get custom id of this
Snowflake get customId => _customId;
/// Get message id of this
Snowflake? get mid => _messageId;
/// Get message [PartialMessage] of this
PartialMessage? get message => guild != null
? (guild?.channels.cache.get(_channelId) as dynamic)?.messages.cache[_messageId]
: ioc.use<MineralClient>().dmChannels.cache.get(_channelId)?.messages.cache.getOrFail(_messageId);
/// Get channel [PartialChannel] of this
PartialChannel get channel => guild != null
? guild!.channels.cache.getOrFail<TextBasedChannel>(_channelId)
: throw UnsupportedError('DM channel is not supported');
Expand Down
4 changes: 4 additions & 0 deletions lib/src/api/interactions/command_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ class CommandInteraction extends Interaction {
this._params,
);

/// Get identifier of this
String get identifier => _identifier;
/// Get channel [PartialChannel] of this
PartialChannel? get channel => guild != null
? guild!.channels.cache.get(_channelId)
: ioc.use<MineralClient>().dmChannels.cache.get(_channelId);

/// Get data of this
Map<String, dynamic> get data => _data;
/// Get params of this
Map<String, dynamic> get params => _params;

/// Returns an instance of [T] or null if the command has the designed option
Expand Down
1 change: 1 addition & 0 deletions lib/src/api/interactions/context_menu_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ContextMenuInteraction extends Interaction {
super._guildId,
);

/// Get type of this
ContextMenuType get typeMenu => ContextMenuType.values.firstWhere((element) => element.value == _type);

Object get toJson => {
Expand Down
2 changes: 2 additions & 0 deletions lib/src/api/interactions/context_message_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class ContextMessageInteraction extends ContextMenuInteraction {
super._guildId,
);

/// Get message [Message] of this
Message get message => _message;
/// Get channel [TextBasedChannel] of this
TextBasedChannel get channel => guild!.channels.cache.get(_channelId)!;

factory ContextMessageInteraction.from({ required Message message, required dynamic payload }) {
Expand Down
2 changes: 2 additions & 0 deletions lib/src/api/interactions/context_user_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class ContextUserInteraction extends ContextMenuInteraction {
super._guild,
);

/// Get target [GuildMember] of this
GuildMember? get target => guild?.members.cache.get(_targetId);
/// Get channel [GuildChannel] of this
GuildChannel? get channel => guild?.channels.cache.get(_channelId);

factory ContextUserInteraction.from({ required dynamic payload }) {
Expand Down
1 change: 1 addition & 0 deletions lib/src/api/interactions/global_command_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class GlobalCommandInteraction extends CommandInteraction {
super.params
);

/// Get channel [PartialChannel] of this
@override
PartialChannel? get channel => super.channel as PartialChannel;

Expand Down
1 change: 1 addition & 0 deletions lib/src/api/interactions/guild_command_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class GuildCommandInteraction extends CommandInteraction {
super.params
);

/// Get channel [TextBasedChannel] of this
@override
TextBasedChannel? get channel => super.channel as TextBasedChannel;

Expand Down
18 changes: 18 additions & 0 deletions lib/src/api/interactions/interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import 'package:mineral/framework.dart';
import 'package:mineral/src/api/messages/message_parser.dart';
import 'package:mineral_ioc/ioc.dart';

/// ### Interaction Type
/// - [ping] : A ping
/// - [channelMessageWithSource] : A message component
/// - [deferredChannelMessageWithSource] : A deferred message component
/// - [deferredUpdateMessage] : A deferred message update
/// - [updateMessage] : A message update
/// - [applicationCommandAutocompleteResult] : A command autocomplete result
/// - [modal] : A modal
///
enum InteractionCallbackType {
pong(1),
channelMessageWithSource(4),
Expand All @@ -30,18 +39,27 @@ class Interaction {

Interaction(this._id, this._label, this._applicationId, this._version, this._typeId, this._token, this._userId, this._guildId);

/// Get id [Snowflake] of this
Snowflake get id => _id;
/// Get label [String] of this
String? get label => _label;
/// Get application id [Snowflake] of this
Snowflake get applicationId => _applicationId;
/// Get version [int] of this
int get version => _version;
/// Get type [InteractionType] of this
InteractionType get type => InteractionType.values.firstWhere((element) => element.value == _typeId);
/// Get token [String] of this
String get token => _token;
/// Get guild [Guild] of this
Guild? get guild => ioc.use<MineralClient>().guilds.cache.get(_guildId);

/// Get user [User] of this
User get user => _guildId != null
? guild!.members.cache.getOrFail(_userId).user
: ioc.use<MineralClient>().users.cache.getOrFail(_userId);

/// Get member [GuildMember] of this
GuildMember? get member => guild?.members.cache.get(_userId);

/// ### Responds to this by an [Message]
Expand Down
2 changes: 2 additions & 0 deletions lib/src/api/interactions/modal_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class ModalInteraction extends Interaction {
this._channelId,
);

/// Get custom id [Snowflake] of this
Snowflake get customId => _customId;
/// Get channel [PartialChannel] of this
PartialChannel? get channel => guild != null
? guild?.channels.cache.get(_channelId)
: ioc.use<MineralClient>().dmChannels.cache.get(_channelId);
Expand Down
21 changes: 21 additions & 0 deletions lib/src/api/invites/invite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,68 @@ class Invite {
this._targetType,
);

/// Get guild [Guild] of this
Guild get guild => ioc.use<MineralClient>().guilds.cache.getOrFail(_guildId);

/// Get type [int] of this
int get type => _type;

/// Get uses [int] of this
int get uses => _uses;

/// Get if this is temporary [bool] of this
bool get isTemporary => _temporary;

/// Get max uses [int] of this
int get maxUses => _maxUses;

/// Get max age [DateTime] of this
DateTime get maxAge => DateTime.fromMillisecondsSinceEpoch(_maxAge);

/// Get expires at [DateTime] of this
DateTime? get expiresAt => _expiresAt != null
? DateTime.parse(_expiresAt!)
: null;

/// Get created at [DateTime] of this
DateTime get createdAt => DateTime.parse(_createdAt);

/// Get code [String] of this
String get code => _code;

/// Get channel [GuildChannel] of this
GuildChannel? get channel => guild.channels.cache.get(_channelId);

/// Get target type [InviteTargetType] of this
InviteTargetType get targetType => InviteTargetType.values.firstWhere((element) => element.value == _targetType);

/// Get inviter [WrappedInviter] of this
WrappedInviter? getInviter () => _inviterId != null && _guildId != null
? WrappedInviter(_guildId!, _inviterId!)
: null;

/// Get target user [User] of this
Future<User>? getTargetUser () => _targetUserId != null
? ioc.use<MineralClient>().users.resolve(_targetUserId!)
: null;

/// Get url [String] of this
String get url => '${Constants.discordInviteHost}/$_code';

/// Delete this invite
///
/// ```dart
/// Invite invite = guild.invites.cache.get('invite_code');
/// invite.delete(reason: 'reason');
/// ```
Future<void> delete ({ String? reason }) async {
await ioc.use<DiscordApiHttpService>()
.destroy(url: '/invites/$_code')
.auditLog(reason)
.build();
}

/// Get beautiful of this
@override
String toString () => url;

Expand Down
Loading