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 new features #71

Merged
merged 33 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
df25633
docs: Write package docs
LeadcodeDev Nov 20, 2022
682acaf
feat: Move Environment to dedicated package
LeadcodeDev Nov 24, 2022
8001b74
feat: Add plugins access
LeadcodeDev Nov 24, 2022
61a1e2e
feat: Add plugins access
LeadcodeDev Nov 24, 2022
7c9f553
feat: using constructors to configure class components
LeadcodeDev Dec 7, 2022
4852803
docs: Write changelog
LeadcodeDev Dec 7, 2022
d4f4d33
feat: Improve some changes
LeadcodeDev Dec 10, 2022
7fc7ee0
refactor: Remove old files
LeadcodeDev Dec 27, 2022
9822bd3
feat: Create mixin to use new console package
LeadcodeDev Dec 27, 2022
2e6e41b
feat: Create compile:exe command
LeadcodeDev Dec 27, 2022
4c6fd35
feat: Create compile:js command
LeadcodeDev Dec 27, 2022
c736686
chore: Implement new mineral packages
LeadcodeDev Dec 27, 2022
fe29046
feat: Create compile:exe command
LeadcodeDev Dec 27, 2022
6fef2aa
feat: Move console import
LeadcodeDev Dec 27, 2022
92df6a4
feat: Create help command
LeadcodeDev Dec 27, 2022
44df0b5
feat: Improve implementation
LeadcodeDev Dec 27, 2022
86b3b74
feat: Move to final properties
LeadcodeDev Dec 27, 2022
d57c17c
feat: Change property visibility
LeadcodeDev Dec 27, 2022
c2d654b
refactor: Improve exceptions
LeadcodeDev Dec 27, 2022
393f529
refactor: Rename Http & Debugger services
LeadcodeDev Dec 27, 2022
79feac5
refactor: Rename ContextMenu & Environment services
LeadcodeDev Dec 27, 2022
4ba8339
refactor: Rename services
LeadcodeDev Dec 27, 2022
36e056e
refactor: Rename collector service
LeadcodeDev Dec 27, 2022
0017d65
refactor: Rename module service
LeadcodeDev Dec 27, 2022
0a83578
refactor: Rename shared state service
LeadcodeDev Dec 27, 2022
93316ad
refactor: Rename command service
LeadcodeDev Dec 27, 2022
9fca152
refactor: Rename plugin service
LeadcodeDev Dec 27, 2022
c4a5fd3
refactor: Rename intent service
LeadcodeDev Dec 27, 2022
c8516d6
refactor: Move extensions to mixins folder
LeadcodeDev Dec 27, 2022
b768bae
refactor: Improve code style
LeadcodeDev Dec 27, 2022
781ef41
feat: Improve help command & readme
LeadcodeDev Dec 27, 2022
541ad15
feat: Improve changelog and add recase dependency
LeadcodeDev Dec 27, 2022
c1f98f7
Merge pull request #70 from mineral-dart/feat-implmement-cli
LeadcodeDev Dec 27, 2022
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
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
## 2.4.0
- Redesign of the order guest
- Implemented the new CLI from `mineral_cli`.
- Removing dependencies using `ffi`
- Refactor application
- Move managers to services

## 2.3.1
- Fix bad User avatar decoration type
- Improve `category.create()` return type
- Make allow and deny to no required params

## 2.3.0
- Improve context menu declaration
- Fix bad state matching

## 2.2.0
- Add plugins access to the `MineralContext`

## 2.1.0
- Migrate environment to dedicated package

