Skip to content

Commit 0f5458a

Browse files
Merge pull request #127 from mineral-dart/develop
New release (4.0.0) !
2 parents 4c3dff6 + 2e44a45 commit 0f5458a

File tree

243 files changed

+3595
-1747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+3595
-1747
lines changed

README.md

Lines changed: 74 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,116 @@
1-
![License](https://img.shields.io/github/license/mineral-dart/core.svg)
2-
![Stars](https://img.shields.io/github/stars/mineral-dart)
3-
![Pull request](https://img.shields.io/github/issues-pr-closed/mineral-dart/core.svg)
4-
![Made with](https://img.shields.io/badge/Made%20with-dart-0866a8.svg)
1+
# Mineral - Discord Bot Framework for Dart
52

63
![banner](https://raw.githubusercontent.com/mineral-dart/core/develop/assets/images/banner.png)
74

8-
## The concepts
9-
Mineral meets a need for scalability over time but also within a team of developers thanks to a modular and flexible software architecture.
10-
modular and flexible software architecture.
5+
Mineral meets a need for scalability over time but also within a team of developers thanks to a modular and flexible software architecture. modular and flexible software architecture.
116

12-
Don't reinvent the wheel, the framework facilitates the sharing and accessibility of your data across your entire
13-
of your application. Design modules that can be reused in several of your projects.
7+
Don't reinvent the wheel, the framework facilitates the sharing and accessibility of your data across your entire of your application. Design modules that can be reused in several of your projects.
148

15-
We want to make your life easier, Mineral provides you with dedicated classes for each of the following features of
16-
Discord: events, commands, context menus, etc...
9+
We want to make your life easier, Mineral provides you with dedicated classes for each of the following features of Discord: events, commands, context menus, etc...
1710

18-
In order to improve your development experience, we wanted to integrate some features that do not exist in Discord but are very interesting
19-
but very interesting features such as intra-application data sharing through the
20-
Stores, a bunch of additional events around your discord servers or access in only one
21-
and 2 lines of code to an API through official Dart packages delivering recurring features such as tickets
22-
recurring features such as tickets, invitations or voice chancels on demand.
11+
In order to improve your development experience, we wanted to integrate some features that do not exist in Discord but are very interesting but very interesting features such as intra-application data sharing through the Stores, a bunch of additional events around your discord servers or access in only one and 2 lines of code to an API through official Dart packages delivering recurring features such as tickets recurring features such as tickets, invitations or voice chancels on demand.
2312

24-
## Mineral tour
25-
### The events
13+
With Mineral, you can unleash the full potential of your bot and bring your Discord server to life.
14+
15+
## Key Features
16+
17+
### Command Handling
18+
19+
Commands in Mineral serve the purpose of defining specific actions that your bot can perform in response to a given command.
20+
They allow users to communicate with your bot and interact with it in a structured way.
2621

27-
They are the heart of any Discord application, events allow you to act at a point in your application's lifecycle when an action is performed on the Discord server where your application is present.
2822
```dart
29-
import 'package:mineral/framework.dart';
30-
import 'package:mineral/core/events';
31-
32-
class MessageReceived extends MineralEvent<MessageCreate> {
33-
Future<void> handle (Message message) async {
34-
if (!message.author.isBot) {
35-
await message.reply(content: 'Hello ${message.author} ! 👋');
36-
}
23+
class HelloWorldCommand extends MineralCommand<GuildCommandInteraction> {
24+
HelloWorldCommand(): super(
25+
label: Display('hello'),
26+
description: Display('Add new member to the ticket !'),
27+
options: [
28+
CommandOption.user(Display('member'), Display('The member to add to the ticket !'))
29+
]
30+
);
31+
32+
Future<void> handle (interaction) async {
33+
final targetMember = interaction.getMember('member');
34+
35+
await interaction.reply(
36+
content: 'Hello $targetMember',
37+
private: true
38+
);
3739
}
3840
}
3941
```
4042

41-
In order to simplify the association between a component (buttons, selection menus...) and its resulting action, you can define a customId key in order to execute your code only if the given interaction is the right one.
43+
### Event Listeners
44+
Commands in Mineral serve the purpose of defining specific actions that your bot can perform in response to a given command.
45+
They allow users to communicate with your bot and interact with it in a structured way.
4246

43-
Consider the component displaying buttons below :
44-
```dart
45-
final button = ButtonBuilder.fromButton(
46-
label: 'My buttton',
47-
customId: 'my-custom-id',
48-
style: ButtonStyle.primary
49-
);
50-
```
51-
52-
### The slash commands
53-
Since version 8 of the websocket, Discord have announced their willingness to migrate traditional commands designed with the MessageCreate event to dedicated components that we call clash commands.
47+
By utilizing events, you can create dynamic and interactive experiences within your Discord bot.
48+
Events allow you to capture and respond to various actions and changes happening in real-time, enabling your bot to adapt and provide relevant functionality based on the events occurring in the Discord environment.
5449

55-
To simplify their design, we provide you with dedicated classes, please consider the examples below.
5650
```dart
57-
import 'package:mineral/framework.dart';
58-
import 'package:mineral/core/api.dart';
59-
60-
class HelloCommand extends MineralCommand {
61-
HelloCommand() {
62-
register(CommandBuilder('hello', 'Say hello to everyone !', scope: Scope.guild));
63-
}
64-
65-
Future<void> handle (CommandInteraction interaction) async {
66-
final Role everyone = interaction.guild?.roles.everyone;
67-
68-
await interaction.reply(content: 'Hello $everyone');
51+
class Ready extends MineralEvent<ReadyEvent> with Console {
52+
Future<void> handle (event) async {
53+
console.info('${event.client.user.username} is ready to use !');
6954
}
7055
}
7156
```
7257

73-
### The menu context
74-
Since the introduction of the new command management system, Discord has also introduced a very interesting feature that allows you to perform an action by taking as a source not a command to be written in the chat, but through a user or a message (very useful to postpone a user or a moved message).
58+
### Interactive Components
59+
By utilizing events, you can create dynamic and interactive experiences within your Discord bot.
60+
Events allow you to capture and respond to various actions and changes happening in real-time, enabling your bot to adapt and provide relevant functionality based on the events occurring in the Discord environment.
61+
62+
By incorporating interactive components into your Discord bot, you can enhance user engagement and provide a more interactive and dynamic experience. They allow users to interact with your bot directly within messages, enabling them to perform actions, make choices, and receive real-time feedback. Interactive components add an extra layer of interactivity to your bot's functionality and can greatly enhance the user experience.
63+
64+
Interactive components enhance the way buttons are used in Discord bots by introducing interactivity and real-time feedback.
65+
66+
A single file allows you to design your composanbt and attach a dedicated handler when the user interacts with it.
7567

76-
In order to fully exploit this functionality, a specific class is created.
7768
```dart
78-
import 'package:mineral/core/api.dart';
79-
import 'package:mineral/framework.dart';
69+
class MyButton extends InteractiveButton {
70+
MyButton(): super('my-id');
8071
81-
class ContextMenu extends MineralContextMenu {
82-
ContextMenu () {
83-
register('message-context', ContextMenuType.message);
72+
@override
73+
Future<void> handle (ButtonCreateEvent event) async {
74+
await event.interaction.reply(
75+
content: 'Hello Mineral !',
76+
private: true
77+
);
8478
}
8579
8680
@override
87-
Future<void> handle(Message message) async {
88-
await message.reply(content: message.content);
89-
}
81+
ButtonBuilder build () => ButtonBuilder.button(customId)
82+
..setLabel('Mineral')
83+
..setStyle(ButtonStyle.primary);
9084
}
9185
```
9286

93-
### Data sharing
94-
95-
The Discord.js documentation advocates in its examples the use of the very bad practice of only developing in a single file that contains your entire Discord application.
96-
97-
Working with this principle allows each of your listeners to use variables defined within the same file, so it is very easy to share data across multiple listeners.
98-
99-
The Mineral framework forces you to design your application following the S principle of the SOLID acronym in order to respect the principle of "single responsibility" (each class/function must perform only one action) which allows to obtain a better scalability in time and at the same time to limit to the maximum the repetition/duplication of code.
100-
101-
The use of this architecture implies that it becomes difficult to share states across your different classes.
102-
103-
In order to facilitate this sharing, the framework offers you the possibility to design classes dedicated to this need thanks to the @Store decorator.
87+
### State Management
88+
Share and manage data across your bot using shared states.
10489

10590
```dart
106-
import 'package:mineral/framework.dart';
91+
class MyState extends MineralState<int> {
92+
MyState() : super(0);
10793
108-
class MyState extends MineralState<List<int>> {
109-
MyState(): super('MyState', 'MyState description');
94+
void increment() => state++;
11095
111-
// Add string to this
112-
void addItem (int value) => state.add(value);
113-
114-
// Verify if this contains given value
115-
bool has (int value) => state.contains(value);
96+
void decrement() => state--;
11697
}
11798
```
11899

119-
When you register your class in your hand, your blind is accessible from any command, event or context menu file.
100+
- **HTTP API Integration:** Seamlessly interact with the Discord API to perform actions such as sending messages, updating user information, creating channels, and more.
120101

121-
`main.dart`
122-
```dart
123-
Future<void> main () async {
124-
Kernel kernel = Kernel()
125-
..intents.defined(all: true)
126-
..events.register([MessageReceived()])
127-
..stores.register([MyState()]);
128-
129-
await kernel.init();
130-
}
131-
```
102+
- **Container and Dependency Injection:** Take advantage of the powerful dependency injection capabilities provided by Mineral's built-in container, making it easy to manage and access your services and dependencies.
132103

133-
Now that your store is registered within your application, you can now access your shared state using the code below, we will illustrate the operation on the MessageCreate event.
134-
```dart
135-
import 'package:mineral/framework.dart';
136-
import 'package:mineral/core/events';
137-
138-
class MessageCreate extends MineralEvent<MessageCreate> with Console {
139-
Future<void> handle (Message message) async {
140-
final myState = states.use<MyStore>();
141-
myState.addItem(1);
142-
143-
console.info(message: 'MyState contains ${store.state.length} items.');
144-
}
145-
}
146-
```
104+
- **Error Handling and Logging:** Benefit from robust error handling and logging mechanisms to ensure smooth operation and easy debugging of your bot.
105+
106+
- **Extensible Architecture:** Extend and customize Mineral to fit your specific needs with ease. The framework provides a modular and extensible architecture that allows for easy integration of custom modules and plugins.
107+
108+
## Community and Support
109+
Join our vibrant community of Discord bot developers on Discord to get support, share your projects, and collaborate with other developers.
110+
111+
We also encourage you to contribute to the Mineral project by reporting issues, suggesting new features, or submitting pull requests on GitHub.
147112

148-
Join our ranks and add your contribution to the best discord framework for Dart 💪
113+
Start your journey with Mineral today and create extraordinary Discord bots that will elevate your server to new heights!
149114

150115
[![Discord](https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/mineral-dart/core)
151116
[![Discord](https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/fH9UQDMZSn)

assets/images/github-branding.png

3.27 MB
Loading

lib/cli.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
library cli;
2+
3+
export 'src/internal/services/cli/command_line_interface.dart' show CommandLineInterface;

lib/core/api.dart

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ library api;
44
export '../src/api/activity.dart' show Activity;
55
export '../src/api/application.dart' show Application;
66
export '../src/api/channels/category_channel.dart' show CategoryChannel;
7+
export '../src/api/channels/dm_channel.dart' show DmChannel;
78
export '../src/api/channels/forum_channel.dart' show ForumChannel;
89
export '../src/api/channels/guild_channel.dart' show GuildChannel;
910
export '../src/api/channels/partial_channel.dart' show PartialChannel, ChannelType;
@@ -12,44 +13,50 @@ export '../src/api/channels/text_based_channel.dart' show TextBasedChannel;
1213
export '../src/api/channels/text_channel.dart' show TextChannel;
1314
export '../src/api/channels/thread_channel.dart' show ThreadChannel;
1415
export '../src/api/channels/voice_channel.dart' show VoiceChannel;
15-
export '../src/api/channels/dm_channel.dart' show DmChannel;
16+
export '../src/api/client/client_permission.dart' show ClientPermission;
1617
export '../src/api/client/client_presence.dart' show ClientPresence, GamePresence;
18+
export '../src/api/client/client_scope.dart' show ClientScope;
1719
export '../src/api/client/mineral_client.dart' show MineralClient, ClientActivity, ClientStatus;
1820
export '../src/api/color.dart' show Color;
1921
export '../src/api/emoji.dart' show Emoji;
22+
export '../src/api/guilds/activities/activity_type.dart' show ActivityType;
23+
export '../src/api/guilds/explicit_content_level.dart' show ExplicitContentLevel;
2024
export '../src/api/guilds/guild.dart' show Guild;
2125
export '../src/api/guilds/guild_member.dart' show GuildMember;
2226
export '../src/api/guilds/guild_preview.dart' show GuildPreview;
2327
export '../src/api/guilds/guild_scheduled_event.dart' show ScheduledEventStatus, ScheduledEventEntityType, GuildScheduledEvent, ScheduledEventUser;
28+
export '../src/api/guilds/notification_level.dart' show NotificationLevel;
29+
export '../src/api/guilds/verification_level.dart' show VerificationLevel;
2430
export '../src/api/image_formater.dart' show ImageFormater;
2531
export '../src/api/interactions/button_interaction.dart' show ButtonInteraction;
2632
export '../src/api/interactions/command_interaction.dart' show CommandInteraction;
27-
export '../src/api/interactions/global_command_interaction.dart' show GlobalCommandInteraction;
28-
export '../src/api/interactions/guild_command_interaction.dart' show GuildCommandInteraction;
2933
export '../src/api/interactions/context_message_interaction.dart' show ContextMessageInteraction;
3034
export '../src/api/interactions/context_user_interaction.dart' show ContextUserInteraction;
35+
export '../src/api/interactions/global_command_interaction.dart' show GlobalCommandInteraction;
36+
export '../src/api/interactions/guild_command_interaction.dart' show GuildCommandInteraction;
3137
export '../src/api/interactions/interaction.dart' show Interaction;
32-
export '../src/api/interactions/modal_interaction.dart' show ModalInteraction;
3338
export '../src/api/interactions/menus/dynamic_menu_interaction.dart' show DynamicMenuInteraction;
3439
export '../src/api/interactions/menus/user_menu_interaction.dart' show UserMenuInteraction;
40+
export '../src/api/interactions/modal_interaction.dart' show ModalInteraction;
41+
export '../src/api/invites/invite.dart' show Invite;
42+
export '../src/api/invites/vanity_invite.dart' show VanityInvite;
43+
export '../src/api/lang.dart' show Lang;
3544
export '../src/api/managers/member_role_manager.dart' show MemberRoleManager;
36-
export '../src/api/managers/voice_manager.dart' show VoiceManager;
3745
export '../src/api/managers/message_manager.dart' show MessageManager, BulkDeleteBuilder;
38-
export '../src/api/messages/message.dart' show Message;
46+
export '../src/api/managers/voice_manager.dart' show VoiceManager;
3947
export '../src/api/messages/dm_message.dart' show DmMessage;
48+
export '../src/api/messages/message.dart' show Message;
4049
export '../src/api/moderation_rule.dart' show ModerationEventType, ModerationTriggerType, ModerationPresetType, ModerationActionType, ModerationTriggerMetadata, ModerationActionMetadata, ModerationAction, ModerationRule;
4150
export '../src/api/permission_overwrite.dart' show PermissionOverwrite, PermissionOverwriteType;
4251
export '../src/api/role.dart' show Role;
4352
export '../src/api/status.dart' show Status, StatusType;
53+
export '../src/api/users/premium_type.dart' show PremiumType;
4454
export '../src/api/users/user.dart' show User;
55+
export '../src/api/users/user_decoration.dart' show UserDecoration;
56+
export '../src/api/users/user_flags/user_flag_contract.dart' show UserFlagContract;
4557
export '../src/api/utils.dart';
4658
export '../src/api/webhook.dart' show Webhook;
4759
export '../src/internal/services/intent_service.dart' show Intent;
48-
export '../src/api/users/premium_type.dart' show PremiumType;
49-
export '../src/api/users/user_decoration.dart' show UserDecoration;
50-
export '../src/api/users/user_flags/user_flag_contract.dart' show UserFlagContract;
51-
export '../src/api/client/client_scope.dart' show ClientScope;
52-
export '../src/api/client/client_permission.dart' show ClientPermission;
53-
export '../src/api/guilds/activities/activity_type.dart' show ActivityType;
60+
5461

5562
typedef Snowflake = String;

0 commit comments

Comments
 (0)