## 2.0.0 - Release
- Improve accessibility
- Implement lasted Discord updates
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ In order to simplify the association between a component (buttons, selection men

Consider the component displaying buttons below :
```dart
final button = ButtonBuilder(
final button = ButtonBuilder.fromButton(
label: 'My buttton',
customId: 'my-custom-id',
style: ButtonStyle.primary
Expand Down Expand Up @@ -135,12 +135,12 @@ Now that your store is registered within your application, you can now access yo
import 'package:mineral/framework.dart';
import 'package:mineral/core/events';

class MessageCreate extends MineralEvent<MessageCreate> {
class MessageCreate extends MineralEvent<MessageCreate> with Console {
Future<void> handle (Message message) async {
final myState = states.use<MyStore>();
myState.addItem(1);

Console.info(message: 'MyState contains ${store.state.length} items.');
console.info(message: 'MyState contains ${store.state.length} items.');
}
}
```
Expand Down
44 changes: 0 additions & 44 deletions bin/mineral.dart

This file was deleted.

3 changes: 1 addition & 2 deletions lib/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ library core;

export 'src/constants.dart';
export 'src/internal/kernel.dart' show Kernel;
export 'src/internal/services/environment.dart' show Environment;
export 'src/internal/services/http.dart';
export 'src/internal/services/http_service.dart';

2 changes: 1 addition & 1 deletion lib/core/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export '../src/api/status.dart' show Status, StatusType;
export '../src/api/user.dart' show User;
export '../src/api/utils.dart';
export '../src/api/webhook.dart' show Webhook;
export '../src/internal/managers/intent_manager.dart' show Intent;
export '../src/internal/services/intent_service.dart' show Intent;

typedef Snowflake = String;
1 change: 1 addition & 0 deletions lib/core/collectors.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Create collectors to filter out expected actions
library collectors;

export '../src/api/collectors/message_collector.dart' show MessageCollector;
1 change: 1 addition & 0 deletions lib/core/events.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// This package contains the events you can listen to from your Discord server
library events;

export '../src/internal/websockets/events/accept_rules_event.dart';
Expand Down
7 changes: 7 additions & 0 deletions lib/core/extras.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/// Access and interact with the framework itself.
///
/// ```dart
/// class MyClass with MineralContext, Container {
///
/// }
/// ```
library extras;

export '../src/internal/mixins/container.dart' show Container;
Expand Down
8 changes: 5 additions & 3 deletions lib/framework.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/// Contains the main services of the mineral framework as well as helper extensions
library framework;

export '../src/console.dart';
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/extensions/collection.dart';
export '../src/internal/extensions/string.dart';
export 'src/internal/mixins/collection.dart';
export 'src/internal/mixins/string.dart';

export '../src/internal/mixins/console.dart';
14 changes: 7 additions & 7 deletions lib/src/api/builders/moderation_rules_builder.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:mineral/core/api.dart';
import 'package:mineral/src/exceptions/too_many.dart';
import 'package:mineral/src/exceptions/too_many_exception.dart';

class ModerationRulesBuilder {
final String label;
Expand All @@ -24,11 +24,11 @@ class ModerationRulesBuilder {

factory ModerationRulesBuilder.spam ({ required String label, required List<ModerationAction> actions, List<Snowflake>? exemptRoles, List<Snowflake>? exemptChannels, bool enabled = true }) {
if (exemptRoles != null && exemptRoles.length > 50) {
throw TooMany(cause: 'You cannot define more than 50 roles in the exclusion zone of the moderation rule.');
throw TooManyException('You cannot define more than 50 roles in the exclusion zone of the moderation rule.');
}

if (exemptChannels != null && exemptChannels.length > 20) {
throw TooMany(cause: 'You cannot define more than 20 channels in the exclusion zone of the moderation rule.');
throw TooManyException('You cannot define more than 20 channels in the exclusion zone of the moderation rule.');
}

return ModerationRulesBuilder(
Expand All @@ -45,11 +45,11 @@ class ModerationRulesBuilder {

factory ModerationRulesBuilder.banKeywords ({ required String label, required List<ModerationAction> actions, required ModerationTriggerMetadata? triggerMetadata, List<Snowflake>? exemptRoles, List<Snowflake>? exemptChannels, bool enabled = true }) {
if (exemptRoles != null && exemptRoles.length > 50) {
throw TooMany(cause: 'You cannot define more than 50 roles in the exclusion zone of the moderation rule.');
throw TooManyException('You cannot define more than 50 roles in the exclusion zone of the moderation rule.');
}

if (exemptChannels != null && exemptChannels.length > 20) {
throw TooMany(cause: 'You cannot define more than 20 channels in the exclusion zone of the moderation rule.');
throw TooManyException('You cannot define more than 20 channels in the exclusion zone of the moderation rule.');
}

return ModerationRulesBuilder(
Expand All @@ -66,11 +66,11 @@ class ModerationRulesBuilder {

factory ModerationRulesBuilder.mentionSpam ({ required String label, required List<ModerationAction> actions, required ModerationTriggerMetadata? triggerMetadata, List<Snowflake>? exemptRoles, List<Snowflake>? exemptChannels, bool enabled = true }) {
if (exemptRoles != null && exemptRoles.length > 50) {
throw TooMany(cause: 'You cannot define more than 50 roles in the exclusion zone of the moderation rule.');
throw TooManyException('You cannot define more than 50 roles in the exclusion zone of the moderation rule.');
}

if (exemptChannels != null && exemptChannels.length > 20) {
throw TooMany(cause: 'You cannot define more than 20 channels in the exclusion zone of the moderation rule.');
throw TooManyException('You cannot define more than 20 channels in the exclusion zone of the moderation rule.');
}

return ModerationRulesBuilder(
Expand Down
4 changes: 2 additions & 2 deletions lib/src/api/channels/category_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class CategoryChannel extends GuildChannel {
/// Get children of this
Map<Snowflake, GuildChannel> get children => guild.channels.cache.where((element) => element.parent?.id == id);

Future<GuildChannel> create (ChannelBuilder channel) async {
return super.guild.channels.create(channel) as GuildChannel;
Future<T?> create<T extends GuildChannel> (ChannelBuilder channel) async {
return super.guild.channels.create(channel);
}

factory CategoryChannel.fromPayload(dynamic payload) {
Expand Down
11 changes: 5 additions & 6 deletions lib/src/api/channels/guild_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import 'package:mineral/core/api.dart';
import 'package:mineral/framework.dart';
import 'package:mineral/src/api/builders/channel_builder.dart';
import 'package:mineral/src/api/managers/permission_overwrite_manager.dart';
import 'package:mineral/src/console.dart';
import 'package:mineral/src/internal/mixins/container.dart';

class GuildChannel extends PartialChannel with Container {
class GuildChannel extends PartialChannel with Container, Console {
final Snowflake _guildId;
final Snowflake? _parentId;
final String _label;
Expand Down Expand Up @@ -57,7 +56,7 @@ class GuildChannel extends PartialChannel with Container {

Future<void> update (ChannelBuilder builder) async {
if (_validate()) {
await container.use<Http>().patch(url: '/channels/$id', payload: builder.payload);
await container.use<HttpService>().patch(url: '/channels/$id', payload: builder.payload);
}
}

Expand All @@ -68,7 +67,7 @@ class GuildChannel extends PartialChannel with Container {
/// await channel.delete()
/// ```
Future<bool> delete () async {
Response response = await container.use<Http>().destroy(url: '/channels/$id');
Response response = await container.use<HttpService>().destroy(url: '/channels/$id');

guild.channels.cache.remove(this);
return response.statusCode == 200;
Expand All @@ -86,12 +85,12 @@ class GuildChannel extends PartialChannel with Container {

bool _validate () {
if (type == ChannelType.guildCategory) {
Console.warn(message: 'A category channel cannot have a parent');
console.warn('A category channel cannot have a parent');
return false;
}

if (type == ChannelType.guildPublicThread || type == ChannelType.private || type == ChannelType.guildNewsThread) {
Console.warn(message: 'A thread channel cannot change a parent');
console.warn('A thread channel cannot change a parent');
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/api/channels/news_channel.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:mineral/core.dart';
import 'package:mineral/core/api.dart';
import 'package:mineral/framework.dart';
import 'package:mineral/src/api/managers/message_manager.dart';
import 'package:mineral/src/api/managers/permission_overwrite_manager.dart';
import 'package:mineral/src/api/managers/thread_manager.dart';
import 'package:mineral/src/api/managers/webhook_manager.dart';
import 'package:mineral/src/console.dart';
import 'package:mineral/src/internal/mixins/container.dart';

class NewsChannel extends TextChannel with Container {
class NewsChannel extends TextChannel with Container, Console {
NewsChannel(
super.description,
super.lastPinTime,
Expand All @@ -30,11 +30,11 @@ class NewsChannel extends TextChannel with Container {
/// Follow this by an webhook application
Future<void> follow (Snowflake webhookId) async {
if (type != ChannelType.guildNews) {
Console.warn(message: 'Impossible to follow the channel $id as it is not an announcement channel');
console.warn('Impossible to follow the channel $id as it is not an announcement channel');
return;
}

await container.use<Http>().post(url: '/channels/$id/followers', payload: {
await container.use<HttpService>().post(url: '/channels/$id/followers', payload: {
'webhook_channel_id': webhookId
});
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/api/channels/partial_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:mineral/core/api.dart';
import 'package:mineral/src/api/channels/dm_channel.dart';
import 'package:mineral/src/api/channels/news_channel.dart';
import 'package:mineral/src/api/channels/stage_channel.dart';
import 'package:mineral/src/console.dart';
import 'package:mineral_console/mineral_console.dart';

class PartialChannel {
final Snowflake _id;
Expand Down Expand Up @@ -44,7 +44,7 @@ class ChannelWrapper {
final ChannelType? channelType = ChannelType.values.firstWhereOrNull((element) => element.value == payload['type']);

if (channelType == null) {
Console.warn(message: "Guild channel ${payload['type']} don't exist! Please report this to our team.");
Console(theme: DefaultTheme()).warn("Guild channel ${payload['type']} don't exist! Please report this to our team.");
return null;
}

Expand All @@ -70,7 +70,7 @@ class ChannelWrapper {
case ChannelType.guildForum:
return ForumChannel.fromPayload(payload);
default:
Console.warn(message: "$channelType is not supported");
Console(theme: DefaultTheme()).warn('$channelType is not supported');
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/api/channels/partial_text_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:mineral/core/builders.dart';
import 'package:mineral/core/collectors.dart';
import 'package:mineral/framework.dart';
import 'package:mineral/src/api/managers/message_manager.dart';
import 'package:mineral/src/internal/extensions/mineral_client.dart';
import 'package:mineral/src/internal/mixins/mineral_client.dart';
import 'package:mineral/src/internal/mixins/container.dart';

class PartialTextChannel extends GuildChannel with Container {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/api/client/mineral_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MineralClient extends MineralService {
String _sessionId;
Application _application;
List<Intent> _intents;
CommandManager _commands;
CommandService _commands;
late DateTime uptime;

MineralClient(
Expand All @@ -65,7 +65,7 @@ class MineralClient extends MineralService {
/// ### Returns the time the [MineralClient] is online
Duration get uptimeDuration => DateTime.now().difference(uptime);

CommandManager get commands => _commands;
CommandService get commands => _commands;

/// ### Defines the presence that this should adopt
///
Expand Down Expand Up @@ -118,14 +118,14 @@ class MineralClient extends MineralService {
}

Future<void> registerGlobalCommands ({ required List<CommandBuilder> commands }) async {
await ioc.use<Http>().put(
await ioc.use<HttpService>().put(
url: "/applications/${_application.id}/commands",
payload: commands.map((command) => command.toJson).toList()
);
}

Future<void> registerGuildCommands ({ required Guild guild, required List<CommandBuilder> commands, required List<MineralContextMenu> contextMenus }) async {
await ioc.use<Http>().put(
await ioc.use<HttpService>().put(
url: "/applications/${_application.id}/guilds/${guild.id}/commands",
payload: [
...commands.map((command) => command.toJson).toList(),
Expand All @@ -143,7 +143,7 @@ class MineralClient extends MineralService {
payload['session_id'],
Application.from(payload['application']),
ioc.use<ShardManager>().intents,
CommandManager(null),
CommandService(null),
);
}
}
Loading